Skip to content

Commit

Permalink
Merge pull request #69 from dwhswenson/include-tests-coverage
Browse files Browse the repository at this point in the history
Stop excluding tests from coverage
  • Loading branch information
dwhswenson authored Dec 10, 2021
2 parents f9cd13d + f0d946b commit 600d361
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 45 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[report]
omit =
*/paths_cli/tests/*
*/paths_cli/_installed_version.py
*/paths_cli/version.py
exclude_lines =
Expand Down
2 changes: 1 addition & 1 deletion paths_cli/compiling/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion paths_cli/tests/commands/test_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion paths_cli/tests/commands/utils.py
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
2 changes: 1 addition & 1 deletion paths_cli/tests/compiling/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
37 changes: 27 additions & 10 deletions paths_cli/tests/compiling/test_volumes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion paths_cli/tests/test_file_copying.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion paths_cli/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion paths_cli/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions paths_cli/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion paths_cli/tests/wizard/mock_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions paths_cli/tests/wizard/test_load_from_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions paths_cli/tests/wizard/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 2 additions & 12 deletions paths_cli/tests/wizard/test_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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']
Expand Down
2 changes: 2 additions & 0 deletions paths_cli/tests/wizard/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 600d361

Please sign in to comment.