예제 #1
0
 def test_MinMaxBounds(self) -> None:
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10)
     assert matches(
         str(e.value),
         r"expected an element of either Auto, Tuple\(Float, Float\) or Tuple\(TimeDelta, TimeDelta\), got 10"
     )
예제 #2
0
def test_Property_wrap() -> None:
    types = [
        Bool(),
        Int(),
        Float(),
        Complex(),
        String(),
        Enum("Some", "a", "b"),
        Color(),
        Regex("^$"),
        Seq(Any),
        Tuple(Any, Any),
        Instance(_TestModel),
        Any(),
        Interval(Float, 0, 1),
        Either(Int, String),
        DashPattern(),
        Size(),
        Percent(),
        Angle(),
        MinMaxBounds(),
    ]

    for x in types:
        for y in (0, 1, 2.3, "foo", None, (), [], {}):
            r = x.wrap(y)
            assert r == y
            assert isinstance(r, type(y))
예제 #3
0
 def test_MinMaxBounds(self, detail):
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10, detail)
     assert str(e).endswith("ValueError") == (not detail)
예제 #4
0
 def test_MinMaxBounds(self):
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10)
     assert not str(e).endswith("ValueError")
예제 #5
0
 def test_MinMaxBounds(self, detail) -> None:
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10, detail)
     assert (str(e.value) == "") == (not detail)
예제 #6
0
 def test_MinMaxBounds(self) -> None:
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10)
     assert matches(str(e.value), r"expected an element of either .*, got 10")
예제 #7
0
 def test_MinMaxBounds(self, detail):
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10, detail)
     assert str(e).endswith("ValueError") == (not detail)
예제 #8
0
 def test_MinMaxBounds(self):
     p = MinMaxBounds()
     with pytest.raises(ValueError) as e:
         p.validate(10)
     assert not str(e).endswith("ValueError")