def test_Regex(self) -> None: p = Regex("green") with pytest.raises(ValueError) as e: p.validate("junk") assert matches( str(e.value), r"expected a string matching 'green' pattern, got 'junk'")
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))
def test_valid(self) -> None: prop = bcpe.Either(Interval(Int, 0, 100), Regex("^x*$"), List(Int)) assert prop.is_valid(0) assert prop.is_valid(1) assert prop.is_valid("") assert prop.is_valid("xxx") assert prop.is_valid([]) assert prop.is_valid([1, 2, 3]) assert prop.is_valid(100) # TODO (bev) should fail assert prop.is_valid(False) assert prop.is_valid(True)
def test_invalid(self) -> None: prop = bcpe.Either(Interval(Int, 0, 100), Regex("^x*$"), List(Int)) assert not prop.is_valid(0.0) assert not prop.is_valid(1.0) assert not prop.is_valid(1.0 + 1.0j) assert not prop.is_valid(()) assert not prop.is_valid({}) assert not prop.is_valid(_TestHasProps()) assert not prop.is_valid(_TestModel()) assert not prop.is_valid(-100) assert not prop.is_valid("yyy") assert not prop.is_valid([1, 2, ""])
def test_Regex(self, detail): p = Regex("green") with pytest.raises(ValueError) as e: p.validate("junk", detail) assert str(e).endswith("ValueError") == (not detail)
def test_Regex(self): p = Regex("green") with pytest.raises(ValueError) as e: p.validate("junk") assert not str(e).endswith("ValueError")
def test_Regex(self, detail) -> None: p = Regex("green") with pytest.raises(ValueError) as e: p.validate("junk", detail) assert (str(e.value) == "") == (not detail)