Skip to content
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
Prev Previous commit
Next Next commit
more test coverage
  • Loading branch information
dwhswenson committed Dec 9, 2020
commit 00b83cc118453283ee827ce5485297a6265364e5
3 changes: 0 additions & 3 deletions paths_cli/commands/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def __call__(self, trajectory, trusted=False):
if not done]
# TODO: update on how many ensembles left, what frame number we are

if not unsatisfied:
return False

start = -1
while self._check_previous_frame(trajectory, start, unsatisfied):
start -= 1
Expand Down
34 changes: 27 additions & 7 deletions paths_cli/tests/commands/test_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def setup(self):
]).named('transition'),
]
self.ensembles = {ens.name: ens for ens in ensembles}
traj_vals = [-0.1, 1.1, 0.5, -0.2, 0.1, -0.3, 0.4, 1.4, -1.0]
self.trajectory = make_1d_traj(traj_vals)
self.engine = CalvinistDynamics(traj_vals)
self.traj_vals = [-0.1, 1.1, 0.5, -0.2, 0.1, -0.3, 0.4, 1.4, -1.0]
self.trajectory = make_1d_traj(self.traj_vals)
self.engine = CalvinistDynamics(self.traj_vals)
self.satisfied_when_traj_len = {
"len1": 1,
"len3": 3,
Expand Down Expand Up @@ -76,6 +76,10 @@ def test_call(self, traj_len, expected, trusted):
# only test call count if we're trusted
assert mock.call_count == expected_calls

def test_long_traj_untrusted(self):
traj = make_1d_traj(self.traj_vals + [1.0, 1.2, 1.3, 1.4])
assert self.conditions(traj) is False

def test_generate(self):
init_snap = self.trajectory[0]
traj = self.engine.generate(init_snap, self.conditions)
Expand Down Expand Up @@ -118,17 +122,25 @@ def test_md(md_fixture):
assert results.output == expected_output
assert results.exit_code == 0

def test_md_main(md_fixture):
@pytest.mark.parametrize('inp', ['nsteps', 'ensemble'])
def test_md_main(md_fixture, inp):
tempdir = tempfile.mkdtemp()
try:
store_name = os.path.join(tempdir, "md.nc")
storage = paths.Storage(store_name, mode='w')
engine, ensemble, snapshot = md_fixture
engine, ens, snapshot = md_fixture
if inp == 'nsteps':
nsteps, ensembles = 5, None
elif inp == 'ensemble':
nsteps, ensembles = None, [ens]
else:
raise RuntimeError("pytest went crazy")

traj, foo = md_main(
output_storage=storage,
engine=engine,
ensembles=[ensemble],
nsteps=None,
ensembles=ensembles,
nsteps=nsteps,
initial_frame=snapshot
)
assert isinstance(traj, paths.Trajectory)
Expand All @@ -140,3 +152,11 @@ def test_md_main(md_fixture):
os.remove(store_name)
os.rmdir(tempdir)

def test_md_main_error(md_fixture):
engine, ensemble, snapshot = md_fixture
with pytest.raises(RuntimeError):
md_main(output_storage=None,
engine=engine,
ensembles=[ensemble],
nsteps=5,
initial_frame=snapshot)