Skip to content

Commit 4b7dd7c

Browse files
committed
more cleanup to get tests running
1 parent 030679c commit 4b7dd7c

11 files changed

Lines changed: 61 additions & 16 deletions

File tree

‎paths_cli/cli.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from .plugin_management import (FilePluginLoader, NamespacePluginLoader,
1717
OPSCommandPlugin)
18+
from .utils import app_dir_plugins
1819

1920
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
2021

@@ -26,11 +27,6 @@ class OpenPathSamplingCLI(click.MultiCommand):
2627
def __init__(self, *args, **kwargs):
2728
# the logic here is all about loading the plugins
2829
commands = str(pathlib.Path(__file__).parent.resolve() / 'commands')
29-
def app_dir_plugins(posix):
30-
return str(pathlib.Path(
31-
click.get_app_dir("OpenPathSampling", force_posix=posix)
32-
).resolve() / 'cli-plugins')
33-
3430
self.plugin_loaders = [
3531
FilePluginLoader(commands, OPSCommandPlugin),
3632
FilePluginLoader(app_dir_plugins(posix=False), OPSCommandPlugin),

‎paths_cli/commands/compile.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import importlib
1212
from paths_cli.utils import app_dir_plugins
1313

14+
# this is just to handle a nicer error
1415
def import_module(module_name, format_type=None, install=None):
1516
try:
1617
mod = importlib.import_module(module_name)

‎paths_cli/compiling/engines.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
HAS_OPENMM = True
1515

1616
def load_openmm_xml(filename):
17-
if not HAS_OPENMM: # pragma: no cover
17+
if not HAS_OPENMM: # -no-cov-
1818
raise RuntimeError("OpenMM does not seem to be installed")
1919

2020
with open(filename, mode='r') as f:

‎paths_cli/compiling/networks.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,22 @@ def tis_trans_info(dct):
5353
name='tps'
5454
)
5555

56-
build_tps_network = TPS_NETWORK_PLUGIN
5756

5857
MISTIS_NETWORK_PLUGIN = NetworkCompilerPlugin(
5958
parameters=[Parameter('trans_info', mistis_trans_info)],
6059
builder=Builder('openpathsampling.MISTISNetwork'),
6160
name='mistis'
6261
)
63-
build_mistis_network = MISTIS_NETWORK_PLUGIN
6462

6563
TIS_NETWORK_PLUGIN = NetworkCompilerPlugin(
6664
builder=Builder('openpathsampling.MISTISNetwork'),
6765
parameters=[Parameter('trans_info', tis_trans_info)],
6866
name='tis'
6967
)
68+
69+
# old names not yet replaced in testing
70+
build_tps_network = TPS_NETWORK_PLUGIN
71+
build_mistis_network = MISTIS_NETWORK_PLUGIN
7072
build_tis_network = TIS_NETWORK_PLUGIN
7173

7274

‎paths_cli/compiling/root_compiler.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def _get_compiler(compiler_name):
5555
registered. It will automatically create a compiler for any unknown
5656
``compiler_name.``
5757
"""
58+
if compiler_name is None:
59+
if None not in _COMPILERS:
60+
_COMPILERS[None] = Compiler(None, None)
61+
return _COMPILERS[None]
62+
5863
canonical_name = _canonical_name(compiler_name)
5964
# create a new compiler if none exists
6065
if canonical_name is None:
@@ -165,6 +170,7 @@ def _sort_user_categories(user_categories):
165170
"""
166171
user_to_canonical = {user_key: _canonical_name(user_key)
167172
for user_key in user_categories}
173+
logger.debug(user_to_canonical)
168174
sorted_keys = sorted(
169175
user_categories,
170176
key=lambda x: COMPILE_ORDER.index(user_to_canonical[x])
@@ -175,12 +181,10 @@ def do_compile(dct):
175181
"""Main function for compiling user input to objects.
176182
"""
177183
objs = []
178-
for category in _sort_user_categories(dct):
179-
# breakpoint()
184+
for category in _sort_user_categories(dct.keys()):
180185
func = _get_compiler(category)
181186
yaml_objs = dct.get(category, [])
182-
logger.debug(f"{yaml_objs}")
187+
logger.debug(yaml_objs)
183188
new = func(yaml_objs)
184-
# new = [func(obj) for obj in yaml_objs]
185189
objs.extend(new)
186190
return objs

‎paths_cli/compiling/volumes.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import functools
33

44
from .core import Compiler, InstanceBuilder, custom_eval, Parameter
5-
from paths_cli.compiling.plugins import VolumeCompilerPlugin
5+
from paths_cli.compiling.plugins import VolumeCompilerPlugin, CompilerPlugin
66
from paths_cli.compiling.root_compiler import compiler_for
77

88
# TODO: extra function for volumes should not be necessary as of OPS 2.0
@@ -64,3 +64,6 @@ def cv_volume_build_func(**dct):
6464
)
6565

