Beispiel #1
0
def test_and__default_not_set():
    spec = And(IsInt, ValueIn(list(range(10))))
    assert spec.default is DEFAULT_NOT_SET
Beispiel #2
0
def test_value_in__single_value_in_set():
    spec = ValueIn(list(range(5)))
    spec(_DUMMY_PATH, 1)
Beispiel #3
0
def test_and__rejects_when_both_is_false():
    spec = And(IsFloat, ValueIn((0.0, 1, 2)))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, 3)
Beispiel #4
0
def test_or__defaults_not_set_in_specs():
    with pytest.raises(ValueError):
        Or(IsInt(default=10), ValueIn((10, )))
Beispiel #5
0
     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"),
         }
     }
 },
Beispiel #6
0
def test_and__defaults_not_set_in_specs():
    with pytest.raises(ValueError):
        And(IsInt(default=10), ValueIn((list(range(100)))))
Beispiel #7
0
def test_or__default_set__valid_value():
    spec = Or(IsInt, ValueIn((10, )), default=17)
    assert spec.default == 17
Beispiel #8
0
def test_value_in__default_description():
    spec = ValueIn(("Abc", "bCe", "cdE"))
    assert spec.description == "value in 'Abc', 'bCe', or 'cdE'"
Beispiel #9
0
def test_value_in__custom_description():
    spec = ValueIn(("Abc", "bCe", "cdE"), description="One of {rvalue}")
    assert spec.description == "One of 'Abc', 'bCe', or 'cdE'"
Beispiel #10
0
def test_value_in__case_sensitive__value_in_set():
    spec = ValueIn(("Abc", "bCe", "cdE"))
    spec(_DUMMY_PATH, "bCe")
Beispiel #11
0
def test_value_in__case_sensitive__value_in_not_set():
    spec = ValueIn(("Abc", "bCe", "cdE"))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, "Bce")
Beispiel #12
0
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")
Beispiel #13
0
def test_value_in__single_value_in_set__with_key():
    spec = ValueIn(list(range(5)), key=len)
    spec(_DUMMY_PATH, "a")
Beispiel #14
0
def test_value_in__single_value_not_in_set():
    spec = ValueIn(list(range(5)))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, 5)
Beispiel #15
0
def test_and__default_set__valid_value():
    spec = And(IsInt, ValueIn(list(range(30))), default=20)
    assert spec.default == 20
Beispiel #16
0
def test_is_value_in__default_not_set():
    spec = ValueIn(list(range(5)))
    assert spec.default is DEFAULT_NOT_SET
Beispiel #17
0
def test_and__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        And(IsInt, ValueIn((1, )), default=5)
Beispiel #18
0
def test_is_value_in__default_set__valid_value():
    spec = ValueIn(list(range(5)), default=4)
    assert spec.default == 4
Beispiel #19
0
def test_or__default_not_set():
    spec = Or(IsInt, ValueIn((10, )))
    assert spec.default is DEFAULT_NOT_SET
Beispiel #20
0
def test_is_value_in__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        ValueIn(list(range(5)), default=5)
Beispiel #21
0
def test_or__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        Or(IsInt, ValueIn((10, )), default=5.5)
Beispiel #22
0
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)
Beispiel #23
0
    "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),
Beispiel #24
0
def test_and__accepts_when_all_true():
    spec = And(IsFloat, ValueIn((0.0, 1, 2)))
    spec(_DUMMY_PATH, 0.0)
Beispiel #25
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,
Beispiel #26
0
    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)