Skip to content

Commit

Permalink
Add a failing test for #85
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jun 8, 2017
1 parent 47cf89e commit dec7ed6
Showing 1 changed file with 53 additions and 9 deletions.
62 changes: 53 additions & 9 deletions src/zope/interface/tests/test_registry.py
Expand Up @@ -14,11 +14,14 @@
"""Component Registry Tests"""
import unittest

from zope.interface import Interface
from zope.interface.adapter import VerifyingAdapterRegistry

from zope.interface.registry import Components

class ComponentsTests(unittest.TestCase):

def _getTargetClass(self):
from zope.interface.registry import Components
return Components

def _makeOne(self, name='test', *args, **kw):
Expand Down Expand Up @@ -2635,6 +2638,54 @@ def __repr__(self):
("HandlerRegistration(_REGISTRY, [IFoo], %r, TEST, "
+ "'DOCSTRING')") % (_name))

class PersistentAdapterRegistry(VerifyingAdapterRegistry):

def __getstate__(self):
state = self.__dict__.copy()
for k in list(state):
if k in self._delegated or k.startswith('_v'):
state.pop(k)
state.pop('ro', None)
return state

def __setstate__(self, state):
bases = state.pop('__bases__', ())
self.__dict__.update(state)
self._createLookup()
self.__bases__ = bases
self._v_lookup.changed(self)

class PersistentComponents(Components):
# Mimic zope.component.persistentregistry.PersistentComponents:
# we should be picklalable, but not persistent.Persistent ourself.

def _init_registries(self):
self.adapters = PersistentAdapterRegistry()
self.utilities = PersistentAdapterRegistry()


class TestPersistentComponents(unittest.TestCase):

def test_pickles_empty(self):
import pickle
comp = PersistentComponents('test')
pickle.dumps(comp)
comp2 = pickle.loads(pickle.dumps(comp))

self.assertEqual(comp2.__name__, 'test')

def test_pickles_with_utility_registration(self):
import pickle
comp = PersistentComponents('test')
comp.registerUtility(
object(),
Interface)

comp2 = pickle.loads(pickle.dumps(comp))
self.assertEqual(comp2.__name__, 'test')

self.assertNotNone(comp2.getUtility(Interface))


class _Monkey(object):
# context-manager for replacing module names in the scope of a test.
Expand All @@ -2652,11 +2703,4 @@ def __exit__(self, exc_type, exc_val, exc_tb):
setattr(self.module, key, value)

def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ComponentsTests),
unittest.makeSuite(UnhashableComponentsTests),
unittest.makeSuite(UtilityRegistrationTests),
unittest.makeSuite(AdapterRegistrationTests),
unittest.makeSuite(SubscriptionRegistrationTests),
unittest.makeSuite(AdapterRegistrationTests),
))
return unittest.defaultTestLoader.loadTestsFromName(__name__)

0 comments on commit dec7ed6

Please sign in to comment.