[Checkins] SVN: zope.component/tseaver-test_cleanup/ Move persistentregistry doctest examples to Sphinx docs.

Tres Seaver cvs-admin at zope.org
Wed Jun 27 02:25:24 UTC 2012


Log message for revision 127125:
  Move persistentregistry doctest examples to Sphinx docs.

Changed:
  _U  zope.component/tseaver-test_cleanup/
  U   zope.component/tseaver-test_cleanup/docs/api/adapter.rst
  A   zope.component/tseaver-test_cleanup/docs/api/persistent.rst
  U   zope.component/tseaver-test_cleanup/docs/api.rst
  U   zope.component/tseaver-test_cleanup/src/zope/component/tests/examples.py
  D   zope.component/tseaver-test_cleanup/src/zope/component/tests/test_persistentregistry.py

-=-
Modified: zope.component/tseaver-test_cleanup/docs/api/adapter.rst
===================================================================
--- zope.component/tseaver-test_cleanup/docs/api/adapter.rst	2012-06-27 02:25:10 UTC (rev 127124)
+++ zope.component/tseaver-test_cleanup/docs/api/adapter.rst	2012-06-27 02:25:20 UTC (rev 127125)
@@ -1,14 +1,14 @@
 Adapter Registration APIs
 =========================
 
-Conforming Adapter Lookup
--------------------------
-
 .. testsetup::
 
    from zope.component.testing import setUp
    setUp()
 
+Conforming Adapter Lookup
+-------------------------
+
 .. autofunction:: zope.component.getAdapterInContext
 
 .. autofunction:: zope.component.queryAdapterInContext

