def test_process_makefile__dict_keys_not_found(): def _dict_keys_missing(current, specs): assert_raises(MakefileError, process_makefile, current, specs) # String keys yield _dict_keys_missing, {"C": 7}, {"A": IsInt, "B": IsInt} # Spec keys yield _dict_keys_missing, {1.3: "Abc"}, {IsStr: IsInt, IsInt: IsStr} # Spec keys, instantiated yield _dict_keys_missing, {1.3: "Abc"}, {IsStr(): IsInt, IsInt: IsStr()} # Mixed keys, spec matches yield _dict_keys_missing, {"C": 14}, {IsInt: IsInt, "A": IsInt} yield _dict_keys_missing, {"A": 23}, {}
def test_process_makefile__dict_keys_found(): def _dict_keys_found(current, specs): process_makefile(current, specs) # String keys yield _dict_keys_found, {"B": 7}, {"A": IsInt, "B": IsInt} # Spec keys yield _dict_keys_found, {1: "Abc"}, {IsStr: IsInt, IsInt: IsStr} # Spec keys, instantiated yield _dict_keys_found, {1: "Abc"}, {IsStr(): IsInt, IsInt: IsStr()} # Mixed keys, spec matches yield _dict_keys_found, {3: 14}, {IsInt: IsInt, "A": IsInt} # Mixed keys, key matches yield _dict_keys_found, {"A": 23}, {IsInt: IsInt, "A": IsInt}
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 _alphanum_check(whitelist): description = "characters a-z, A-Z, 0-9%s allowed" description %= (", and %r" % whitelist, ) if whitelist else "" whitelist += string.ascii_letters + string.digits return And(IsStr(), ValuesSubsetOf(whitelist, description=description))
def test_is_str__default_set__valid_value(): spec = IsStr(default="abc") assert_equal(spec.default, "abc")
def test_is_str__default_not_set(): spec = IsStr() assert_is(spec.default, DEFAULT_NOT_SET)
def test_is_str__custom_description(): custom_desc = "a ball of string" spec = IsStr(description=custom_desc) assert_equal(spec.description, custom_desc)
def test_is_str__default_description(): spec = IsStr() assert_equal(spec.description, "a non-empty string")
def _reject_not_str(value): spec = IsStr() assert_raises(MakefileError, spec, _DUMMY_PATH, value)
def test_is_str__rejects_empty_str(): spec = IsStr() assert_raises(MakefileError, spec, _DUMMY_PATH, "")
def test_is_str__accepts_unicode_str(): spec = IsStr() spec(_DUMMY_PATH, u"def")
def test_is_str__accepts_standard_str(): spec = IsStr() spec(_DUMMY_PATH, "abc")
# Recursive definition of sample tree _VALIDATION_SUBSAMPLE_KEY = And(StringStartsWith("<"), StringEndsWith(">")) _VALIDATION_SAMPLES_KEY = And(IsStr, Not(_VALIDATION_SUBSAMPLE_KEY)) _VALIDATION_SAMPLES = { _VALIDATION_SAMPLES_KEY: { "GenotypingMethod": StringIn(("reference sequence", "random sampling", "samtools"), default="samtools"), "SpeciesName": IsStr, # Not used; left for backwards compatibility "CommonName": IsStr, # Not used; left for backwards compatibility "Gender": IsStr(default=REQUIRED_VALUE), } } _VALIDATION_SAMPLES[_VALIDATION_SUBSAMPLE_KEY] = _VALIDATION_SAMPLES # Genotyping settings; note that explicit lists must not be used here, to allow # proper inheritance of default values. Use IsListOf instead. _VALIDATION_GENOTYPES = { "Padding": IsUnsignedInt, "GenotypeEntirePrefix": IsBoolean(default=False), "MPileup": { StringStartsWith("-"): Or(IsInt, IsStr, IsNone), }, "BCFTools": { StringStartsWith("-"): Or(IsInt, IsStr, IsNone), },
description = "characters a-z, A-Z, 0-9%s allowed" description %= (", and %r" % whitelist, ) if whitelist else "" whitelist += string.ascii_letters + string.digits return And(IsStr(), ValuesSubsetOf(whitelist, description=description)) # Valid names for prefixes _VALID_PREFIX_NAME = \ And(_alphanum_check(whitelist="._-*"), Not(StringIn(["Options"] + [(s + "Reads") for s in _READ_TYPES]))) # Valid paths for prefixes; avoids some problems with e.g. Bowtie2 _VALID_PREFIX_PATH = \ And(IsStr(), Not(ValuesIntersect("\\:?\"<>|() \t\n\v\f\r")), default=REQUIRED_VALUE) # Valid strings for targets / samples / libraries / lanes _VALID_TARGET_NAME = \ And(_alphanum_check(whitelist="._-"), ValueGE(2, key=len, description="at least two characters long")) _VALIDATION_OPTIONS = { # Sequencing platform, used to tag read-groups. "Platform": StringIn(("CAPILLARY", "LS454", "ILLUMINA", "SOLID", "HELICOS", "IONTORRENT", "PACBIO"), default="ILLUMINA"), # Offset for quality scores in FASTQ files. "QualityOffset":