Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7af7eae
Add start to wizard
dwhswenson Feb 18, 2021
7fec891
TPS wizard works through state defs
dwhswenson Feb 19, 2021
250f4e2
a little more work on the wizard
dwhswenson Feb 27, 2021
666f9a9
major steps toward TPS wizard
dwhswenson Mar 4, 2021
8910ba2
A little more cleanup on wizard stuff
dwhswenson Mar 4, 2021
0b60338
Start to add tests for wizard
dwhswenson Mar 4, 2021
68066b1
tests for most of the Wizard object
dwhswenson Mar 6, 2021
4da1b9a
move MockConsole, start to get_object decorator
dwhswenson Mar 6, 2021
c17f3d1
more work toward using get_object
dwhswenson Mar 6, 2021
77fa5ce
tests for OpenMM wizard
dwhswenson Mar 6, 2021
76ea517
Prep tests for CVs
dwhswenson Mar 7, 2021
5d2e3f8
Some CV cleanup; more periodicity to CVs
dwhswenson Mar 7, 2021
b5ec9ce
Wizard ready for 2-state TPS demo
dwhswenson Mar 7, 2021
b32d03a
Add tests for CV wizards
dwhswenson Mar 7, 2021
a52bac0
tests for volume wizards
dwhswenson Mar 8, 2021
a9c4d96
simplify code to reflect current usage
dwhswenson Mar 8, 2021
a85118f
more cleanup of unused
dwhswenson Mar 8, 2021
42aa3c9
More tests; work toward handling Spring Shooting
dwhswenson Mar 18, 2021
13f7108
fix up tests
dwhswenson Mar 18, 2021
9d6c3dd
Add tests for shooting, load_from_ops
dwhswenson Mar 18, 2021
6467b59
Remove name from core (used as wizard.name)
dwhswenson Mar 19, 2021
d2050e4
Add tests for TPS wizard
dwhswenson Mar 20, 2021
94cd34e
Tests for two_state_tps.py
dwhswenson Mar 20, 2021
3f183de
tests for engines and errors
dwhswenson Mar 20, 2021
35c9ca1
Update for parsing.tools.custom_eval
dwhswenson Mar 26, 2021
97189a6
split off _do_one in wizard
dwhswenson Mar 26, 2021
f932fce
Add remaining tests for wizard
dwhswenson Jun 18, 2021
a3c7b4b
from unittest import mock...
dwhswenson Jun 18, 2021
a7fefd2
missed one
dwhswenson Jun 18, 2021
9259aca
fix for tests locally
dwhswenson Jun 18, 2021
10b676d
try ignoring wizard (does that fix test errors?)
dwhswenson Jun 18, 2021
8b7c8b8
re-include wizard tests
dwhswenson Jun 18, 2021
6c37dce
don't actually monkeypatch when testing Wizard
dwhswenson Jun 18, 2021
d444895
fix deprecation warnings for OPS 1.5
dwhswenson Jul 6, 2021
47106e6
Add Wizard (skeleton form) to docs
dwhswenson Jul 7, 2021
e9dd815
Add test job with openmm etc integrations
dwhswenson Jul 7, 2021
ea29ac4
fix whitespace in yaml
dwhswenson Jul 7, 2021
b52c1ef
fix include in yaml
dwhswenson Jul 7, 2021
3b64ce7
fix typo in workflow
dwhswenson Jul 7, 2021
8dcd07d
fix workflow
dwhswenson Jul 7, 2021
e774caa
increase fetch-depth to help codecov
dwhswenson Jul 7, 2021
d07699e
... helps is fetch-depth is in the right heading
dwhswenson Jul 7, 2021
2ba6390
finish test coverage
dwhswenson Jul 24, 2021
59b6fbe
Add test for bad MDTraj atom index input
dwhswenson Jul 24, 2021
4f3e53a
Add tests/wizard/__init__.py
dwhswenson Jul 24, 2021
0b33b79
no-cov on joke
dwhswenson Jul 24, 2021
60eb119
Apply suggestions from code review
dwhswenson Jul 26, 2021
3d92cd2
misc review cleanup
dwhswenson Jul 26, 2021
07b7d7c
Merge branch 'main' of github.com:openpathsampling/openpathsampling-c…
dwhswenson Jul 27, 2021
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
Prev Previous commit
Next Next commit
Start to add tests for wizard
  • Loading branch information
