示例#1
0
def test_and__str__two_items__first_is_operator():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.LT(3, 4)
    obj = versions.And(obj_1, obj_2)

    assert_equal(str(obj),
                 "(at least v1.2.x and prior to v2.0.x) and prior to v3.4.x")
示例#2
0
def test_or__str__two_items__first_is_operator():
    obj_1 = versions.Or(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.LT(3, 4)
    obj = versions.Or(obj_1, obj_2)

    assert str(
        obj) == "(at least v1.2.x or prior to v2.0.x) or prior to v3.4.x"
示例#3
0
def test_or__check_version__insufficient_number_of_values():
    def _do_or_check_num_values(obj_1, obj_2):
        obj = versions.Or(obj_1, obj_2)
        assert_raises(ValueError, obj, (1, 3))

    yield _do_or_check_num_values, versions.GE(1, 2, 2), versions.LT(2, 0)
    yield _do_or_check_num_values, versions.GE(1, 2, 2), versions.LT(2, 0, 1)
示例#4
0
def test_or__check_version__truncated():
    def _do_or_check_truncated(obj_1, obj_2):
        obj = versions.Or(obj_1, obj_2)
        assert obj((1, 3, 3))

    yield _do_or_check_truncated, versions.GE(1, 2), versions.LT(2, 0)
    yield _do_or_check_truncated, versions.GE(1, 2, 2), versions.LT(2, 0)
    yield _do_or_check_truncated, versions.GE(1, 2), versions.LT(2, 0, 1)
示例#5
0
def test_or__str__two_items__second_is_operator():
    obj_1 = versions.GE(1, 2)
    obj_2 = versions.And(versions.GE(2, 0), versions.LT(3, 4))
    obj = versions.Or(obj_1, obj_2)

    assert str(
        obj) == "at least v1.2.x or (at least v2.0.x and prior to v3.4.x)"
示例#6
0
def test_check__can_pickle():
    def _do_test_can_pickle(obj):
        pickle.dumps(obj)

    yield _do_test_can_pickle, versions.EQ(1, 2, 3)
    yield _do_test_can_pickle, versions.GE(1, 2, 3)
    yield _do_test_can_pickle, versions.LT(1, 2, 3)
    yield _do_test_can_pickle, versions.Any()
    yield _do_test_can_pickle, versions.And(versions.EQ(1, 2, 3))
    yield _do_test_can_pickle, versions.Or(versions.GE(1, 2, 3))
示例#7
0
def test_lt__check_values__not_less_than_too_few_values():
    obj = versions.LT(2, 3)
    assert_raises(ValueError, obj, (3, ))
示例#8
0
def test_requirement__new_obj_if_checks_differ():
    obj1 = versions.Requirement("echo", "", versions.GE(1))
    obj2 = versions.Requirement("echo", "", versions.LT(1))
    assert obj1 is not obj2
示例#9
0
def test_requirement__obj_is_cached_for_same_values():
    obj1 = versions.Requirement("echo", "", versions.LT(1))
    obj2 = versions.Requirement("echo", "", versions.LT(1))
    assert obj1 is obj2
示例#10
0
def test_or__check_version__neither_true():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.And(versions.GE(2, 3), versions.LT(3, 0))
    obj = versions.Or(obj_1, obj_2)
    assert not obj((2, 2))
示例#11
0
def test_or__check_version__both_true():
    obj_1 = versions.GE(1, 2)
    obj_2 = versions.LT(2, 0)
    obj = versions.Or(obj_1, obj_2)
    assert obj((1, 3))
示例#12
0
def test_or__init__non_check_value():
    with pytest.raises(ValueError):
        versions.Or(versions.LT(2), None)
示例#13
0
def test_requirement__new_obj_if_call_differ():
    obj1 = versions.Requirement("echo", "", versions.LT(1))
    obj2 = versions.Requirement("true", "", versions.LT(1))
    assert_is_not(obj1, obj2)
示例#14
0
def test_or__init__non_check_value():
    assert_raises(ValueError, versions.Or, versions.LT(2), None)
示例#15
0
def test_and__str__two_items():
    obj_ge = versions.GE(1, 2)
    obj_lt = versions.LT(3, 4)
    obj = versions.And(obj_ge, obj_lt)

    assert_equal(str(obj), "at least v1.2.x and prior to v3.4.x")
示例#16
0
def test_lt__check_values__not_less_than_too_few_values():
    obj = versions.LT(2, 3)
    with pytest.raises(ValueError):
        obj((3, ))
示例#17
0
def test_and__check_version__first_true():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.And(versions.GE(2, 3), versions.LT(3, 0))
    obj = versions.And(obj_1, obj_2)
    assert not obj((1, 3))
示例#18
0
def test_requirement_highest_priority_retained():
    obj1 = versions.Requirement("echo", "", versions.LT(1), priority=5)
    assert_equal(obj1.priority, 5)
    obj2 = versions.Requirement("echo", "", versions.LT(1), priority=0)
    assert_is(obj1, obj2)
    assert_equal(obj2.priority, 5)
示例#19
0
def test_or__str__two_items():
    obj_ge = versions.GE(1, 2)
    obj_lt = versions.LT(3, 4)
    obj = versions.Or(obj_ge, obj_lt)

    assert str(obj) == "at least v1.2.x or prior to v3.4.x"
示例#20
0
def test_and__check_version__second_true():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.And(versions.GE(2, 3), versions.LT(3, 0))
    obj = versions.And(obj_1, obj_2)
    assert not obj((2, 3))


def test_and__check_version__neither_true():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.And(versions.GE(2, 3), versions.LT(3, 0))
    obj = versions.And(obj_1, obj_2)
    assert not obj((2, 2))


_TRUNCATED_VERSIONS = (
    (versions.GE(1, 2), versions.LT(2, 0)),
    (versions.GE(1, 2, 2), versions.LT(2, 0)),
    (versions.GE(1, 2), versions.LT(2, 0, 1)),
)


@pytest.mark.parametrize("obj_1, obj_2", _TRUNCATED_VERSIONS)
def test_and__check_version__truncated(obj_1, obj_2):
    obj = versions.And(obj_1, obj_2)
    assert obj((1, 3, 3))


_INSUFFICIENT_VALUES = (
    (versions.GE(1, 2, 2), versions.LT(2, 0)),
    (versions.GE(1, 2), versions.LT(2, 0, 1)),
    (versions.GE(1, 2, 2), versions.LT(2, 0, 1)),
示例#21
0
def test_lt__str__one_value():
    obj = versions.LT(1)
    assert str(obj) == "prior to v1.x"
示例#22
0
def test_lt__str__two_values():
    obj = versions.LT(2, 1)
    assert str(obj) == "prior to v2.1.x"
示例#23
0
def test_or__check_version__second_true():
    obj_1 = versions.And(versions.GE(1, 2), versions.LT(2, 0))
    obj_2 = versions.And(versions.GE(2, 3), versions.LT(3, 0))
    obj = versions.Or(obj_1, obj_2)
    assert obj((2, 3))
示例#24
0
def test_lt__check_values__less_than():
    obj = versions.LT(2, 3)
    assert obj((2, 2))
    assert obj((1, 9))
示例#25
0
def test_or__check_version__insufficient_number_of_values__is_lazy():
    obj_1 = versions.GE(1, 2)
    obj_2 = versions.LT(2, 0, 1)
    obj = versions.Or(obj_1, obj_2)
    assert obj((1, 3))
示例#26
0
def test_lt__check_values__not_less_than():
    obj = versions.LT(2, 3)
    assert not obj((2, 3))
    assert not obj((2, 4))
示例#27
0
def test_requirement__new_obj_if_search_differ():
    obj1 = versions.Requirement("echo", r"(\d+)", versions.LT(1))
    obj2 = versions.Requirement("echo", "", versions.LT(1))
    assert obj1 is not obj2
示例#28
0
def test_lt__check_values__less_than_truncated():
    obj = versions.LT(2, 3)
    assert obj((2, 2, 1))
    assert obj((2, 1, 2))
示例#29
0
def test_requirement_highest_priority_retained():
    obj1 = versions.Requirement("echo", "", versions.LT(1), priority=5)
    assert obj1.priority == 5
    obj2 = versions.Requirement("echo", "", versions.LT(1), priority=0)
    assert obj1 is obj2
    assert obj2.priority == 5
示例#30
0
def test_lt__str__two_values():
    obj = versions.LT(2, 1)
    assert_equal(str(obj), "prior to v2.1.x")