def __init__(self, name): super().__init__(String(), dynamo_name="d_" + name) self._name = name # Mock model so this can render as M.name # noinspection PyTypeChecker self.model = type("M", tuple(), {})
def test_set_type_instance(): """Set can take an instance of a Type as well as a Type subclass""" type_instance = String() instance_set = Set(type_instance) assert instance_set.inner_typedef is type_instance type_subclass = String subclass_set = Set(type_subclass) assert isinstance(subclass_set.inner_typedef, type_subclass)
def test_set_registered(): """set registers its typedef so loading/dumping happens properly""" type_engine = declare.TypeEngine.unique() string_type = String() string_set_type = Set(string_type) type_engine.bind() assert string_type not in type_engine.bound_types type_engine.register(string_set_type) type_engine.bind() assert string_type in type_engine.bound_types
def test_string(): typedef = String() symmetric_test(typedef, ("foo", "foo"))
class MyType(Type): backing_type = "S" python_type = str typedef = MyType() with pytest.raises(NotImplementedError): typedef._load({"S": "value"}, context={}) with pytest.raises(NotImplementedError): typedef._dump("value", context={}) @pytest.mark.parametrize("type", [ Type(), String(), Binary(), Number(), Boolean(), Set(String), Set(Binary), Set(Number), ]) def test_type_paths_raise(type): """List, Map, DynamicList, and DynamicMap are the only types that support paths""" with pytest.raises(RuntimeError): _ = type["string-key"] # noqa: F841 with pytest.raises(RuntimeError): _ = type[3] # noqa: F841