diff --git a/tests/test_registry.py b/tests/test_registry.py index b9d39e7ce..3f4f143e6 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -13,8 +13,59 @@ class MySchema(Schema): class MySubSchema(Schema): pass + # by classname assert 'MySchema' in class_registry._registry assert 'MySubSchema' in class_registry._registry + # by fullpath + assert 'tests.test_registry.MySchema' in class_registry._registry + assert 'tests.test_registry.MySubSchema' in class_registry._registry + + +def test_serializer_class_registry_register_same_classname_different_module(): + + reglen = len(class_registry._registry) + + cls1 = type('MyTestRegSchema', (Schema,), {'__module__': 'modA'}) + + assert 'MyTestRegSchema' in class_registry._registry + assert len(class_registry._registry.get('MyTestRegSchema')) == 1 + assert 'modA.MyTestRegSchema' in class_registry._registry + #  storing for classname and fullpath + assert len(class_registry._registry) == reglen + 2 + + cls2 = type('MyTestRegSchema', (Schema,), {'__module__': 'modB'}) + + assert 'MyTestRegSchema' in class_registry._registry + #  aggregating classes with same name from different modules + assert len(class_registry._registry.get('MyTestRegSchema')) == 2 + assert 'modB.MyTestRegSchema' in class_registry._registry + #  storing for same classname (+0) and different module (+1) + assert len(class_registry._registry) == reglen + 2 + 1 + + +def test_serializer_class_registry_override_if_same_classname_same_module(): + + reglen = len(class_registry._registry) + + cls1 = type('MyTestReg2Schema', (Schema,), {'__module__': 'SameModulePath'}) + + assert 'MyTestReg2Schema' in class_registry._registry + assert len(class_registry._registry.get('MyTestReg2Schema')) == 1 + assert 'SameModulePath.MyTestReg2Schema' in class_registry._registry + assert len(class_registry._registry.get('SameModulePath.MyTestReg2Schema')) == 1 + #  storing for classname and fullpath + assert len(class_registry._registry) == reglen + 2 + + cls2 = type('MyTestReg2Schema', (Schema,), {'__module__': 'SameModulePath'}) + + assert 'MyTestReg2Schema' in class_registry._registry + #  overriding same class name and same module + assert len(class_registry._registry.get('MyTestReg2Schema')) == 1 + assert 'SameModulePath.MyTestReg2Schema' in class_registry._registry + # overriding same fullpath + assert len(class_registry._registry.get('SameModulePath.MyTestReg2Schema')) == 1 + #  overriding for same classname (+0) and different module (+0) + assert len(class_registry._registry) == reglen + 2 class A: