Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isolating #732 via tests #780

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,68 @@ 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

cls2 = type('MyTestRegSchema', (Schema,), {'__module__': 'modB'})

assert 'MyTestRegSchema' in class_registry._registry
#  only the class with matching module has been replaced
assert len(class_registry._registry.get('MyTestRegSchema')) == 2
assert 'modB.MyTestRegSchema' in class_registry._registry
#  only the class with matching module has been replaced (+0)
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:
Expand Down