Skip to content

Commit

Permalink
add some test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhswenson committed Aug 25, 2024
1 parent 06db15a commit ff15749
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 0 additions & 2 deletions paths_cli/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def _extract_trajectories(self, obj):
yield obj.trajectory
elif isinstance(obj, paths.Trajectory):
yield obj
elif isinstance(obj, paths.BaseSnapshot):
yield paths.Trajectory([obj])
elif isinstance(obj, list):
for o in obj:
yield from self._extract_trajectories(o)
Expand Down
25 changes: 22 additions & 3 deletions paths_cli/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,12 @@ def create_file(self, getter):
get_type, getter_style = self._parse_getter(getter)
main, other = {
'traj': (self.traj, self.other_traj),
'sset': (self.sample_set, self.other_sample_set)
'sset': (self.sample_set, self.other_sample_set),
'samp': (self.sample_set[0], self.other_sample_set[0]),
}[get_type]
if get_type == 'samp':
storage.save(main)
storage.save(other)
if get_type == 'sset':
storage.save(self.sample_set)
storage.save(self.other_sample_set)
Expand All @@ -231,20 +235,23 @@ def create_file(self, getter):

if other_tag:
storage.tags[other_tag] = other

storage.close()
return filename

@pytest.mark.parametrize("getter", [
'name-traj', 'number-traj', 'tag-final-traj', 'tag-initial-traj',
'name-sset', 'number-sset', 'tag-final-sset', 'tag-initial-sset'
'name-sset', 'number-sset', 'tag-final-sset', 'tag-initial-sset',
'name-samp', 'number-samp',
])
def test_get(self, getter):
filename = self.create_file(getter)
storage = paths.Storage(filename, mode='r')
get_type, getter_style = self._parse_getter(getter)
expected = {
'sset': [s.trajectory for s in self.sample_set],
'traj': [self.traj]
'traj': [self.traj],
'samp': [self.sample_set[0].trajectory],
}[get_type]
get_arg = {
'name': 'traj',
Expand Down Expand Up @@ -303,6 +310,18 @@ def test_cannot_guess(self):
with pytest.raises(RuntimeError):
self.PARAMETER.get(storage, None)

def test_get_bad_name(self):
filename = self._filename("bad_tag")
storage = paths.Storage(filename, 'w')
storage.save(self.traj)
storage.save(self.other_traj)
storage.tags['bad_tag'] = "foo"
storage.close()

storage = paths.Storage(filename, 'r')
with pytest.raises(RuntimeError, match="initial conditions type"):
self.PARAMETER.get(storage, "bad_tag")


class TestINIT_SNAP(ParamInstanceTest):
PARAMETER = INIT_SNAP
Expand Down

0 comments on commit ff15749

Please sign in to comment.