Skip to content

Commit

Permalink
add new worker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Hernandez committed Aug 2, 2016
1 parent 9b2d2b9 commit 1a11835
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 38 deletions.
29 changes: 0 additions & 29 deletions examples/config-2.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion osprey/cli/parser_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from argparse import ArgumentDefaultsHelpFormatter


from ..execute_skeleton import TEMPLATES

def func(args, parser):
# delay import of the rest of the module to improve `osprey -h` performance
from ..execute_skeleton import execute
Expand All @@ -15,7 +17,7 @@ def configure_parser(sub_parsers):
p.add_argument('-t', '--template', help=(
"which skeleton to create. 'msmbuilder' is a skeleton config file for"
"MSMBuilder molecular dynamics / Markov state model based "
"projects."), choices=['msmbuilder', 'sklearn'], default='msmbuilder',)
"projects."), choices=TEMPLATES.keys(), default='msmbuilder')
p.add_argument('-f', '--filename', help='config filename to create',
default='config.yaml')
p.set_defaults(func=func)
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions osprey/execute_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from os.path import join, exists
from pkg_resources import resource_filename

TEMPLATES = {'msmbuilder': 'msmbuilder_skeleton_config.yaml',
'sklearn': 'sklearn_skeleton_config.yaml',
'random_example': 'random_example.yaml',
'gp_example': 'sklearn_skeleton_config.yaml',
'grid_example': 'grid_example.yaml'}


def execute(args, parser):
if args.template == 'msmbuilder':
fn = resource_filename('osprey', join('data',
'msmbuilder_skeleton_config.yaml'))
elif args.template == 'sklearn':
fn = resource_filename('osprey', join('data',
'sklearn_skeleton_config.yaml'))
template_file = TEMPLATES.get(args.template, None)
if template_file:
fn = resource_filename('osprey', join('data', template_file))
else:
raise RuntimeError('unknown template: %s' % args.template)

Expand Down
75 changes: 73 additions & 2 deletions osprey/tests/test_cli_worker_and_dump.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import print_function, absolute_import, division
import os
import os.path
import sys
import json
import shutil
import subprocess
import tempfile
from shutil import copyfile
from distutils.spawn import find_executable
from numpy.testing.decorators import skipif

Expand All @@ -18,7 +20,7 @@


@skipif(not HAVE_MSMBUILDER, 'this test requires MSMBuilder')
def test_1():
def test_msmbuilder_skeleton():
from msmbuilder.example_datasets import FsPeptide
assert OSPREY_BIN is not None
cwd = os.path.abspath(os.curdir)
Expand All @@ -41,7 +43,7 @@ def test_1():
shutil.rmtree(dirname)


def test_2():
def test_sklearn_skeleton():
assert OSPREY_BIN is not None
cwd = os.path.abspath(os.curdir)
dirname = tempfile.mkdtemp()
Expand All @@ -64,6 +66,75 @@ def test_2():
shutil.rmtree(dirname)


def test_random_example():
assert OSPREY_BIN is not None
cwd = os.path.abspath(os.curdir)
dirname = tempfile.mkdtemp()

try:
os.chdir(dirname)
subprocess.check_call([OSPREY_BIN, 'skeleton', '-t', 'random_example',
'-f', 'config.yaml'])
subprocess.check_call([OSPREY_BIN, 'worker', 'config.yaml', '-n', '1'])
assert os.path.exists('osprey-trials.db')

subprocess.check_call([OSPREY_BIN, 'current_best', 'config.yaml'])

yield _test_dump_1

yield _test_plot_1

finally:
os.chdir(cwd)
shutil.rmtree(dirname)


def test_gp_example():
assert OSPREY_BIN is not None
cwd = os.path.abspath(os.curdir)
dirname = tempfile.mkdtemp()

try:
os.chdir(dirname)
subprocess.check_call([OSPREY_BIN, 'skeleton', '-t', 'gp_example',
'-f', 'config.yaml'])
subprocess.check_call([OSPREY_BIN, 'worker', 'config.yaml', '-n', '1'])
assert os.path.exists('osprey-trials.db')

subprocess.check_call([OSPREY_BIN, 'current_best', 'config.yaml'])

yield _test_dump_1

yield _test_plot_1

finally:
os.chdir(cwd)
shutil.rmtree(dirname)


def test_grid_example():
assert OSPREY_BIN is not None
cwd = os.path.abspath(os.curdir)
dirname = tempfile.mkdtemp()

try:
os.chdir(dirname)
subprocess.check_call([OSPREY_BIN, 'skeleton', '-t', 'grid_example',
'-f', 'config.yaml'])
subprocess.check_call([OSPREY_BIN, 'worker', 'config.yaml', '-n', '1'])
assert os.path.exists('osprey-trials.db')

subprocess.check_call([OSPREY_BIN, 'current_best', 'config.yaml'])

yield _test_dump_1

yield _test_plot_1

finally:
os.chdir(cwd)
shutil.rmtree(dirname)


def _test_dump_1():
out = subprocess.check_output(
[OSPREY_BIN, 'dump', 'config.yaml', '-o', 'json'])
Expand Down

0 comments on commit 1a11835

Please sign in to comment.