def test_process_makefile__shared_subtrees_with_defaults__defaults_disabled(): subtree = {"A": IsInt(default=1234), "B": IsInt(default=5678)} specs = {"A": subtree, "B": WithoutDefaults(subtree)} current = {"A": {"B": 17}, "B": {"A": 71}} expected = {"A": {"A": 1234, "B": 17}, "B": {"A": 71}} result = process_makefile(current, specs) assert_equal(result, expected)
def test_process_makefile__sets_missing_keys(): current = {"A": 1} specs = { "A": IsInt(default=0), "B": IsInt(default=-1), "C": IsInt(default=-2) } expected = {"A": 1, "B": -1, "C": -2} result = process_makefile(current, specs) assert_equal(result, expected)
def test_process_makefile__sets_missing_recursive__with_missing_substructure(): current = {"A": 1} specs = { "A": IsInt(default=0), "B": { "C": IsInt(default=-1), "D": IsInt(default=-2) } } expected = {"A": 1, "B": {"C": -1, "D": -2}} result = process_makefile(current, specs) assert_equal(result, expected)
def test_specs__path_is_displayed_in_exception(): def _path_is_displayed_in_exception(spec, value): assert_raises_regexp(MakefileError, _DUMMY_PATH_STR, spec, _DUMMY_PATH, value) yield _path_is_displayed_in_exception, IsInt(), "foo" yield _path_is_displayed_in_exception, IsUnsignedInt(), -1 yield _path_is_displayed_in_exception, IsFloat(), "abc" yield _path_is_displayed_in_exception, IsBoolean(), 1 yield _path_is_displayed_in_exception, IsStr(), 1 yield _path_is_displayed_in_exception, IsNone(), 1 yield _path_is_displayed_in_exception, ValueLT(0), 1 yield _path_is_displayed_in_exception, ValueLE(0), 1 yield _path_is_displayed_in_exception, ValueGE(0), -1 yield _path_is_displayed_in_exception, ValueGT(0), -1 yield _path_is_displayed_in_exception, ValueIn([1]), 2 yield _path_is_displayed_in_exception, ValuesIntersect([1]), [2] yield _path_is_displayed_in_exception, ValuesSubsetOf([1]), [2] yield _path_is_displayed_in_exception, ValueMissing(), True yield _path_is_displayed_in_exception, And(IsStr), 1 yield _path_is_displayed_in_exception, Or(IsStr), 1 yield _path_is_displayed_in_exception, Xor(IsStr, IsInt), True yield _path_is_displayed_in_exception, Not(IsInt), 1 yield _path_is_displayed_in_exception, StringIn("abc"), 1 yield _path_is_displayed_in_exception, StringsIntersect("abc"), [1] yield _path_is_displayed_in_exception, StringsSubsetOf("abc"), [1] yield _path_is_displayed_in_exception, StringIsUppercase(), 1 yield _path_is_displayed_in_exception, StringStartsWith("FOO"), 1 yield _path_is_displayed_in_exception, StringEndsWith("FOO"), 1 yield _path_is_displayed_in_exception, IsListOf(IsInt), "foo" yield _path_is_displayed_in_exception, IsDictOf(IsInt, IsInt), 1
def test_xor__defaults_not_set_in_specs(): assert_raises(ValueError, Xor, IsInt(default=10), ValueGT(10))
def test_is_int__accepts_integers(): spec = IsInt() spec(_DUMMY_PATH, 1234) spec(_DUMMY_PATH, 0) spec(_DUMMY_PATH, -1234)
def test_process_makefile__implicit_subdict_is_allowed(): current = {"A": 1, "B": None} expected = {"A": 1, "B": {"C": 3}} specs = {"A": IsInt, "B": {"C": IsInt(default=3)}} result = process_makefile(current, specs) assert_equal(result, expected)
def test_process_makefile__accept_missing_value_if_in_implicit_subtree(): current = {"A": 1} expected = {"A": 1} specs = {"A": IsInt, IsStr: {"C": IsInt(default=REQUIRED_VALUE)}} result = process_makefile(current, specs) assert_equal(result, expected)
def test_process_makefile__fails_required_value_not_set_in_dynamic_subtree(): current = {"A": 1, "B": {}} specs = {"A": IsInt, IsStr: {"C": IsInt(default=REQUIRED_VALUE)}} assert_raises(MakefileError, process_makefile, current, specs)
def test_process_makefile__fails_when_required_value_not_set(): current = {"A": 1} specs = {"A": IsInt, "B": {"C": IsInt(default=REQUIRED_VALUE)}} assert_raises(MakefileError, process_makefile, current, specs)
def test_process_makefile__accept_when_required_value_is_set(): current = {"A": 1, "B": {"C": 3}} expected = {"A": 1, "B": {"C": 3}} specs = {"A": IsInt, "B": {"C": IsInt(default=REQUIRED_VALUE)}} result = process_makefile(current, specs) assert_equal(result, expected)
def test_is_int__default_description(): spec = IsInt() assert_equal(spec.description, "an integer")
def _reject_not_str(value): spec = IsInt() assert_raises(MakefileError, spec, _DUMMY_PATH, value)
def test_is_int__accepts_longs(): spec = IsInt() spec(_DUMMY_PATH, 1234L) spec(_DUMMY_PATH, 0L) spec(_DUMMY_PATH, -1234L)
def test_is_dict_of__defaults_not_set_in_value_specs(): assert_raises(ValueError, IsDictOf, IsInt, IsInt(default=10))
def test_is_int__default_set__valid_value(): spec = IsInt(default=7913) assert_equal(spec.default, 7913)
def test_is_list_of__defaults_not_set_in_specs(): assert_raises(ValueError, IsListOf, IsInt(default=10))
def test_is_int__default_not_set(): spec = IsInt() assert_is(spec.default, DEFAULT_NOT_SET)
def test_is_int__custom_description(): custom_desc = "any old integer" spec = IsInt(description=custom_desc) assert_equal(spec.description, custom_desc)
def test_not__defaults_not_set_in_specs(): assert_raises(ValueError, Not, IsInt(default=10))
import pprint from pypeline.common.makefile import \ MakefileError, \ read_makefile, \ WithoutDefaults, \ Or, \ IsInt, \ IsFloat, \ IsStr, \ StringStartsWith _SPECIFICATION_OF_OPTIONS = { StringStartsWith("--") : Or(IsInt, IsFloat), "--min-depth" : IsInt(default = 8), "--max-depth" : IsInt(default = 100), } _MAKEFILE_SPECIFICATION = { "Defaults" : _SPECIFICATION_OF_OPTIONS, "VCF_Files" : { IsStr : { "Output_File" : IsStr, "Options" : WithoutDefaults(_SPECIFICATION_OF_OPTIONS), } } }