Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1006: minor fixes and several new unit tests for PSA module #1508

Merged
merged 13 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,9 @@ def get_path_metric_func(name):
try:
return path_metrics[name]
except KeyError as key:
print("Path metric {0} not found. Valid selections: ".format(key))
for name in path_metrics.keys(): print(" \"{0}\"".format(name))
# except KeyError as key:
# err_str = "Path metric {0} not found. Valid selections: ".format(key)
# err_str += " ".join(["\"{0}\"".format(name) for name in path_metrics.keys()])
# raise KeyError(err_str)
err_str = "Path metric {0} not found. Valid selections: ".format(key)
err_str += " ".join(["\"{0}\"".format(name) for name in path_metrics.keys()])
raise KeyError(err_str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use multiline strings

raise KeyError("Path metric {} not found. Valid Selections: {}".format(
                           key, ' '.join(['"{}"'.format(name) for name in path_metrics.keys()]))



def sqnorm(v, axis=None):
Expand Down
6 changes: 1 addition & 5 deletions testsuite/MDAnalysisTests/analysis/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ class TestPSAExceptions(TestCase):
def test_get_path_metric_func_bad_key(self):
'''Test that KeyError is caught by
get_path_metric_func().'''

try:
with self.assertRaises(KeyError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with pytest.raises(KeyError):
    PSA.get_path_metric_func('foobar')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I put my changes on hold since, once I rebased properly, realized everything is now pytest-specific. Hoping to finish this PR within the week.

PSA.get_path_metric_func('123456')
except KeyError:
self.fail('KeyError should be caught')

def test_get_coord_axes_bad_dims(self):
"""Test that ValueError is raised when
numpy array with incorrect dimensions
is fed to get_coord_axes()."""

with self.assertRaises(ValueError):
PSA.get_coord_axes(np.zeros((5,5,5,5)))

Expand Down