6666
build_union_volume = UNION_VOLUME_PLUGIN
67+
68+
VOLUME_COMPILER = CompilerPlugin(VolumeCompilerPlugin, aliases=['state',
69+
'states'])

‎paths_cli/param_core.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ def get(self, name):
115115
storage = Storage(name, self.mode)
116116
return storage
117117

118+
@classmethod
119+
def cleanup(cls):
120+
if cls.has_simstore_patch:
121+
import openpathsampling as paths
122+
from openpathsampling.experimental.storage.monkey_patches \
123+
import unpatch
124+
paths = unpatch(paths)
125+
118126

119127
class OPSStorageLoadNames(AbstractLoader):
120128
"""Simple loader that expects its input to be a name or index.

‎paths_cli/tests/commands/test_compile.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_compile(ad_openmm, test_data_dir):
6666
ad_openmm / "integrator.xml"]
6767
for filename in files:
6868
shutil.copy2(str(filename), cwd)
69-
pytest.skip() # TODO: compiler aliases don't work yet
69+
# pytest.skip() # TODO: compiler aliases don't work yet
7070
result = runner.invoke(
7171
compile_,
7272
['setup.yml', '-o', str(ad_openmm / 'setup.db')]
@@ -79,9 +79,10 @@ def test_compile(ad_openmm, test_data_dir):
7979
traceback.print_tb(result.exc_info[2])
8080
print(result.exception)
8181
print(result.exc_info)
82-
assert result.exit_code == 0
8382
print(result.output)
83+
assert result.exit_code == 0
8484
assert os.path.exists(str(ad_openmm / 'setup.db'))
85+
import openpathsampling as paths
8586
from openpathsampling.experimental.storage import (
8687
Storage, monkey_patch_all)
8788
# TODO: need to do the temporary monkey patch here
@@ -92,3 +93,11 @@ def test_compile(ad_openmm, test_data_dir):
9293
engine = st.engines['engine']
9394
phi = st.cvs['phi']
9495
C_7eq = st.volumes['C_7eq']
96+
from openpathsampling.experimental.storage.monkey_patches import unpatch
97+
paths = unpatch(paths)
98+
paths.InterfaceSet.simstore = False
99+
import importlib
100+
importlib.reload(paths.netcdfplus)
101+
importlib.reload(paths.collectivevariable)
102+
importlib.reload(paths.collectivevariables)
103+
importlib.reload(paths)

‎paths_cli/tests/commands/test_contents.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import openpathsampling as paths
88

99
from paths_cli.commands.contents import *
10+
from .utils import assert_click_success
1011

1112
def test_contents(tps_fixture):
1213
# we just do a full integration test of this one
@@ -36,6 +37,7 @@ def test_contents(tps_fixture):
3637
"Trajectories: 1 unnamed item",
3738
f"Snapshots: {2*len(init_conds[0])} unnamed items", ""
3839
]
40+
assert_click_success(results)
3941
assert results.exit_code == 0
4042
assert results.output.split('\n') == expected
4143
for truth, beauty in zip(expected, results.output.split('\n')):
@@ -72,6 +74,7 @@ def test_contents_table(tps_fixture, table):
7274
],
7375
}[table]
7476
assert results.output.split("\n") == expected
77+
assert_click_success(results)
7578
assert results.exit_code == 0
7679

7780
def test_contents_table_error():
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
from paths_cli.compiling.plugins import *
3+
from unittest.mock import Mock
4+
5+
class TestCompilerPlugin:
6+
def setup(self):
7+
self.plugin_class = Mock(compiler_name='foo')
8+
self.plugin = CompilerPlugin(self.plugin_class)
9+
self.aliased_plugin = CompilerPlugin(self.plugin_class,
10+
aliases=['bar'])
11+
12+
@pytest.mark.parametrize('plugin_type', ['basic', 'aliased'])
13+
def test_init(self, plugin_type):
14+
plugin = {'basic': self.plugin,
15+
'aliased': self.aliased_plugin}[plugin_type]
16+
expected_alias = {'basic': [], 'aliased': ['bar']}[plugin_type]
17+
assert plugin.aliases == expected_alias
18+
assert plugin.plugin_class == self.plugin_class
19+
assert plugin.name == 'foo'

0 commit comments

Comments
 (0)