Exemple #1
0
def test_intersects__handles_types(value):
    spec = ValuesIntersect(list(range(5)))
    with pytest.raises(
            MakefileError,
            match="Expected value: one or more of 0, 1, 2, 3, and 4"):
        spec(_DUMMY_PATH, value)
Exemple #2
0
def test_subset_of__rejects_dictionary():
    spec = ValuesIntersect("abc")
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, {"a": 1, "b": 2})
Exemple #3
0
def test_intersects__default_set__valid_value():
    spec = ValuesIntersect(list(range(5)), default=[3, 4])
    assert spec.default == [3, 4]
Exemple #4
0
def test_intersects__default_set__must_meet_spec():
    with pytest.raises(ValueError):
        ValuesIntersect(list(range(5)), default=[5])
Exemple #5
0
def test_intersects__chars__case_sensitive__rejects_differences_in_case():
    spec = ValuesIntersect("abcdefghijkl")
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, "A BIG DEAL")
Exemple #6
0
def test_intersects__default_not_set():
    spec = ValuesIntersect(list(range(5)))
    assert spec.default is DEFAULT_NOT_SET
Exemple #7
0
def test_intersects__case_sensitive__value_in_not_set():
    spec = ValuesIntersect(("Abc", "bCe", "cdE"))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, ["Bce"])
Exemple #8
0
def test_intersects__single_value_in_set():
    spec = ValuesIntersect(list(range(5)))
    spec(_DUMMY_PATH, [1])
Exemple #9
0
def test_intersects__empty_set():
    spec = ValuesIntersect(list(range(5)))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, [])
Exemple #10
0
def test_intersects__case_sensitive__value_in_set():
    spec = ValuesIntersect(("Abc", "bCe", "cdE"))
    spec(_DUMMY_PATH, ["bCe"])
Exemple #11
0
def test_intersects__some_values_in_set():
    spec = ValuesIntersect(list(range(5)))
    spec(_DUMMY_PATH, [4, 5])
Exemple #12
0
def test_intersects__single_value_not_in_set():
    spec = ValuesIntersect(list(range(5)))
    with pytest.raises(MakefileError):
        spec(_DUMMY_PATH, [5])
Exemple #13
0
def test_intersects__multiple_values_in_set():
    spec = ValuesIntersect(list(range(5)))
    spec(_DUMMY_PATH, [1, 4])
Exemple #14
0
    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")),
}
Exemple #15
0
def test_intersects__chars__case_sensitive():
    spec = ValuesIntersect("abcdefghijkl")
    spec(_DUMMY_PATH, "a big deal")
Exemple #16
0
    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":
Exemple #17
0
        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)
def test_specs__path_is_displayed_in_exception(spec, value):