Added: zope.component/tseaver-test_cleanup/docs/api/persistent.rst
===================================================================
--- zope.component/tseaver-test_cleanup/docs/api/persistent.rst	                        (rev 0)
+++ zope.component/tseaver-test_cleanup/docs/api/persistent.rst	2012-06-27 02:25:20 UTC (rev 127125)
@@ -0,0 +1,236 @@
+Persistent Registries
+=====================
+
+.. testsetup::
+
+   from zope.component.testing import setUp
+   setUp()
+
+Conforming Adapter Lookup
+-------------------------
+Here, we'll demonstrate that changes work even when data are stored in
+a database and when accessed from multiple connections.
+
+Start by setting up a database and creating two transaction
+managers and database connections to work with.
+
+.. doctest::
+
+    >>> import ZODB.tests.util
+    >>> db = ZODB.tests.util.DB()
+    >>> import transaction
+    >>> t1 = transaction.TransactionManager()
+    >>> c1 = db.open(transaction_manager=t1)
+    >>> r1 = c1.root()
+    >>> t2 = transaction.TransactionManager()
+    >>> c2 = db.open(transaction_manager=t2)
+    >>> r2 = c2.root()
+
+Create a set of components registries in the database, alternating
+connections.
+
+.. doctest::
+
+    >>> from zope.component.persistentregistry import PersistentComponents
+    >>> from zope.component.tests.examples import I1
+    >>> from zope.component.tests.examples import I2
+    >>> from zope.component.tests.examples import U
+    >>> from zope.component.tests.examples import U1
+    >>> from zope.component.tests.examples import U12
+    >>> from zope.component.tests.examples import handle1
+    >>> from zope.component.tests.examples import handle2
+    >>> from zope.component.tests.examples import handle3
+    >>> from zope.component.tests.examples import handle4
+
+    >>> _ = t1.begin()
+    >>> r1[1] = PersistentComponents('1')
+    >>> t1.commit()
+
+    >>> _ = t2.begin()
+    >>> r2[2] = PersistentComponents('2', (r2[1], ))
+    >>> t2.commit()
+
+    >>> _ = t1.begin()
+    >>> r1[3] = PersistentComponents('3', (r1[1], ))
+    >>> t1.commit()
+
+    >>> _ = t2.begin()
+    >>> r2[4] = PersistentComponents('4', (r2[2], r2[3]))
+    >>> t2.commit()
+
+    >>> _ = t1.begin()
+    >>> r1[1].__bases__
+    ()
+    >>> r1[2].__bases__ == (r1[1], )
+    True
+
+    >>> r1[1].registerUtility(U1(1))
+    >>> r1[1].queryUtility(I1)
+    U1(1)
+    >>> r1[2].queryUtility(I1)
+    U1(1)
+    >>> t1.commit()
+
+    >>> _ = t2.begin()
+    >>> r2[1].registerUtility(U1(2))
+    >>> r2[2].queryUtility(I1)
+    U1(2)
+
+    >>> r2[4].queryUtility(I1)
+    U1(2)
+    >>> t2.commit()
+
+
+    >>> _ = t1.begin()
+    >>> r1[1].registerUtility(U12(1), I2)
+    >>> r1[4].queryUtility(I2)
+    U12(1)
+    >>> t1.commit()
+
+
+    >>> _ = t2.begin()
+    >>> r2[3].registerUtility(U12(3), I2)
+    >>> r2[4].queryUtility(I2)
+    U12(3)
+    >>> t2.commit()
+
+    >>> _ = t1.begin()
+
+    >>> r1[1].registerHandler(handle1, info="First handler")
+    >>> r1[2].registerHandler(handle2, required=[U])
+
+    >>> r1[3].registerHandler(handle3)
+
+    >>> r1[4].registerHandler(handle4)
+
+    >>> r1[4].handle(U1(1))
+    handle1 U1(1)
+    handle3 U1(1)
+    handle2 (U1(1),)
+    handle4 U1(1)
+
+    >>> t1.commit()
+
+    >>> _ = t2.begin()
+    >>> r2[4].handle(U1(1))
+    handle1 U1(1)
+    handle3 U1(1)
+    handle2 (U1(1),)
+    handle4 U1(1)
+    >>> t2.abort()
+
+    >>> db.close()
+
+Subscription to Events in Persistent Registries
+-----------------------------------------------
+
+.. doctest::
+
+    >>> import ZODB.tests.util
+    >>> db = ZODB.tests.util.DB()
+    >>> import transaction
+    >>> t1 = transaction.TransactionManager()
+    >>> c1 = db.open(transaction_manager=t1)
+    >>> r1 = c1.root()
+    >>> t2 = transaction.TransactionManager()
+    >>> c2 = db.open(transaction_manager=t2)
+    >>> r2 = c2.root()
+
+    >>> from zope.component.persistentregistry import PersistentComponents
+
+    >>> _ = t1.begin()
+    >>> r1[1] = PersistentComponents('1')
+    >>> r1[1].registerHandler(handle1)
+    >>> r1[1].registerSubscriptionAdapter(handle1, provided=I2)
+    >>> _ = r1[1].unregisterHandler(handle1)
+    >>> _ = r1[1].unregisterSubscriptionAdapter(handle1, provided=I2)
+    >>> t1.commit()
+    >>> _ = t1.begin()
+    >>> r1[1].registerHandler(handle1)
+    >>> r1[1].registerSubscriptionAdapter(handle1, provided=I2)
+    >>> t1.commit()
+
+    >>> _ = t2.begin()
+    >>> len(list(r2[1].registeredHandlers()))
+    1
+    >>> len(list(r2[1].registeredSubscriptionAdapters()))
+    1
+    >>> t2.abort()
+
+Adapter Registrations after Serialization / Deserialization
+-----------------------------------------------------------
+
+We want to make sure that we see updates corrextly.
+
+.. doctest::
+
+    >>> import persistent
+    >>> import transaction
+    >>> from zope.interface import Interface
+    >>> from zope.interface import implements
+    >>> class IFoo(Interface):
+    ...     pass
+    >>> class Foo(persistent.Persistent):
+    ...     implements(IFoo)
+    ...     name = ''
+    ...     def __init__(self, name=''):
+    ...         self.name = name
+    ...     def __repr__(self):
+    ...         return 'Foo(%r)' % self.name
+
+    >>> from zope.component.tests.examples import base
+    >>> from zope.component.tests.examples import clear_base
+    >>> len(base._v_subregistries)
+    0
+
+    >>> import ZODB.tests.util
+    >>> db = ZODB.tests.util.DB()
+    >>> tm1 = transaction.TransactionManager()
+    >>> c1 = db.open(transaction_manager=tm1)
+    >>> from zope.component.persistentregistry import PersistentAdapterRegistry
+    >>> r1 = PersistentAdapterRegistry((base,))
+    >>> r2 = PersistentAdapterRegistry((r1,))
+    >>> c1.root()[1] = r1
+    >>> c1.root()[2] = r2
+    >>> tm1.commit()
+    >>> r1._p_deactivate()
+
+    >>> len(base._v_subregistries)
+    0
+
+    >>> tm2 = transaction.TransactionManager()
+    >>> c2 = db.open(transaction_manager=tm2)
+    >>> r1 = c2.root()[1]
+    >>> r2 = c2.root()[2]
+
+    >>> r1.lookup((), IFoo, '')
+
+    >>> base.register((), IFoo, '', Foo(''))
+    >>> r1.lookup((), IFoo, '')
+    Foo('')
+
+    >>> r2.lookup((), IFoo, '1')
+
+    >>> r1.register((), IFoo, '1', Foo('1'))
+
+    >>> r2.lookup((), IFoo, '1')
+    Foo('1')
+
+    >>> r1.lookup((), IFoo, '2')
+    >>> r2.lookup((), IFoo, '2')
+
+    >>> base.register((), IFoo, '2', Foo('2'))
+
+    >>> r1.lookup((), IFoo, '2')
+    Foo('2')
+
+    >>> r2.lookup((), IFoo, '2')
+    Foo('2')
+
+    >>> db.close()
+    >>> clear_base()
+
+.. testcleanup::
+
+   from zope.component.testing import tearDown
+   tearDown()

