def test_wrap(self) -> None: prop = bcpe.Either(List(Int), Dict(String, Int)) wrapped = prop.wrap([10, 20]) assert isinstance(wrapped, PropertyValueList) assert prop.wrap(wrapped) is wrapped wrapped = prop.wrap({"foo": 10}) assert isinstance(wrapped, PropertyValueDict) assert prop.wrap(wrapped) is wrapped
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_str(self) -> None: prop = bcpe.Either(Int, Int) assert str(prop) == "Either(Int, Int)"
def test_has_ref(self) -> None: prop = bcpe.Either(Int, Int) assert not prop.has_ref
def test_init(self) -> None: with pytest.raises(TypeError): bcpe.Either()