示例#1
0
    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
示例#2
0
    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)
示例#3
0
    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, ""])
示例#4
0
 def test_str(self) -> None:
     prop = bcpe.Either(Int, Int)
     assert str(prop) == "Either(Int, Int)"
示例#5
0
 def test_has_ref(self) -> None:
     prop = bcpe.Either(Int, Int)
     assert not prop.has_ref
示例#6
0
 def test_init(self) -> None:
     with pytest.raises(TypeError):
         bcpe.Either()