diff --git a/.coveragerc b/.coveragerc index d5a61508..66545f18 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,5 @@ [report] omit = - */paths_cli/tests/* */paths_cli/_installed_version.py */paths_cli/version.py exclude_lines = diff --git a/paths_cli/compiling/core.py b/paths_cli/compiling/core.py index 7791005f..0a68c01e 100644 --- a/paths_cli/compiling/core.py +++ b/paths_cli/compiling/core.py @@ -153,7 +153,7 @@ class InstanceCompilerPlugin(OPSPlugin): """ SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json" category = None - + def __init__(self, builder, parameters, name=None, *, aliases=None, description=None, requires_ops=(1, 0), requires_cli=(0, 3)): diff --git a/paths_cli/tests/commands/test_md.py b/paths_cli/tests/commands/test_md.py index f4aab68f..b35df94b 100644 --- a/paths_cli/tests/commands/test_md.py +++ b/paths_cli/tests/commands/test_md.py @@ -159,7 +159,7 @@ def test_md_main(md_fixture, inp): nsteps, ensembles = 5, None elif inp == 'ensemble': nsteps, ensembles = None, [ens] - else: + else: # -no-cov- raise RuntimeError("pytest went crazy") traj, foo = md_main( diff --git a/paths_cli/tests/commands/utils.py b/paths_cli/tests/commands/utils.py index 27a31d16..c1f665c0 100644 --- a/paths_cli/tests/commands/utils.py +++ b/paths_cli/tests/commands/utils.py @@ -1,7 +1,7 @@ import traceback def assert_click_success(result): - if result.exit_code != 0: + if result.exit_code != 0: # -no-cov- (only occurs on test error) print(result.output) traceback.print_tb(result.exc_info[2]) print(result.exc_info[0], result.exc_info[1]) diff --git a/paths_cli/tests/compiling/test_core.py b/paths_cli/tests/compiling/test_core.py index 6c8be07e..86fd95f5 100644 --- a/paths_cli/tests/compiling/test_core.py +++ b/paths_cli/tests/compiling/test_core.py @@ -332,7 +332,7 @@ def _validate_obj(obj, input_type): assert obj == 'bar' elif input_type == 'dict': assert obj.data == 'qux' - else: + else: # -no-cov- raise RuntimeError("Error in test setup") @pytest.mark.parametrize('input_type', ['str', 'dict']) diff --git a/paths_cli/tests/compiling/test_volumes.py b/paths_cli/tests/compiling/test_volumes.py index f28bf4e3..cc3cc408 100644 --- a/paths_cli/tests/compiling/test_volumes.py +++ b/paths_cli/tests/compiling/test_volumes.py @@ -1,6 +1,8 @@ import pytest from unittest import mock from paths_cli.tests.compiling.utils import mock_compiler +from paths_cli.compiling.plugins import CVCompilerPlugin +from paths_cli.compiling.core import Parameter import yaml import numpy as np @@ -23,20 +25,20 @@ def setup(self): } self.func = { - 'inline': "\n ".join(["name: foo", "type: mdtraj"]), + 'inline': "\n " + "\n ".join([ + "name: foo", + "type: fake_type", + "input_data: bar", + ]), 'external': 'foo' } - def create_inputs(self, inline, periodic): - yml = "\n".join(["type: cv-volume", "cv: {func}", - "lambda_min: 0", "lambda_max: 1"]) - def set_periodic(self, periodic): if periodic == 'periodic': self.named_objs_dict['foo']['period_max'] = 'np.pi' self.named_objs_dict['foo']['period_min'] = '-np.pi' - @pytest.mark.parametrize('inline', ['external', 'external']) + @pytest.mark.parametrize('inline', ['external', 'inline']) @pytest.mark.parametrize('periodic', ['periodic', 'nonperiodic']) def test_build_cv_volume(self, inline, periodic): self.set_periodic(periodic) @@ -47,14 +49,29 @@ def test_build_cv_volume(self, inline, periodic): mock_cv = CoordinateFunctionCV(lambda s: s.xyz[0][0], period_min=period_min, period_max=period_max).named('foo') + + patch_loc = 'paths_cli.compiling.root_compiler._COMPILERS' + if inline =='external': - patch_loc = 'paths_cli.compiling.root_compiler._COMPILERS' compilers = { 'cv': mock_compiler('cv', named_objs={'foo': mock_cv}) } - with mock.patch.dict(patch_loc, compilers): - vol = build_cv_volume(dct) - elif inline == 'internal': + elif inline == 'inline': + fake_plugin = CVCompilerPlugin( + name="fake_type", + parameters=[Parameter('input_data', str)], + builder=lambda input_data: mock_cv + ) + compilers = { + 'cv': mock_compiler( + 'cv', + type_dispatch={'fake_type': fake_plugin} + ) + } + else: # -no-cov- + raise RuntimeError("Should never get here") + + with mock.patch.dict(patch_loc, compilers): vol = build_cv_volume(dct) in_state = make_1d_traj([0.5])[0] diff --git a/paths_cli/tests/test_file_copying.py b/paths_cli/tests/test_file_copying.py index 0a59cbc6..a32408ed 100644 --- a/paths_cli/tests/test_file_copying.py +++ b/paths_cli/tests/test_file_copying.py @@ -59,7 +59,8 @@ def __init__(self): self.previously_seen = set([]) def __call__(self, snap): - if snap in self.previously_seen: + if snap in self.previously_seen: # -no-cov- + # this is only covered if an error occurs raise AssertionError("Second CV eval for " + str(snap)) self.previously_seen.update({snap}) return snap.xyz[0][0] diff --git a/paths_cli/tests/test_parameters.py b/paths_cli/tests/test_parameters.py index 4bd2651f..e495ad8a 100644 --- a/paths_cli/tests/test_parameters.py +++ b/paths_cli/tests/test_parameters.py @@ -103,7 +103,7 @@ def _filename(self, getter): def create_file(self, getter): filename = self._filename(getter) - if getter == "named": + if getter == "name": self.other_scheme = self.other_scheme.named("other") self.other_engine = self.other_engine.named("other") diff --git a/paths_cli/tests/test_utils.py b/paths_cli/tests/test_utils.py index b6234ec5..1d43c6ff 100644 --- a/paths_cli/tests/test_utils.py +++ b/paths_cli/tests/test_utils.py @@ -10,7 +10,7 @@ def test_len(self): def test_empty(self): ordered = OrderedSet() assert len(ordered) == 0 - for _ in ordered: + for _ in ordered: # -no-cov- raise RuntimeError("This should not happen") def test_order(self): diff --git a/paths_cli/tests/utils.py b/paths_cli/tests/utils.py index 7dbcf247..a00ffa7a 100644 --- a/paths_cli/tests/utils.py +++ b/paths_cli/tests/utils.py @@ -3,13 +3,13 @@ try: urllib.request.urlopen('https://www.google.com') -except: +except: # -no-cov- HAS_INTERNET = False else: HAS_INTERNET = True def assert_url(url): - if not HAS_INTERNET: + if not HAS_INTERNET: # -no-cov- pytest.skip("Internet connection seems faulty") # TODO: On a 404 this will raise a urllib.error.HTTPError. It would be diff --git a/paths_cli/tests/wizard/mock_wizard.py b/paths_cli/tests/wizard/mock_wizard.py index d273c5be..59dc07d5 100644 --- a/paths_cli/tests/wizard/mock_wizard.py +++ b/paths_cli/tests/wizard/mock_wizard.py @@ -30,7 +30,9 @@ def input(self, content): self.input_call_count += 1 try: user_input = next(self._input_iter) - except StopIteration as e: + except StopIteration as e: # -no-cov- + # this only occurs on a test error and provides diagnostic + # information print(self.log_text) raise e diff --git a/paths_cli/tests/wizard/test_load_from_ops.py b/paths_cli/tests/wizard/test_load_from_ops.py index a5ce9675..7b32d8d9 100644 --- a/paths_cli/tests/wizard/test_load_from_ops.py +++ b/paths_cli/tests/wizard/test_load_from_ops.py @@ -20,13 +20,15 @@ def __init__(self, objects): self._objects = objects self._named_objects = {obj.name: obj for obj in objects} - def __getitem__(self, key): - if isinstance(key, int): - return self._objects[key] - elif isinstance(key, str): - return self._named_objects[key] - else: - raise TypeError("Huh?") + # leaving this commented out... it doesn't seem to be used currently, + # but if it is needed in the future, this should be the implementation + # def __getitem__(self, key): + # if isinstance(key, int): + # return self._objects[key] + # elif isinstance(key, str): + # return self._named_objects[key] + # else: # -no-cov- + # raise TypeError("Huh?") def __iter__(self): return iter(self._objects) diff --git a/paths_cli/tests/wizard/test_parameters.py b/paths_cli/tests/wizard/test_parameters.py index 9cdf3ff6..f4774e08 100644 --- a/paths_cli/tests/wizard/test_parameters.py +++ b/paths_cli/tests/wizard/test_parameters.py @@ -15,16 +15,12 @@ class TestWizardParameter: def _reverse(string): return "".join(reversed(string)) - @staticmethod - def _summarize(string): - return f"Here's a summary: we made {string}" - def setup(self): self.parameter = WizardParameter( name='foo', ask="How should I {do_what}?", loader=self._reverse, - summarize=self._summarize, + summarize=lambda string: f"Should be unused. Input: {string}", ) self.wizard = mock_wizard(["bar"]) self.compiler_plugin = compiling.InstanceCompilerPlugin( diff --git a/paths_cli/tests/wizard/test_volumes.py b/paths_cli/tests/wizard/test_volumes.py index 368c9244..52a6937d 100644 --- a/paths_cli/tests/wizard/test_volumes.py +++ b/paths_cli/tests/wizard/test_volumes.py @@ -16,15 +16,6 @@ from openpathsampling.tests.test_helpers import make_1d_traj -def _wrap(x, period_min, period_max): - # used in testing periodic CVs - while x >= period_max: - x -= period_max - period_min - while x < period_min: - x += period_max - period-min - return x - - @pytest.fixture def volume_setup(): cv = CoordinateFunctionCV(lambda snap: snap.xyz[0][0]).named('x') @@ -54,7 +45,7 @@ def test_volume_intro(as_state, has_state): assert "You'll need to define" in intro elif not as_state: assert intro == _VOL_DESC - else: + else: # -no-cov- raise RuntimeError("WTF?") def _binary_volume_test(volume_setup, func): @@ -120,8 +111,7 @@ def test_cv_defined_volume(periodic): min_ = 0.0 max_ = 1.0 cv = CoordinateFunctionCV( - lambda snap: _wrap(snap.xyz[0][0], period_min=min_, - period_max=max_), + lambda snap: snap.xyz[0][0], period_min=min_, period_max=max_ ).named('x') inputs = ['x', '0.75', '1.25'] diff --git a/paths_cli/tests/wizard/test_wizard.py b/paths_cli/tests/wizard/test_wizard.py index c8d50671..b377c568 100644 --- a/paths_cli/tests/wizard/test_wizard.py +++ b/paths_cli/tests/wizard/test_wizard.py @@ -309,6 +309,7 @@ def test_save_to_file(self, toy_engine): assert len(storage.networks) == len(storage.schemes) == 0 assert len(storage.engines) == 1 assert storage.engines[toy_engine.name] == toy_engine + assert storage.engines[0] == toy_engine assert "Everything has been stored" in self.wizard.console.log_text @pytest.mark.parametrize('req,count,expected', [ @@ -382,6 +383,7 @@ def test_run_wizard(self, toy_engine): assert len(storage.networks) == len(storage.schemes) == 0 assert len(storage.engines) == 1 assert storage.engines[toy_engine.name] == toy_engine + assert storage.engines[0] == toy_engine def test_run_wizard_quit(self): console = MockConsole()