Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Add a test and a fix for a problem creating the persistent versions of
Browse files Browse the repository at this point in the history
declarations pointed out by Jim.

Fix up a docstring format per feedback from Jim.
  • Loading branch information
rpatterson committed Jan 27, 2007
1 parent 982f21f commit 701b3a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, *args, **kw):
ProvidesClass.__init__(self, *args, **kw)
self.dependents = DependentsDict()
def persistentProvides(obj):
return PersistentProvidesClass(*obj.__reduce__()[1:])
return PersistentProvidesClass(*obj.__reduce__()[1])
persistentFactories[Provides] = persistentProvides

from zope.interface.declarations import Implements
Expand Down
32 changes: 30 additions & 2 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ def test_provides(self):
self.assertTrue(barmodule.IBar.providedBy(bar))

def test_weakref(self):
"""Weak references to persistent objects don't remain after
ZODB pack and garbage collection."""
"""Verify interacton of declaration weak refs with ZODB
Weak references to persistent objects don't remain after ZODB
pack and garbage collection."""

bar = self.root['bar'] = Bar()
baz = self.root['baz'] = Baz()
Expand Down Expand Up @@ -142,6 +144,32 @@ def test_weakref(self):
barmodule = root['registry'].findModule("barmodule")

self.assertEqual(barmodule.IBar.dependents.keys(), [])

def test_persistentDeclarations(self):
"""Verify equivalency of persistent declarations
Make sure that the persistent declaration instance are
equivalent to the non-persistent instances they originate
from."""

self.registry.newModule("barmodule", bar_code)
barmodule = self.registry.findModule("barmodule")

class Baz(object):
implements(barmodule.IBar)

bar = Bar()
directlyProvides(bar, barmodule.IBar)

self.assertEqual(
bar.__provides__._Provides__args,
barmodule.IBar.dependents.keys()[0]._Provides__args
)

self.assertEqual(
Baz.__implemented__.__bases__,
barmodule.IBar.dependents.keys()[1].__bases__
)

def test_suite():
return unittest.makeSuite(PersistentInterfaceTest)

0 comments on commit 701b3a0

Please sign in to comment.