dwhswenson committed Mar 4, 2021
commit 0b60338d67114507c54f0dd0596f7dcd507d059b
12 changes: 12 additions & 0 deletions paths_cli/tests/wizard/mock_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from paths_cli.wizard.wizard import Wizard
import mock

def make_mock_wizard(inputs):
wizard = Wizard([])
wizard.console.input = mock.Mock(return_value=inputs)
return wizard

def make_mock_retry_wizard(inputs):
wizard = Wizard([])
wizard.console.input = mock.Mock(side_effect=inputs)
return wizard
51 changes: 51 additions & 0 deletions paths_cli/tests/wizard/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest
import mock

from openpathsampling.experimental.storage.collective_variables import \
CoordinateFunctionCV

from paths_cli.wizard.core import *

from paths_cli.tests.wizard.mock_wizard import (
make_mock_wizard, make_mock_retry_wizard
)

def test_name():
wizard = make_mock_wizard('foo')
cv = CoordinateFunctionCV(lambda s: s.xyz[0][0])
assert not cv.is_named
result = name(wizard, cv, obj_type="CV", store_name="cvs")
assert result is cv
assert result.is_named
assert result.name == 'foo'

def test_name_exists():
wizard = make_mock_retry_wizard(['foo', 'bar'])
wizard.cvs['foo'] = 'placeholder'
cv = CoordinateFunctionCV(lambda s: s.xyz[0][0])
assert not cv.is_named
result = name(wizard, cv, obj_type="CV", store_name="cvs")
assert result is cv
assert result.is_named
assert result.name == 'bar'
assert wizard.console.input.call_count == 2

@pytest.mark.parametrize('req,expected', [
(('foo', 2, 2), '2'), (('foo', 2, float('inf')), 'at least 2'),
(('foo', 0, 2), 'at most 2'),
(('foo', 1, 3), 'at least 1 and at most 3')
])
def test_interpret_req(req, expected):
assert interpret_req(req) == expected

@pytest.mark.parametrize('length,expected', [
(0, 'foo'), (1, 'baz'), (2, 'quux'),
])
def test_get_missing_object(length, expected):
dct = dict([('bar', 'baz'), ('qux', 'quux')][:length])
fallback = lambda x: 'foo'
wizard = make_mock_wizard('2')
result = get_missing_object(wizard, dct, display_name='string',
fallback_func=fallback)
assert result == expected
pass
Comment thread
dwhswenson marked this conversation as resolved.
Outdated
18 changes: 18 additions & 0 deletions paths_cli/tests/wizard/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import mock

from paths_cli.wizard.tools import *

@pytest.mark.parametrize('word,expected', [
('foo', 'a'), ('egg', 'an')
])
def test_a_an(word, expected):
assert a_an(word) == expected


@pytest.mark.parametrize('user_inp,expected', [
('y', True), ('n', False),
# ('Y', True), ('N', False), ('yes', True), ('no', False)
Comment thread
dwhswenson marked this conversation as resolved.
Outdated
])
def test_yes_no(user_inp, expected):
assert yes_no(user_inp) == expected
Empty file added paths_cli/wizard/__init__.py
Empty file.
11 changes: 6 additions & 5 deletions paths_cli/wizard/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from joke import name_joke
from tools import a_an
from paths_cli.wizard.joke import name_joke
from paths_cli.wizard.tools import a_an