Modified: zope.component/tseaver-test_cleanup/docs/api.rst
===================================================================
--- zope.component/tseaver-test_cleanup/docs/api.rst	2012-06-27 02:25:10 UTC (rev 127124)
+++ zope.component/tseaver-test_cleanup/docs/api.rst	2012-06-27 02:25:20 UTC (rev 127125)
@@ -12,3 +12,4 @@
    api/factory
    api/interface
    api/security
+   api/persistent

Modified: zope.component/tseaver-test_cleanup/src/zope/component/tests/examples.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/tests/examples.py	2012-06-27 02:25:10 UTC (rev 127124)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/examples.py	2012-06-27 02:25:20 UTC (rev 127125)
@@ -17,6 +17,7 @@
 from zope.interface import implementer
 from zope.interface.interfaces import IInterface
 
+from zope.component._declaration import adapter
 from zope.component.testfiles.views import IC
 
 class ITestType(IInterface):
@@ -50,7 +51,48 @@
 def noop(*args):
     pass
 
+class U(object):
+
+    def __init__(self, name):
+        self.__name__ = name
+
+    def __repr__(self):
+        return "%s(%s)" % (self.__class__.__name__, self.__name__)
+
 @implementer(I1)
+class U1(U):
+    pass
+
+ at implementer(I1, I2)
+class U12(U):
+    pass
+
+ at adapter(I1)
+def handle1(x):
+    print 'handle1', x
+
+def handle2(*objects):
+    print 'handle2', objects
+
+ at adapter(I1)
+def handle3(x):
+    print 'handle3', x
+
+ at adapter(I1)
+def handle4(x):
+    print 'handle4', x
+
+class GlobalRegistry:
+    pass
+
+from zope.component.globalregistry import GlobalAdapterRegistry
+base = GlobalAdapterRegistry(GlobalRegistry, 'adapters')
+GlobalRegistry.adapters = base
+def clear_base():
+    base.__init__(GlobalRegistry, 'adapters')
+
+
+ at implementer(I1)
 class Ob(object):
     def __repr__(self):
         return '<instance Ob>'

