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))
"PhylogeneticInference": { IsStr: { # Which program to use; TODO: Add support for other programs "Program": StringIn(("examl",), default="examl"), # Exclude one or more samples from the phylogeny "ExcludeSamples": [IsStr], # Which samples to root the final trees on / or midpoint rooting "RootTreesOn": [IsStr], # Create a tree per gene, for each region of interest, # or create a supermatrix tree from all regions specified. "PerGeneTrees": IsBoolean(default=False), # Selection of regions of interest / settings per region "RegionsOfInterest": { IsStr: { "Partitions": Or(And(IsStr, ValuesSubsetOf("123456789X")), ValueIn([False]), default=REQUIRED_VALUE), "SubsetRegions": Or(IsStr, IsNone, default=None), }, }, "SubsetRegions": { IsStr: IsStr, }, "ExaML": { "Bootstraps": IsUnsignedInt(default=100), "Replicates": IsUnsignedInt(default=1), "Model": StringIn(("GAMMA", "PSR"), default="gamma"), } }
def test_subset_of__handles_types(value): spec = ValuesSubsetOf(list(range(5))) with pytest.raises(MakefileError, match="Expected value: subset of 0, 1, 2, 3, and 4"): spec(_DUMMY_PATH, value)
def test_subset_of__default_set__must_meet_spec(): with pytest.raises(ValueError): ValuesSubsetOf(list(range(5)), default=[4, 5])
def test_subset_of__default_set__valid_value(): spec = ValuesSubsetOf(list(range(5)), default=[3, 4]) assert spec.default == [3, 4]
def test_subset_of__default_not_set(): spec = ValuesSubsetOf(list(range(5))) assert spec.default is DEFAULT_NOT_SET
def test_subset_of__chars__case_sensitive__rejects_differences_in_case(): spec = ValuesSubsetOf("abcdefghijkl ") with pytest.raises(MakefileError): spec(_DUMMY_PATH, "A big DEAL")
############################################################################### ############################################################################### # 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), ) @pytest.mark.parametrize("spec, value", _PATH_IN_EXCEPTION_VALUES) def test_specs__path_is_displayed_in_exception(spec, value): with pytest.raises(MakefileError, match=_DUMMY_PATH_STR):
def test_subset_of__case_sensitive__value_in_not_set(): spec = ValuesSubsetOf(("Abc", "bCe", "cdE")) with pytest.raises(MakefileError): spec(_DUMMY_PATH, ["Bce"])
def test_subset_of__case_sensitive__value_in_set(): spec = ValuesSubsetOf(("Abc", "bCe", "cdE")) spec(_DUMMY_PATH, ["bCe"])
def test_subset_of__empty_set(): spec = ValuesSubsetOf(list(range(5))) spec(_DUMMY_PATH, [])
def test_subset_of__multiple_values_not_in_set(): spec = ValuesSubsetOf(list(range(5))) with pytest.raises(MakefileError): spec(_DUMMY_PATH, [4, 5])
def test_subset_of__multiple_values_in_set(): spec = ValuesSubsetOf(list(range(5))) spec(_DUMMY_PATH, [1, 4])
def test_subset_of__single_value_in_set(): spec = ValuesSubsetOf(list(range(5))) spec(_DUMMY_PATH, [1])
"DuplicateHist": IsBoolean(default=False), "RawBAM": IsBoolean(default=False), "RealignedBAM": IsBoolean(default=True), "Summary": IsBoolean(default=True), "mapDamage": Or(IsBoolean, StringIn(('rescale', 'model', 'plot', 'no', 'yes')), default=True) } _VALID_FEATURES_LIST = ValuesSubsetOf( ("Coverage", "Depths", "DuplicateHist", "mapDamage", "Raw BAM", "RawBAM", "Realigned BAM", "RealignedBAM", "Summary")) _VALID_EXCLUDE_DICT = { "Single": IsBoolean(default=False), "Collapsed": IsBoolean(default=False), "CollapsedTruncated": IsBoolean(default=False), "Paired": IsBoolean(default=False), "Singleton": IsBoolean(default=False), } _VALID_EXCLUDE_LIST = ValuesSubsetOf(_READ_TYPES) class BAMFeatures(PreProcessMakefile): """Makefile pre-processor that converts convert an old-style 'Features'
def test_subset_of__chars__case_sensitive(): spec = ValuesSubsetOf("abcdefghijkl ") spec(_DUMMY_PATH, "a big deal")
IsStr: { # Which program to use; TODO: Add support for other programs "Program": StringIn(("examl", ), default="examl"), # Exclude one or more samples from the phylogeny "ExcludeSamples": [IsStr], # Which samples to root the final trees on / or midpoint rooting "RootTreesOn": [IsStr], # Create a tree per gene, for each region of interest, # or create a supermatrix tree from all regions specified. "PerGeneTrees": IsBoolean(default=False), # Selection of regions of interest / settings per region "RegionsOfInterest": { IsStr: { "Partitions": Or( And(IsStr, ValuesSubsetOf("123456789X")), ValueIn([False]), default=REQUIRED_VALUE, ), "SubsetRegions": Or(IsStr, IsNone, default=None), } }, "SubsetRegions": { IsStr: IsStr }, "ExaML": { "Bootstraps": IsUnsignedInt(default=100), "Replicates": IsUnsignedInt(default=1), "Model": StringIn(("GAMMA", "PSR"), default="gamma"), },