Skip to content
Closed
Changes from all commits
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
21 changes: 8 additions & 13 deletions paths_cli/tests/commands/test_contents.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import os
import tempfile
import pytest
from unittest.mock import patch
from click.testing import CliRunner

import openpathsampling as paths

from paths_cli.commands.contents import *
from .utils import assert_click_success


def test_contents(tps_fixture):
# we just do a full integration test of this one
scheme, network, engine, init_conds = tps_fixture
Expand All @@ -18,11 +16,8 @@ def test_contents(tps_fixture):
for obj in tps_fixture:
storage.save(obj)
storage.tags['initial_conditions'] = init_conds

results = runner.invoke(contents, ['setup.nc'])
cwd = os.getcwd()
expected = [
f"Storage @ '{cwd}/setup.nc'",
"CVs: 1 item", "* x",
"Volumes: 8 items", "* A", "* B", "* plus 6 unnamed items",
"Engines: 2 items", "* flat", "* plus 1 unnamed item",
Expand All @@ -38,10 +33,12 @@ def test_contents(tps_fixture):
f"Snapshots: {2*len(init_conds[0])} unnamed items", ""
]
assert_click_success(results)
assert results.output.split('\n') == expected
for truth, beauty in zip(expected, results.output.split('\n')):
check = results.output.split('\n')[-len(expected):]
assert check == expected
for truth, beauty in zip(expected, check):
assert truth == beauty


@pytest.mark.parametrize('table', ['volumes', 'trajectories', 'tags'])
def test_contents_table(tps_fixture, table):
scheme, network, engine, init_conds = tps_fixture
Expand All @@ -53,28 +50,26 @@ def test_contents_table(tps_fixture, table):
storage.tags['initial_conditions'] = init_conds

results = runner.invoke(contents, ['setup.nc', '--table', table])
cwd = os.getcwd()
expected = {
'volumes': [
f"Storage @ '{cwd}/setup.nc'",
"volumes: 8 items", "* A", "* B", "* plus 6 unnamed items",
""
],
'trajectories': [
f"Storage @ '{cwd}/setup.nc'",
"trajectories: 1 unnamed item",
""
],
'tags': [
f"Storage @ '{cwd}/setup.nc'",
"tags: 1 item",
"* initial_conditions",
""
],
}[table]
assert results.output.split("\n") == expected
check = results.output.split('\n')[-len(expected):]
assert check == expected
assert_click_success(results)


def test_contents_table_error():
runner = CliRunner()
with runner.isolated_filesystem():
Expand Down