def test_is_str__rejects_empty_str(): with pytest.raises(MakefileError): IsStr()(_DUMMY_PATH, "") with pytest.raises(MakefileError): IsStr(min_len=1)(_DUMMY_PATH, "") with pytest.raises(MakefileError): IsStr(min_len=2)(_DUMMY_PATH, "") with pytest.raises(MakefileError): IsStr(min_len=3)(_DUMMY_PATH, "")
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__min_len_2(): spec = IsStr(min_len=2) with pytest.raises(MakefileError): spec(_DUMMY_PATH, "") with pytest.raises(MakefileError): spec(_DUMMY_PATH, "a") spec(_DUMMY_PATH, "ab") spec(_DUMMY_PATH, "abc")
% (", ".join(unknown_regions),)) # 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 "Sex": IsStr(), "Gender": IsStr(), } } _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 %= (", and %r" % whitelist, ) if whitelist else "" whitelist += string.ascii_letters + string.digits return And(IsStr(min_len=min_len), 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 = _alphanum_check(whitelist="._-", min_len=2) _VALID_FEATURES_DICT = { "Coverage": IsBoolean(default=True), "Depths": IsBoolean(default=True), "DuplicateHist": RemovedOption(), "RawBAM": RemovedOption(), "RealignedBAM": RemovedOption(), "Summary": IsBoolean(default=True), "mapDamage": StringIn(("rescale", "model", "plot")), }
def test_is_str__min_len_0(): spec = IsStr(min_len=0) spec(_DUMMY_PATH, "") spec(_DUMMY_PATH, "a") spec(_DUMMY_PATH, "ab")
def test_is_str__default_set__must_meet_spec(): with pytest.raises(ValueError): IsStr(default=17)
def test_is_str__default_set__valid_value(): spec = IsStr(default="abc") assert spec.default == "abc"
def test_is_dict_of__defaults_not_set_in_value_specs(): with pytest.raises(ValueError): IsDictOf(IsInt, IsInt(default=10)) ############################################################################### ############################################################################### # Path is displayed in exception _PATH_IN_EXCEPTION_VALUES = ( (IsInt(), "foo"), (IsUnsignedInt(), -1), (IsFloat(), "abc"), (IsBoolean(), 1), (IsStr(), 1), (IsNone(), 1), (ValueIn([1]), 2), (ValuesIntersect([1]), [2]), (ValuesSubsetOf([1]), [2]), (ValueMissing(), True), (And(IsStr), 1), (Or(IsStr), 1), (Not(IsInt), 1), (StringIn("abc"), 1), (StringStartsWith("FOO"), 1), (StringEndsWith("FOO"), 1), (IsListOf(IsInt), "foo"), (IsDictOf(IsInt, IsInt), 1), )
def test_is_str__custom_description(): custom_desc = "a ball of string" spec = IsStr(description=custom_desc) assert spec.description == custom_desc
def test_is_str__default_description(): spec = IsStr() assert spec.description == "a non-empty string"
def test_is_str__rejects_not_str(value): spec = IsStr() with pytest.raises(MakefileError, match="Expected value: a non-empty string"): spec(_DUMMY_PATH, value)
def test_is_str__rejects_negative_min_len(): with pytest.raises(ValueError): IsStr(min_len=-1)
def test_is_str__accepts_empty_str(): spec = IsStr(min_len=0) spec(_DUMMY_PATH, "")
def test_is_str__accepts_standard_str(): spec = IsStr() spec(_DUMMY_PATH, "abc")
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")) _VALID_FEATURES_DICT = { "Coverage": IsBoolean(default=True), "Depths": IsBoolean(default=True), "DuplicateHist": IsBoolean(default=False), "RawBAM":
def test_is_str__default_not_set(): spec = IsStr() assert spec.default is DEFAULT_NOT_SET
unknown_regions = set(msa) - set(mkfile["Project"]["Regions"]) if unknown_regions: raise MakefileError("Unknown Regions of Interest in Genotyping: %s" % (", ".join(unknown_regions), )) # 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": RemovedOption(), "SpeciesName": RemovedOption(), "CommonName": RemovedOption(), "Sex": IsStr(), "Gender": RemovedOption(), } } _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)