Пример #1
0
def test_set():
    v = Value("int")

    assert v.set(1) == v
Пример #2
0
def test_get_all_values():
    vi = Value("int", strict=False)
    assert vi.set("1").value == 1
    assert vi.set("1.1").value == None
    assert vi.set("1,1").value == None
    assert vi.set("1,a").value == None
    assert vi.set("1,").value == 1
    assert vi.set("1.").value == 1
    assert vi.set(1).value == 1
    assert vi.set(1.3).value == None
    assert vi.set(None).value is None

    vf = Value("float")
    assert vf.set("1").value == 1.0
    assert vf.set("1.1").value == 1.1
    assert vf.set("1,1").value == 1.1
    assert vf.set("1,").value == 1.0
    assert vf.set(".1").value == 0.1
    assert vf.set(",1").value == 0.1
    assert vf.set(1).value == 1.0
    assert vf.set(1.2).value == 1.2
    assert vf.set(None).value is None
Пример #3
0
def test_is_allowed():
    v = Value(type_name="int", allowed={1, 2, 3, 4})

    v.set(1)
    assert v.value == 1
Пример #4
0
def test_is_allowed_not_strict_failure():
    v = Value(type_name="int", allowed={1, 2, 3, 4}, strict=False)

    v.set(5)
    assert v.value is None
    assert v.is_valid is False
Пример #5
0
def test_value_failure_2():
    v = Value(type_name="int", strict=True)

    with pytest.raises(exc.IntError):
        v.set("5.1")
        v.value
Пример #6
0
def test_is_allowed_failure():
    v = Value(type_name="int", allowed={1, 2, 3, 4})

    with pytest.raises(exc.ForbiddenValue):
        v.set(5)
        v.value