[Checkins] SVN: zope.component/tseaver-test_cleanup/ Move sitemanager API doctests to Sphinx / unittests.
Tres Seaver
cvs-admin at zope.org
Sun Jun 17 21:36:48 UTC 2012
Log message for revision 126901:
Move sitemanager API doctests to Sphinx / unittests.
Changed:
_U zope.component/tseaver-test_cleanup/
U zope.component/tseaver-test_cleanup/docs/api.rst
U zope.component/tseaver-test_cleanup/src/zope/component/_api.py
U zope.component/tseaver-test_cleanup/src/zope/component/tests/test___init__.py
U zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py
-=-
Modified: zope.component/tseaver-test_cleanup/docs/api.rst
===================================================================
--- zope.component/tseaver-test_cleanup/docs/api.rst 2012-06-17 21:36:38 UTC (rev 126900)
+++ zope.component/tseaver-test_cleanup/docs/api.rst 2012-06-17 21:36:44 UTC (rev 126901)
@@ -1,6 +1,96 @@
:mod:`zope.component` API
=========================
+
+.. automodule:: zope.component
+
+ .. autofunction:: getGlobalSiteManager
+
+ The API returns the module-scope global registry:
+
+ .. doctest::
+
+ >>> from zope.component.interfaces import IComponentLookup
+ >>> from zope.component.globalregistry import base
+ >>> from zope.component import getGlobalSiteManager
+ >>> gsm = getGlobalSiteManager()
+ >>> gsm is base
+ True
+
+ The registry implements the
+ :class:`~zope.component.interfaces.IComponentLookup` interface:
+
+ .. doctest::
+
+ >>> IComponentLookup.providedBy(gsm)
+ True
+
+ The same registry is returned each time we call the function:
+
+ .. doctest::
+
+ >>> getGlobalSiteManager() is gsm
+ True
+
+ .. autofunction:: getSiteManager(context=None)
+
+ We don't know anything about the default service manager, except that it
+ is an `IComponentLookup`.
+
+ .. doctest::
+
+ >>> from zope.component import getSiteManager
+ >>> from zope.component.interfaces import IComponentLookup
+ >>> IComponentLookup.providedBy(getSiteManager())
+ True
+
+ Calling `getSiteManager()` with no args is equivalent to calling it with a
+ context of `None`.
+
+ .. doctest::
+
+ >>> getSiteManager() is getSiteManager(None)
+ True
+
+ If the context passed to `getSiteManager()` is not `None`, it is
+ adapted to `IComponentLookup` and this adapter returned. So, we
+ create a context that can be adapted to `IComponentLookup` using
+ the `__conform__` API.
+
+ Let's create the simplest stub-implementation of a site manager possible:
+
+ .. doctest::
+
+ >>> sitemanager = object()
+
+ Now create a context that knows how to adapt to our newly created site
+ manager.
+
+ .. doctest::
+
+ >>> from zope.component.tests.test_doctests \
+ ... import ConformsToIComponentLookup
+ >>> context = ConformsToIComponentLookup(sitemanager)
+
+ Now make sure that the `getSiteManager()` API call returns the correct
+ site manager.
+
+ .. doctest::
+
+ >>> getSiteManager(context) is sitemanager
+ True
+
+ Using a context that is not adaptable to `IComponentLookup` should fail.
+
+ .. doctest::
+
+ >>> getSiteManager(sitemanager)
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ('Could not adapt', <instance Ob>,
+ <InterfaceClass zope...interfaces.IComponentLookup>)
+
+
:mod:`zope.component.interfaces`
--------------------------------
Modified: zope.component/tseaver-test_cleanup/src/zope/component/_api.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/_api.py 2012-06-17 21:36:38 UTC (rev 126900)
+++ zope.component/tseaver-test_cleanup/src/zope/component/_api.py 2012-06-17 21:36:44 UTC (rev 126901)
@@ -33,7 +33,7 @@
# to our Python version if not.
try:
from zope.hookable import hookable
-except ImportError:
+except ImportError: #pragma NO COVER
from zope.component.hookable import hookable
# getSiteManager() returns a component registry. Although the term
@@ -42,6 +42,8 @@
base = None
@hookable
def getSiteManager(context=None):
+ """ See IComponentArchitecture.
+ """
global base
if context is None:
if base is None:
Modified: zope.component/tseaver-test_cleanup/src/zope/component/tests/test___init__.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/tests/test___init__.py 2012-06-17 21:36:38 UTC (rev 126900)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/test___init__.py 2012-06-17 21:36:44 UTC (rev 126901)
@@ -28,7 +28,42 @@
import zope.component as zc
verifyObject(IComponentRegistrationConvenience, zc)
+ def test_getGlobalSiteManager(self):
+ from zope.component.globalregistry import base
+ from zope.component.interfaces import IComponentLookup
+ import zope.component as zc
+ gsm = zc.getGlobalSiteManager()
+ self.assertTrue(gsm is base)
+ self.assertTrue(IComponentLookup.providedBy(gsm))
+ self.assertTrue(zc.getGlobalSiteManager() is gsm)
+ def test_getSiteManager_no_args(self):
+ from zope.component.globalregistry import base
+ from zope.component.interfaces import IComponentLookup
+ import zope.component as zc
+ sm = zc.getSiteManager()
+ self.assertTrue(sm is base)
+ self.assertTrue(IComponentLookup.providedBy(sm))
+ self.assertTrue(zc.getSiteManager() is sm)
+
+ def test_getSiteManager_w_None(self):
+ import zope.component as zc
+ self.assertTrue(zc.getSiteManager(None) is zc.getSiteManager())
+
+ def test_getSiteManager_w_conforming_context(self):
+ import zope.component as zc
+ from zope.component.tests.test_doctests \
+ import ConformsToIComponentLookup
+ sitemanager = object()
+ context = ConformsToIComponentLookup(sitemanager)
+ self.assertTrue(zc.getSiteManager(context) is sitemanager)
+
+ def test_getSiteManager_w_invalid_context(self):
+ import zope.component as zc
+ from zope.component.interfaces import ComponentLookupError
+ self.assertRaises(ComponentLookupError, zc.getSiteManager, object())
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(PackageAPITests),
Modified: zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py 2012-06-17 21:36:38 UTC (rev 126900)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py 2012-06-17 21:36:44 UTC (rev 126901)
@@ -166,83 +166,6 @@
return self.sitemanager
-def test_getGlobalSiteManager():
- """One of the most important functions is to get the global site manager.
-
- >>> from zope.component.testing import setUp, tearDown
- >>> setUp()
- >>> from zope.component.interfaces import IComponentLookup
- >>> from zope.component.globalregistry import base
-
- Get the global site manager via the CA API function:
-
- >>> gsm = component.getGlobalSiteManager()
-
- Make sure that the global site manager implements the correct interface
- and is the global site manager instance we expect to get.
-
- >>> IComponentLookup.providedBy(gsm)
- True
- >>> base is gsm
- True
-
- Finally, ensure that we always get the same global site manager, otherwise
- our component registry will always be reset.
-
- >>> component.getGlobalSiteManager() is gsm
- True
- >>> tearDown()
- """
-
-def test_getSiteManager():
- """Make sure that `getSiteManager()` always returns the correct site
- manager instance.
-
- We don't know anything about the default service manager, except that it
- is an `IComponentLookup`.
-
- >>> from zope.component.testing import setUp, tearDown
- >>> setUp()
- >>> from zope.component.interfaces import IComponentLookup
- >>> IComponentLookup.providedBy(component.getSiteManager())
- True
-
- Calling `getSiteManager()` with no args is equivalent to calling it with a
- context of `None`.
-
- >>> component.getSiteManager() is component.getSiteManager(None)
- True
-
- If the context passed to `getSiteManager()` is not `None`, it is
- adapted to `IComponentLookup` and this adapter returned. So, we
- create a context that can be adapted to `IComponentLookup` using
- the `__conform__` API.
-
- Let's create the simplest stub-implementation of a site manager possible:
-
- >>> sitemanager = object()
-
- Now create a context that knows how to adapt to our newly created site
- manager.
-
- >>> context = ConformsToIComponentLookup(sitemanager)
-
- Now make sure that the `getSiteManager()` API call returns the correct
- site manager.
-
- >>> component.getSiteManager(context) is sitemanager
- True
-
- Using a context that is not adaptable to `IComponentLookup` should fail.
-
- >>> component.getSiteManager(ob) #doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
- Traceback (most recent call last):
- ...
- ComponentLookupError: ('Could not adapt', <instance Ob>,
- <InterfaceClass zope...interfaces.IComponentLookup>)
- >>> tearDown()
- """
-
def testAdapterInContext(self):
"""The `getAdapterInContext()` and `queryAdapterInContext()` API functions
do not only use the site manager to look up the adapter, but first tries
More information about the checkins
mailing list