Skip to content

Commit 3ae0ce1

Browse files
committed
remaining tests for file_copying
1 parent 7033c0d commit 3ae0ce1

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎paths_cli/tests/commands/test_append.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def test_append_remove_tag(tps_network_and_traj):
8888
result = runner.invoke(append,
8989
[in_file, '-a', "output.nc",
9090
"--tag", 'template', '--save-tag', ''])
91-
print(result.output)
9291
assert result.exception is None
9392
assert result.exit_code == 0
9493

‎paths_cli/tests/test_file_copying.py‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import collections
2+
import functools
13
import os
24
import tempfile
35
from unittest.mock import MagicMock, patch
46
import pytest
57

6-
78
import openpathsampling as paths
89
from openpathsampling.tests.test_helpers import make_1d_traj
910

@@ -64,7 +65,7 @@ def __call__(self, snap):
6465
return snap.xyz[0][0]
6566

6667
self.cv = paths.FunctionCV("test", RunOnceFunction())
67-
traj = paths.tests.test_helpers.make_1d_traj([2, 1])
68+
traj = make_1d_traj([2, 1])
6869
self.snap = traj[0]
6970
self.other_snap = traj[1]
7071

@@ -75,9 +76,54 @@ def test_precompute_cvs(self):
7576
assert recalced == 2
7677
assert self.cv.diskcache_enabled is True
7778

78-
def test_precompute_cvs_and_inputs(self):
79-
pytest.skip()
79+
@pytest.mark.parametrize('cvs', [['test'], None])
80+
def test_precompute_cvs_and_inputs(self, cvs):
81+
with tempfile.TemporaryDirectory() as tmpdir:
82+
storage = paths.Storage(os.path.join(tmpdir, "test.nc"),
83+
mode='w')
84+
traj = make_1d_traj(list(range(10)))
85+
cv = paths.FunctionCV("test", lambda s: s.xyz[0][0])
86+
storage.save(traj)
87+
storage.save(cv)
88+
89+
if cvs is not None:
90+
cvs = [storage.cvs[cv] for cv in cvs]
91+
92+
precompute_func, blocks = precompute_cvs_func_and_inputs(
93+
input_storage=storage,
94+
cvs=cvs,
95+
blocksize=2
96+
)
97+
assert len(blocks) == 5
98+
for block in blocks:
99+
assert len(block) == 2
100+
101+
# smoke test: only effect should be caching results
102+
precompute_func(blocks[0])
80103

81104

82105
def test_rewrite_file():
83-
pytest.skip()
106+
# making a mock for storage instead of actually testing integration
107+
class FakeStore(object):
108+
def __init__(self):
109+
self._stores = collections.defaultdict(list)
110+
111+
def store(self, obj, store_name):
112+
self._stores[store_name].append(obj)
113+
114+
stage_names = ['foo', 'bar']
115+
storage = FakeStore()
116+
store_funcs = {
117+
name: functools.partial(storage.store, store_name=name)
118+
for name in stage_names
119+
}
120+
stage_mapping = {
121+
'foo': (store_funcs['foo'], [0, 1, 2]),
122+
'bar': (store_funcs['bar'], [[3], [4], [5]])
123+
}
124+
silent_tqdm = lambda x, desc=None, leave=True: x
125+
with patch('paths_cli.file_copying.tqdm', silent_tqdm):
126+
rewrite_file(stage_names, stage_mapping)
127+
128+
assert storage._stores['foo'] == [0, 1, 2]
129+
assert storage._stores['bar'] == [[3], [4], [5]]

0 commit comments

Comments
 (0)