Ejemplo n.º 1
0
 def test_Complex(self) -> None:
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk")
     assert matches(
         str(e.value),
         r"expected a value of type Complex, got junk of type str")
Ejemplo n.º 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))
Ejemplo n.º 3
0
 def test_Complex(self, detail):
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk", detail)
     assert str(e).endswith("ValueError") == (not detail)
Ejemplo n.º 4
0
 def test_Complex(self):
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk")
     assert not str(e).endswith("ValueError")
Ejemplo n.º 5
0
 def test_Complex(self, detail) -> None:
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk", detail)
     assert (str(e.value) == "") == (not detail)
Ejemplo n.º 6
0
 def test_Complex(self, detail):
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk", detail)
     assert str(e).endswith("ValueError") == (not detail)
Ejemplo n.º 7
0
 def test_Complex(self):
     p = Complex()
     with pytest.raises(ValueError) as e:
         p.validate("junk")
     assert not str(e).endswith("ValueError")