Skip to content

Commit

Permalink
isolating marshmallow-code#732 via tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asmodehn committed Apr 20, 2018
1 parent 0e61623 commit 282f5d3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 282f5d3

Please sign in to comment.