def name(wizard, obj, obj_type, store_name, default=None):
wizard.say(f"Now let's name your {obj_type}.")
Expand All @@ -9,7 +9,8 @@ def name(wizard, obj, obj_type, store_name, default=None):
name = wizard.ask("What do you want to call it?")
if name in getattr(wizard, store_name):
wizard.bad_input(f"Sorry, you already have {a_an(obj_type)} "
f"named {name}. Please try another name.")
f"{obj_type} named {name}. Please try another "
"name.")
name = None

obj = obj.named(name)
Expand All @@ -19,7 +20,7 @@ def name(wizard, obj, obj_type, store_name, default=None):
return obj

def abort_retry_quit(wizard, obj_type):
a_an = 'an' if obj_type[0] in 'aeiou' else 'a'
a_an = a_an(obj_type)
retry = wizard.ask(f"Do you want to try again to make {a_an} "
f"{obj_type}, do you want to continue without, or "
f"do you want to quit?",
Expand Down Expand Up @@ -60,6 +61,6 @@ def get_missing_object(wizard, obj_dict, display_name, fallback_func):
objs = list(obj_dict.keys())
sel = wizard.ask_enumerate(f"Which {display_name} would you like "
"to use?", options=objs)
obj = objs[sel]
obj = obj_dict[sel]
return obj

4 changes: 3 additions & 1 deletion paths_cli/wizard/engines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import paths_cli.wizard.openmm as openmm
from load_from_ops import load_from_ops, LABEL as load_label
from paths_cli.wizard.load_from_ops import (
load_from_ops, LABEL as load_label
)
from functools import partial

SUPPORTED_ENGINES = {}
Expand Down
11 changes: 6 additions & 5 deletions paths_cli/wizard/openmm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from paths_cli.wizard.errors import FILE_LOADING_ERROR_MSG, not_installed
from paths_cli.wizard.tools import get_int_value
try:
from simtk import openmm as mm
import mdtraj as md
Expand Down Expand Up @@ -69,10 +68,12 @@ def openmm(wizard):

n_frames_max = n_steps_per_frame = None

n_steps_per_frame = get_int_value(wizard,
"How many MD steps per saved frame?")
n_frames_max = get_int_value(wizard, ("How many frames before aborting "
"a trajectory?"))
n_steps_per_frame = wizard.ask_custom_eval(
"How many MD steps per saved frame?", type_=int
)
n_frames_max = wizard.ask_custom_eval(
"How many frames before aborting a trajectory?", type_=int
)
# TODO: assemble the OpenMM simulation
engine = paths.engines.openmm.Engine(
topology=topology,
Expand Down
14 changes: 1 addition & 13 deletions paths_cli/wizard/tools.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@

def a_an(obj):
return "an" if obj[0] in "aeiou" else "a"
return "an" if obj[0].lower() in "aeiou" else "a"

def yes_no(char):
return {'y': True, 'n': False}[char]
Comment thread
dwhswenson marked this conversation as resolved.
Outdated

def get_int_value(wizard, question, default=None, helper=None):
as_int = None
while as_int is None:
evald = wizard.ask_custom_eval(question, default=default,
helper=helper)
try:
as_int = int(evald)
except Exception as e:
wizard.exception("Sorry, I didn't understand that.", e)
return as_int
6 changes: 3 additions & 3 deletions paths_cli/wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import shutil

class Console:
class Console: # no-cov
# TODO: add logging so we can output the session
def print(self, *content):
print(*content)
Expand Down Expand Up @@ -45,15 +45,15 @@ def __init__(self, steps):
self.default = {}
self._patched = False # if we've done the monkey-patching

def _patch(self):
def _patch(self): # no-cov
import openpathsampling as paths
from openpathsampling.experimental.storage import monkey_patch_all
if not self._patched:
paths = monkey_patch_all(paths)
paths.InterfaceSet.simstore = True
self._patched = True

def debug(content):
def debug(content): # no-cov
self.console.print(content)

def _speak(self, content, preface):
Expand Down