-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP - initial commit of test suite for `runner.py`. * Added a few more tests to cover edge cases. The rest should be covered by other test suites.
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
import lephare as lp | ||
from lephare._lephare import keyword | ||
|
||
TESTDIR = os.path.abspath(os.path.dirname(__file__)) | ||
TESTDATADIR = os.path.join(TESTDIR, "../data") | ||
|
||
|
||
def test_runner_base(): | ||
"""This is the most rudimentary test of the Runner class. We have to provide | ||
both a list of config_keys and a path to a config file. We want to check only | ||
that the class can be instantiated and that the resulting keymap isn't empty.""" | ||
|
||
test_keys = ["key1", "key2", "key3"] | ||
config_file_path = os.path.join(TESTDATADIR, "examples/COSMOS.para") | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path) | ||
assert len(runner.keymap) | ||
|
||
|
||
def test_runner_no_config_keys(): | ||
"""Expect that a RuntimeError is raised when no config_keys or | ||
config_keys=None is passed to Runner.""" | ||
with pytest.raises(RuntimeError) as excinfo: | ||
lp.Runner() | ||
assert excinfo.value == "Runner is a base class and cannot be initialized" | ||
|
||
with pytest.raises(RuntimeError) as excinfo: | ||
lp.Runner(config_keys=None) | ||
assert excinfo.value == "Runner is a base class and cannot be initialized" | ||
|
||
|
||
def test_runner_config_keymap_updates(): | ||
"""This test checks that the keymap is updated when a config_keymap is passed | ||
to the Runner class.""" | ||
test_keys = ["key1", "key2", "key3"] | ||
config_file_path = os.path.join(TESTDATADIR, "examples/COSMOS.para") | ||
config_keymap = { | ||
"STAR_SED": keyword("STAR_SED", "foo"), | ||
"LIMITS_MAPP_CUT": keyword("LIMITS_MAPP_CUT", "42"), | ||
} | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path, config_keymap=config_keymap) | ||
|
||
resulting_keymap = runner.keymap | ||
assert resulting_keymap["STAR_SED"].value == "foo" | ||
assert resulting_keymap["LIMITS_MAPP_CUT"].value == "42" | ||
|
||
|
||
def test_runner_cannot_run(): | ||
"""Since the runner class is an abstract class, we expect that it cannot call | ||
the run method directly.""" | ||
|
||
test_keys = ["key1", "key2", "key3"] | ||
config_file_path = os.path.join(TESTDATADIR, "examples/COSMOS.para") | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path) | ||
|
||
with pytest.raises(Exception) as excinfo: | ||
runner.run() | ||
assert excinfo.value == "runner.py is an abstract class" | ||
|
||
|
||
def test_runner_verbosity(): | ||
"""Check to make sure that verbosity is set correctly via the config_keymap""" | ||
test_keys = ["key1", "key2", "key3"] | ||
config_file_path = os.path.join(TESTDATADIR, "examples/COSMOS.para") | ||
config_keymap = {} | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path, config_keymap=config_keymap) | ||
|
||
assert not runner.verbose | ||
|
||
config_keymap = {"VERBOSE": keyword("VERBOSE", "NO")} | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path, config_keymap=config_keymap) | ||
|
||
assert not runner.verbose | ||
|
||
config_keymap = {"VERBOSE": keyword("VERBOSE", "YES")} | ||
runner = lp.Runner(config_keys=test_keys, config_file=config_file_path, config_keymap=config_keymap) | ||
|
||
assert runner.verbose | ||
|
||
|
||
def test_runner_config_file_not_found(): | ||
"""Pass in a config file that does not exist and expect a RuntimeError.""" | ||
|
||
test_keys = ["key1", "key2", "key3"] | ||
config_file_path = os.path.join(TESTDATADIR, "foo/bar.para") | ||
|
||
with pytest.raises(RuntimeError) as excinfo: | ||
_ = lp.Runner(config_keys=test_keys, config_file=config_file_path) | ||
assert excinfo.value == f"File {config_file_path} not found" |