Skip to content

Commit 47e41af

Browse files
committed
Tests for --table arg to contents
1 parent 695ed8b commit 47e41af

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

paths_cli/commands/contents.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import click
22
from paths_cli.parameters import INPUT_FILE
33

4-
UNNAMED_SECTIONS = {
5-
'Steps': lambda storage: storage.steps,
6-
'Move Changes': lambda storage: storage.movechanges,
7-
'SampleSets': lambda storage: storage.samplesets,
8-
'Trajectories': lambda storage: storage.trajectories,
9-
'Snapshots': lambda storage: storage.snapshots
10-
}
4+
UNNAMED_SECTIONS = ['steps', 'movechanges', 'samplesets', 'trajectories',
5+
'snapshots']
116

127
@click.command(
138
'contents',
@@ -52,7 +47,15 @@ def report_all_tables(storage):
5247
print(get_section_string_nameable('Tags', storage.tags, _get_named_tags))
5348

5449
print("\nData Objects:")
55-
for section, store_func in UNNAMED_SECTIONS.items():
50+
data_object_mapping = {
51+
'Steps': lambda storage: storage.steps,
52+
'Move Changes': lambda storage: storage.movechanges,
53+
'SampleSets': lambda storage: storage.samplesets,
54+
'Trajectories': lambda storage: storage.trajectories,
55+
'Snapshots': lambda storage: storage.snapshots
56+
}
57+
58+
for section, store_func in data_object_mapping.items():
5659
store = store_func(storage)
5760
print(get_unnamed_section_string(section, store))
5861

paths_cli/tests/commands/test_contents.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,30 @@ def test_contents(tps_fixture):
4040
assert results.output.split('\n') == expected
4141
for truth, beauty in zip(expected, results.output.split('\n')):
4242
assert truth == beauty
43+
44+
@pytest.mark.parametrize('table', ['volumes', 'trajectories'])
45+
def test_contents_table(tps_fixture, table):
46+
scheme, network, engine, init_conds = tps_fixture
47+
runner = CliRunner()
48+
with runner.isolated_filesystem():
49+
storage = paths.Storage("setup.nc", 'w')
50+
for obj in tps_fixture:
51+
storage.save(obj)
52+
storage.tags['initial_conditions'] = init_conds
53+
54+
results = runner.invoke(contents, ['setup.nc', '--table', table])
55+
cwd = os.getcwd()
56+
expected = {
57+
'volumes': [
58+
f"Storage @ '{cwd}/setup.nc'",
59+
"volumes: 8 items", "* A", "* B", "* plus 6 unnamed items",
60+
""
61+
],
62+
'trajectories': [
63+
f"Storage @ '{cwd}/setup.nc'",
64+
"trajectories: 1 unnamed item",
65+
""
66+
]
67+
}[table]
68+
assert results.output.split("\n") == expected
69+
assert results.exit_code == 0

0 commit comments

Comments
 (0)