-
Notifications
You must be signed in to change notification settings - Fork 853
Fixes #5170: Improve msd_type parsing #5173
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
90a3074
f720f00
21bfdf8
206766d
8a9b472
a746e0c
2c69667
ced5ece
45a4658
5f62866
b2bec49
fad64a3
83594a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -382,14 +382,11 @@ def _parse_msd_type(self): | |||||
| "xyz": [0, 1, 2], | ||||||
| } | ||||||
|
|
||||||
| self.msd_type = self.msd_type.lower() | ||||||
|
|
||||||
| try: | ||||||
| self._dim = keys[self.msd_type] | ||||||
| except KeyError: | ||||||
| raise ValueError( | ||||||
| "invalid msd_type: {} specified, please specify one of xyz, " | ||||||
| "xy, xz, yz, x, y, z".format(self.msd_type) | ||||||
| self._dim = keys[self.msd_type.lower()] | ||||||
| except (AttributeError, KeyError): | ||||||
| raise TypeError( | ||||||
| "msd_type must be a string and one of: xyz, xy, xz, yz, x, y, z" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Keep the parameter exposed in the error message. |
||||||
| ) | ||||||
|
|
||||||
| self.dim_fac = len(self._dim) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,11 +117,21 @@ def test_updating_ag_rejected(self, u): | |
| with pytest.raises(TypeError, match=errmsg): | ||
| m = MSD(updating_ag, msd_type="xyz", fft=False) | ||
|
|
||
| @pytest.mark.parametrize("msdtype", ["foo", "bar", "yx", "zyx"]) | ||
| def test_msdtype_error(self, u, SELECTION, msdtype): | ||
| errmsg = f"invalid msd_type: {msdtype}" | ||
| with pytest.raises(ValueError, match=errmsg): | ||
| m = MSD(u, SELECTION, msd_type=msdtype) | ||
| @pytest.mark.parametrize( | ||
| "msd_type, exc", | ||
| [ | ||
| ("Xz", None), # valid, mixed case. | ||
| (123, TypeError), # non-string. | ||
| ], | ||
| ) | ||
| def test_msdtype_error(self, u, SELECTION, msd_type, exc): | ||
| if exc is None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do this, keep this solely to checking for an error being raised with bad inputs. |
||
| m = MSD(u, SELECTION, msd_type=msd_type, fft=False) | ||
| assert m.dim_fac == 2 | ||
| assert m._dim == [0, 2] | ||
| else: | ||
| with pytest.raises(exc): | ||
| MSD(u, SELECTION, msd_type=msd_type, fft=False) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't do this, keep all the old parameters ("foo", "bar", etc...) and solely check for the ValueError to be raised, just like the old test. |
||
|
|
||
| @pytest.mark.parametrize( | ||
| "dim, dim_factor", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the value error, it's an error in the input value.