def test_and__default_not_set(): spec = And(IsInt, ValueIn(list(range(10)))) assert spec.default is DEFAULT_NOT_SET
def test_value_in__single_value_in_set(): spec = ValueIn(list(range(5))) spec(_DUMMY_PATH, 1)
def test_and__rejects_when_both_is_false(): spec = And(IsFloat, ValueIn((0.0, 1, 2))) with pytest.raises(MakefileError): spec(_DUMMY_PATH, 3)
def test_or__defaults_not_set_in_specs(): with pytest.raises(ValueError): Or(IsInt(default=10), ValueIn((10, )))
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_and__defaults_not_set_in_specs(): with pytest.raises(ValueError): And(IsInt(default=10), ValueIn((list(range(100)))))
def test_or__default_set__valid_value(): spec = Or(IsInt, ValueIn((10, )), default=17) assert spec.default == 17
def test_value_in__default_description(): spec = ValueIn(("Abc", "bCe", "cdE")) assert spec.description == "value in 'Abc', 'bCe', or 'cdE'"
def test_value_in__custom_description(): spec = ValueIn(("Abc", "bCe", "cdE"), description="One of {rvalue}") assert spec.description == "One of 'Abc', 'bCe', or 'cdE'"
def test_value_in__case_sensitive__value_in_set(): spec = ValueIn(("Abc", "bCe", "cdE")) spec(_DUMMY_PATH, "bCe")
def test_value_in__case_sensitive__value_in_not_set(): spec = ValueIn(("Abc", "bCe", "cdE")) with pytest.raises(MakefileError): spec(_DUMMY_PATH, "Bce")
def test_value_in__single_value_not_in_set__with_key(): spec = ValueIn(list(range(5)), key=len) with pytest.raises(MakefileError): spec(_DUMMY_PATH, "abcde")
def test_value_in__single_value_in_set__with_key(): spec = ValueIn(list(range(5)), key=len) spec(_DUMMY_PATH, "a")
def test_value_in__single_value_not_in_set(): spec = ValueIn(list(range(5))) with pytest.raises(MakefileError): spec(_DUMMY_PATH, 5)
def test_and__default_set__valid_value(): spec = And(IsInt, ValueIn(list(range(30))), default=20) assert spec.default == 20
def test_is_value_in__default_not_set(): spec = ValueIn(list(range(5))) assert spec.default is DEFAULT_NOT_SET
def test_and__default_set__must_meet_spec(): with pytest.raises(ValueError): And(IsInt, ValueIn((1, )), default=5)
def test_is_value_in__default_set__valid_value(): spec = ValueIn(list(range(5)), default=4) assert spec.default == 4
def test_or__default_not_set(): spec = Or(IsInt, ValueIn((10, ))) assert spec.default is DEFAULT_NOT_SET
def test_is_value_in__default_set__must_meet_spec(): with pytest.raises(ValueError): ValueIn(list(range(5)), default=5)
def test_or__default_set__must_meet_spec(): with pytest.raises(ValueError): Or(IsInt, ValueIn((10, )), default=5.5)
def test_is_value_in__handles_types(value): spec = ValueIn((1, 2, 3, 4)) with pytest.raises(MakefileError, match="Expected value: value in 1, 2, 3, or 4"): spec(_DUMMY_PATH, value)
"CollapsedTruncated": IsBoolean(default=False), "Paired": IsBoolean(default=False), "Singleton": IsBoolean(default=False), } _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": ValueIn((33, 64, "Solexa"), default=33), # Split a lane into multiple entries, one for each (pair of) file(s) "SplitLanesByFilenames": RemovedOption(), "CompressionFormat": RemovedOption(), "AdapterRemoval": { "Version": RemovedOption(), "--pcr1": IsStr, "--pcr2": IsStr, "--adapter1": IsStr, "--adapter2": IsStr, "--adapter-list": IsStr, "--maxns": IsUnsignedInt, "--minquality": IsUnsignedInt, "--trimns": Or(IsNone, IsBoolean),
def test_and__accepts_when_all_true(): spec = And(IsFloat, ValueIn((0.0, 1, 2))) spec(_DUMMY_PATH, 0.0)
# change the behavior of old makefiles. for key in _READ_TYPES: result.setdefault(key, False) return result, _VALID_EXCLUDE_DICT _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": ValueIn((33, 64, "Solexa"), default=33), # Split a lane into multiple entries, one for each (pair of) file(s) "SplitLanesByFilenames": Or(IsBoolean, IsListOf(IsStr), default=True), # Format to use when compressing FASTQ files ("gz" or "bz2") "CompressionFormat": ValueIn(("gz", "bz2"), default="bz2"), "AdapterRemoval": { "Version": ValueIn(("v1.4", "v1.5+"), default="v1.5+"), "--pcr1": IsStr, "--pcr2": IsStr, "--adapter1": IsStr, "--adapter2": IsStr, "--adapter-list": IsStr, "--maxns": IsUnsignedInt, "--minquality": IsUnsignedInt,
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), ) @pytest.mark.parametrize("spec, value", _PATH_IN_EXCEPTION_VALUES)