Deleted: zope.component/tseaver-test_cleanup/src/zope/component/tests/test_persistentregistry.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/tests/test_persistentregistry.py	2012-06-27 02:25:10 UTC (rev 127124)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/test_persistentregistry.py	2012-06-27 02:25:20 UTC (rev 127125)
@@ -1,294 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001 - 2012 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Persistent component registry tests
-"""
-import unittest
-
-from zope.interface import Interface
-from zope.interface import implements
-from zope.component import adapter
-from zope.component.testing import setUp
-from zope.component.testing import tearDown
-
-
-class I1(Interface):
-    pass
-
-class I2(Interface):
-    pass
-
-class U(object):
-
-    def __init__(self, name):
-        self.__name__ = name
-
-    def __repr__(self):
-        return "%s(%s)" % (self.__class__.__name__, self.__name__)
-
-class U1(U):
-    implements(I1)
-
-class U12(U):
-    implements(I1, I2)
-
- at adapter(I1)
-def handle1(x):
-    print 'handle1', x
-
-def handle(*objects):
-    print 'handle', objects
-
- at adapter(I1)
-def handle3(x):
-    print 'handle3', x
-
- at adapter(I1)
-def handle4(x):
-    print 'handle4', x
-
-def test_persistent_component_managers():
-    """
-Here, we'll demonstrate that changes work even when data are stored in
-a database and when accessed from multiple connections.
-
-Start by setting up a database and creating two transaction
-managers and database connections to work with.
-
-    >>> from zope.component.testing import setUp, tearDown
-    >>> setUp()
-    >>> import ZODB.tests.util
-    >>> db = ZODB.tests.util.DB()
-    >>> import transaction
-    >>> t1 = transaction.TransactionManager()
-    >>> c1 = db.open(transaction_manager=t1)
-    >>> r1 = c1.root()
-    >>> t2 = transaction.TransactionManager()
-    >>> c2 = db.open(transaction_manager=t2)
-    >>> r2 = c2.root()
-
-Create a set of components registries in the database, alternating
-connections.
-
-    >>> from zope.component.persistentregistry import PersistentComponents
-
-    >>> _ = t1.begin()
-    >>> r1[1] = PersistentComponents('1')
-    >>> t1.commit()
-
-    >>> _ = t2.begin()
-    >>> r2[2] = PersistentComponents('2', (r2[1], ))
-    >>> t2.commit()
-
-    >>> _ = t1.begin()
-    >>> r1[3] = PersistentComponents('3', (r1[1], ))
-    >>> t1.commit()
-
-    >>> _ = t2.begin()
-    >>> r2[4] = PersistentComponents('4', (r2[2], r2[3]))
-    >>> t2.commit()
-
-    >>> _ = t1.begin()
-    >>> r1[1].__bases__
-    ()
-    >>> r1[2].__bases__ == (r1[1], )
-    True
-
-    >>> r1[1].registerUtility(U1(1))
-    >>> r1[1].queryUtility(I1)
-    U1(1)
-    >>> r1[2].queryUtility(I1)
-    U1(1)
-    >>> t1.commit()
-
-    >>> _ = t2.begin()
-    >>> r2[1].registerUtility(U1(2))
-    >>> r2[2].queryUtility(I1)
-    U1(2)
-
-    >>> r2[4].queryUtility(I1)
-    U1(2)
-    >>> t2.commit()
-
-
-    >>> _ = t1.begin()
-    >>> r1[1].registerUtility(U12(1), I2)
-    >>> r1[4].queryUtility(I2)
-    U12(1)
-    >>> t1.commit()
-
-
-    >>> _ = t2.begin()
-    >>> r2[3].registerUtility(U12(3), I2)
-    >>> r2[4].queryUtility(I2)
-    U12(3)
-    >>> t2.commit()
-
-    >>> _ = t1.begin()
-
-    >>> r1[1].registerHandler(handle1, info="First handler")
-    >>> r1[2].registerHandler(handle, required=[U])
-
-    >>> r1[3].registerHandler(handle3)
-
-    >>> r1[4].registerHandler(handle4)
-
-    >>> r1[4].handle(U1(1))
-    handle1 U1(1)
-    handle3 U1(1)
-    handle (U1(1),)
-    handle4 U1(1)
-
-    >>> t1.commit()
-
-    >>> _ = t2.begin()
-    >>> r2[4].handle(U1(1))
-    handle1 U1(1)
-    handle3 U1(1)
-    handle (U1(1),)
-    handle4 U1(1)
-    >>> t2.abort()
-
-    >>> db.close()
-    >>> tearDown()
-    """
-
-def persistent_registry_doesnt_scew_up_subsribers():
-    """
-    >>> from zope.component.testing import setUp, tearDown
-    >>> setUp()
-    >>> import ZODB.tests.util
-    >>> db = ZODB.tests.util.DB()
-    >>> import transaction
-    >>> t1 = transaction.TransactionManager()
-    >>> c1 = db.open(transaction_manager=t1)
-    >>> r1 = c1.root()
-    >>> t2 = transaction.TransactionManager()
-    >>> c2 = db.open(transaction_manager=t2)
-    >>> r2 = c2.root()
-
-    >>> from zope.component.persistentregistry import PersistentComponents
-
-    >>> _ = t1.begin()
-    >>> r1[1] = PersistentComponents('1')
-    >>> r1[1].registerHandler(handle1)
-    >>> r1[1].registerSubscriptionAdapter(handle1, provided=I2)
-    >>> _ = r1[1].unregisterHandler(handle1)
-    >>> _ = r1[1].unregisterSubscriptionAdapter(handle1, provided=I2)
-    >>> t1.commit()
-    >>> _ = t1.begin()
-    >>> r1[1].registerHandler(handle1)
-    >>> r1[1].registerSubscriptionAdapter(handle1, provided=I2)
-    >>> t1.commit()
-
-    >>> _ = t2.begin()
-    >>> len(list(r2[1].registeredHandlers()))
-    1
-    >>> len(list(r2[1].registeredSubscriptionAdapters()))
-    1
-    >>> t2.abort()
-    >>> tearDown()
-    """
-
-
-
-class GlobalRegistry:
-    pass
-
-from zope.component.globalregistry import GlobalAdapterRegistry
-base = GlobalAdapterRegistry(GlobalRegistry, 'adapters')
-GlobalRegistry.adapters = base
-def clear_base():
-    base.__init__(GlobalRegistry, 'adapters')
-
-def test_deghostification_of_persistent_adapter_registries():
-    """
-
-We want to make sure that we see updates corrextly.
-
-    >>> import persistent
-    >>> import transaction
-    >>> from zope.interface import Interface
-    >>> from zope.interface import implements
-    >>> class IFoo(Interface):
-    ...     pass
-    >>> class Foo(persistent.Persistent):
-    ...     implements(IFoo)
-    ...     name = ''
-    ...     def __init__(self, name=''):
-    ...         self.name = name
-    ...     def __repr__(self):
-    ...         return 'Foo(%r)' % self.name
-
-    >>> from zope.component.testing import setUp, tearDown
-    >>> setUp()
-    >>> len(base._v_subregistries)
-    0
-
-    >>> import ZODB.tests.util
-    >>> db = ZODB.tests.util.DB()
-    >>> tm1 = transaction.TransactionManager()
-    >>> c1 = db.open(transaction_manager=tm1)
-    >>> from zope.component.persistentregistry import PersistentAdapterRegistry
-    >>> r1 = PersistentAdapterRegistry((base,))
-    >>> r2 = PersistentAdapterRegistry((r1,))
-    >>> c1.root()[1] = r1
-    >>> c1.root()[2] = r2
-    >>> tm1.commit()
-    >>> r1._p_deactivate()
-
-    >>> len(base._v_subregistries)
-    0
-
-    >>> tm2 = transaction.TransactionManager()
-    >>> c2 = db.open(transaction_manager=tm2)
-    >>> r1 = c2.root()[1]
-    >>> r2 = c2.root()[2]
-
-    >>> r1.lookup((), IFoo, '')
-
-    >>> base.register((), IFoo, '', Foo(''))
-    >>> r1.lookup((), IFoo, '')
-    Foo('')
-
-    >>> r2.lookup((), IFoo, '1')
-
-    >>> r1.register((), IFoo, '1', Foo('1'))
-
-    >>> r2.lookup((), IFoo, '1')
-    Foo('1')
-
-    >>> r1.lookup((), IFoo, '2')
-    >>> r2.lookup((), IFoo, '2')
-
-    >>> base.register((), IFoo, '2', Foo('2'))
-
-    >>> r1.lookup((), IFoo, '2')
-    Foo('2')
-
-    >>> r2.lookup((), IFoo, '2')
-    Foo('2')
-
-Cleanup:
-
-    >>> db.close()
-    >>> clear_base()
-    >>> tearDown()
-    """
-
-
-def test_suite():
-    import doctest
-    return unittest.TestSuite((
-        doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
-        ))



More information about the checkins mailing list