Exemple #1
0
def test_specs__path_is_displayed_in_exception():
    def _path_is_displayed_in_exception(spec, value):
        assert_raises_regexp(MakefileError, _DUMMY_PATH_STR, spec, _DUMMY_PATH,
                             value)

    yield _path_is_displayed_in_exception, IsInt(), "foo"
    yield _path_is_displayed_in_exception, IsUnsignedInt(), -1
    yield _path_is_displayed_in_exception, IsFloat(), "abc"
    yield _path_is_displayed_in_exception, IsBoolean(), 1
    yield _path_is_displayed_in_exception, IsStr(), 1
    yield _path_is_displayed_in_exception, IsNone(), 1
    yield _path_is_displayed_in_exception, ValueLT(0), 1
    yield _path_is_displayed_in_exception, ValueLE(0), 1
    yield _path_is_displayed_in_exception, ValueGE(0), -1
    yield _path_is_displayed_in_exception, ValueGT(0), -1
    yield _path_is_displayed_in_exception, ValueIn([1]), 2
    yield _path_is_displayed_in_exception, ValuesIntersect([1]), [2]
    yield _path_is_displayed_in_exception, ValuesSubsetOf([1]), [2]
    yield _path_is_displayed_in_exception, ValueMissing(), True
    yield _path_is_displayed_in_exception, And(IsStr), 1
    yield _path_is_displayed_in_exception, Or(IsStr), 1
    yield _path_is_displayed_in_exception, Xor(IsStr, IsInt), True
    yield _path_is_displayed_in_exception, Not(IsInt), 1
    yield _path_is_displayed_in_exception, StringIn("abc"), 1
    yield _path_is_displayed_in_exception, StringsIntersect("abc"), [1]
    yield _path_is_displayed_in_exception, StringsSubsetOf("abc"), [1]
    yield _path_is_displayed_in_exception, StringIsUppercase(), 1
    yield _path_is_displayed_in_exception, StringStartsWith("FOO"), 1
    yield _path_is_displayed_in_exception, StringEndsWith("FOO"), 1
    yield _path_is_displayed_in_exception, IsListOf(IsInt), "foo"
    yield _path_is_displayed_in_exception, IsDictOf(IsInt, IsInt), 1
Exemple #2
0
def test_xor__rejects_when_both_is_false():
    spec = Xor(IsFloat, ValueLT(1.0))
    assert_raises(MakefileError, spec, _DUMMY_PATH, 2)
Exemple #3
0
def test_xor__accepts_when_second_is_false():
    spec = Xor(IsFloat, ValueLT(1.0))
    spec(_DUMMY_PATH, 2.0)
Exemple #4
0
def test_xor__accepts_when_first_is_false():
    spec = Xor(IsFloat, ValueLT(1))
    spec(_DUMMY_PATH, 0)
Exemple #5
0
def test_xor__rejects_when_all_true():
    spec = Xor(IsFloat, ValueLT(1))
    assert_raises(MakefileError, spec, _DUMMY_PATH, 0.0)
Exemple #6
0
def test_and__rejects_when_both_is_false():
    spec = And(IsFloat, ValueLT(1.5))
    assert_raises(MakefileError, spec, _DUMMY_PATH, 2)
Exemple #7
0
def test_and__accepts_when_all_true():
    spec = And(IsFloat, ValueLT(1.5))
    spec(_DUMMY_PATH, 0.0)
Exemple #8
0
def test_is_value_lt__default_set__valid_value():
    spec = ValueLT(10, default=9)
    assert_equal(spec.default, 9)
Exemple #9
0
def test_is_value_lt__default_not_set():
    spec = ValueLT(10)
    assert_is(spec.default, DEFAULT_NOT_SET)
Exemple #10
0
def test_value_lt__custom_description():
    spec = ValueLT('Bar', description='anything less than {rvalue}')
    assert_equal(spec.description, "anything less than 'Bar'")
Exemple #11
0
def test_value_lt__default_description():
    spec = ValueLT('Foo')
    assert_equal(spec.description, "value < 'Foo'")
Exemple #12
0
def test_value_lt__rejects_value_gt__with_key():
    spec = ValueLT(7, key=len)
    assert_raises(MakefileError, spec, _DUMMY_PATH, "abcdefgh")
Exemple #13
0
def test_value_lt__accepts_value_lt__with_key():
    spec = ValueLT(7, key=len)
    spec(_DUMMY_PATH, "abcdef")
Exemple #14
0
def test_value_lt__rejects_value_gt():
    spec = ValueLT(7)
    assert_raises(MakefileError, spec, _DUMMY_PATH, 8)
Exemple #15
0
def test_value_lt__accepts_value_lt():
    spec = ValueLT(7)
    spec(_DUMMY_PATH, 6)