Esempio n. 1
0
def test_quantity_int_value_high():
    q = Quantity(int, value_high=101)
    assert not q.valid("ssdf")
    assert q.valid(101)
    assert q.valid(101.0)
    assert not q.valid(110)
    assert q.valid(100.99999)
    assert q.valid(True)
Esempio n. 2
0
def test_quantity_str():
    q = Quantity(str, "hallo")
    assert not q.valid("ssdf")
    assert q.valid("hallo")
    assert not q.valid(101)
    assert not q.valid(101.0)
    assert not q.valid(True)
Esempio n. 3
0
def test_quantity_construct():
    with pytest.raises(ValueError, match="must be of type"):
        Quantity(str, 1)
    with pytest.raises(ValueError, match="must be of type"):
        Quantity(str, True)
    with pytest.raises(ValueError, match="value must be set for"):
        Quantity(str, value_low="a")
    with pytest.raises(ValueError, match="value must be set for"):
        Quantity(str, value_high="a")

    with pytest.raises(ValueError, match="must be of type"):
        Quantity(bool, 1)
    with pytest.raises(ValueError, match="must be of type"):
        Quantity(bool, "True")
    with pytest.raises(ValueError, match="value must be set for"):
        Quantity(bool, value_low="a")
    with pytest.raises(ValueError, match="value must be set for"):
        Quantity(bool, value_high="a")

    for datatype in [int, float]:
        with pytest.raises(ValueError, match="value must be a numeric type"):
            Quantity(datatype, value="str")
        with pytest.raises(ValueError,
                           match="value_low must not be set for datatype"):
            Quantity(datatype, value=1.0, value_low=1.0)
        with pytest.raises(ValueError,
                           match="value_high must not be set for datatype"):
            Quantity(datatype, value=1.0, value_high=1.0)
        with pytest.raises(
                ValueError,
                match="value_low and/or value_high must be set for datatype"):
            Quantity(datatype)
Esempio n. 4
0
def test_quantity_int_value():
    q = Quantity(int, 101)
    assert not q.valid("ssdf")
    assert q.valid(101)
    assert q.valid(101.0)
    assert not q.valid(True)
Esempio n. 5
0
def test_quantity_bool():
    q = Quantity(bool, True)
    assert not q.valid("ssdf")
    assert not q.valid(101)
    assert not q.valid(101.0)
    assert q.valid(True)