예제 #1
0
    def test_init(self) -> None:
        with pytest.raises(TypeError):
            bcpn.Nullable()
        with pytest.raises(ValueError):
            bcpn.Nullable(Int(help="inner help"))

        prop0 = bcpn.Nullable(Int(), help="help")
        assert prop0._help == prop0.__doc__ == "help"
예제 #2
0
    def test_valid(self) -> None:
        prop = bcpn.Nullable(List(Int))

        assert prop.is_valid(None)

        assert prop.is_valid([])
        assert prop.is_valid([1, 2, 3])
예제 #3
0
    def test_invalid(self) -> None:
        prop = bcpn.Nullable(List(Int))

        assert not prop.is_valid(-100)
        assert not prop.is_valid("yyy")
        assert not prop.is_valid([1, 2, ""])

        assert not prop.is_valid(())
        assert not prop.is_valid({})
        assert not prop.is_valid(_TestHasProps())
        assert not prop.is_valid(_TestModel())
예제 #4
0
 def test_str(self) -> None:
     prop = bcpn.Nullable(List(Int))
     assert str(prop) == "Nullable(List(Int))"
예제 #5
0
 def test_has_ref(self) -> None:
     prop0 = bcpn.Nullable(Int)
     assert not prop0.has_ref
     prop1 = bcpn.Nullable(Instance(_TestModel))
     assert prop1.has_ref
예제 #6
0
 def test_init(self) -> None:
     with pytest.raises(TypeError):
         bcpn.Nullable()
예제 #7
0
 def test_wrap_list(self) -> None:
     prop = bcpn.Nullable(List(Int))
     assert prop.wrap(None) is None
     wrapped = prop.wrap([10, 20])
     assert isinstance(wrapped, PropertyValueList)
     assert prop.wrap(wrapped) is wrapped
예제 #8
0
 def test_wrap_dict(self) -> None:
     prop = bcpn.Nullable(Dict(String, Int))
     assert prop.wrap(None) is None
     wrapped = prop.wrap({"foo": 10})
     assert isinstance(wrapped, PropertyValueDict)
     assert prop.wrap(wrapped) is wrapped