[Checkins] SVN: zope.component/tseaver-test_cleanup/ Moar getUtilty / queryUtility API doctests to Sphinx / unittests.

Tres Seaver cvs-admin at zope.org
Sun Jun 17 21:36:56 UTC 2012


Log message for revision 126903:
  Moar getUtilty / queryUtility 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/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:48 UTC (rev 126902)
+++ zope.component/tseaver-test_cleanup/docs/api.rst	2012-06-17 21:36:53 UTC (rev 126903)
@@ -5,95 +5,93 @@
 Site Manager APIs
 -----------------
 
-.. automodule:: zope.component
+.. autofunction:: zope.component.getGlobalSiteManager
 
-   .. autofunction:: getGlobalSiteManager
+   The API returns the module-scope global registry:
 
-      The API returns the module-scope global registry:
+   .. doctest::
 
-      .. doctest::
+      >>> from zope.component.interfaces import IComponentLookup
+      >>> from zope.component.globalregistry import base
+      >>> from zope.component import getGlobalSiteManager
+      >>> gsm = getGlobalSiteManager()
+      >>> gsm is base
+      True
 
-         >>> 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:
 
-      The registry implements the
-      :class:`~zope.component.interfaces.IComponentLookup` interface:
+   .. doctest::
 
-      .. doctest::
+      >>> IComponentLookup.providedBy(gsm)
+      True
 
-         >>> IComponentLookup.providedBy(gsm)
-         True
+   The same registry is returned each time we call the function:
 
-      The same registry is returned each time we call the function:
+   .. doctest::
 
-      .. doctest::
+      >>> getGlobalSiteManager() is gsm
+      True
 
-         >>> getGlobalSiteManager() is gsm
-         True
+.. autofunction:: zope.component.getSiteManager(context=None)
 
-   .. autofunction:: getSiteManager(context=None)
+   We don't know anything about the default service manager, except that it
+   is an `IComponentLookup`.
 
-      We don't know anything about the default service manager, except that it
-      is an `IComponentLookup`.
+   .. doctest::
 
-      .. doctest::
+     >>> from zope.component import getSiteManager
+     >>> from zope.component.interfaces import IComponentLookup
+     >>> IComponentLookup.providedBy(getSiteManager())
+     True
 
-        >>> 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`.
 
-      Calling `getSiteManager()` with no args is equivalent to calling it with a
-      context of `None`.
+   .. doctest::
 
-      .. doctest::
+     >>> getSiteManager() is getSiteManager(None)
+     True
 
-        >>> 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.
 
-      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:
 
-      Let's create the simplest stub-implementation of a site manager possible:
+   .. doctest::
 
-      .. doctest::
+     >>> sitemanager = object()
 
-        >>> sitemanager = object()
+   Now create a context that knows how to adapt to our newly created site
+   manager.
 
-      Now create a context that knows how to adapt to our newly created site
-      manager.
+   .. doctest::
 
-      .. doctest::
+     >>> from zope.component.tests.test_doctests \
+     ...    import ConformsToIComponentLookup
+     >>> context = ConformsToIComponentLookup(sitemanager)
 
-        >>> from zope.component.tests.test_doctests \
-        ...    import ConformsToIComponentLookup
-        >>> context = ConformsToIComponentLookup(sitemanager)
+   Now make sure that the `getSiteManager()` API call returns the correct
+   site manager.
 
-      Now make sure that the `getSiteManager()` API call returns the correct
-      site manager.
+   .. doctest::
 
-      .. doctest::
+     >>> getSiteManager(context) is sitemanager
+     True
 
-        >>> getSiteManager(context) is sitemanager
-        True
+   Using a context that is not adaptable to `IComponentLookup` should fail.
 
-      Using a context that is not adaptable to `IComponentLookup` should fail.
+   .. doctest::
 
-      .. doctest::
+     >>> getSiteManager(sitemanager)
+     Traceback (most recent call last):
+     ...
+     ComponentLookupError: ('Could not adapt', <instance Ob>,
+     <InterfaceClass zope...interfaces.IComponentLookup>)
 
-        >>> getSiteManager(sitemanager)
-        Traceback (most recent call last):
-        ...
-        ComponentLookupError: ('Could not adapt', <instance Ob>,
-        <InterfaceClass zope...interfaces.IComponentLookup>)
 
-
 Utility Registration APIs
 -------------------------
 
@@ -105,13 +103,16 @@
 course. The pure instatiation of an object does not make it a utility. If
 you do not specify a default, you get a `ComponentLookupError`.
 
+.. testsetup::
+
+   from zope.component.testing import setUp
+   setUp()
+
 .. doctest::
 
    >>> from zope.component import getUtility
    >>> from zope.component import queryUtility
-   >>> from zope.component.testing import setUp, tearDown
    >>> from zope.component.tests.test_doctests import I1
-   >>> setUp()
    >>> getUtility(I1) #doctest: +NORMALIZE_WHITESPACE
    Traceback (most recent call last):
    ...
@@ -141,16 +142,44 @@
    True
    >>> queryUtility(I1) is ob
    True
-   >>> tearDown()
 
-.. automodule:: zope.component
+Registering a utility without a name does not mean that it is available
+when looking for the utility with a name:
 
-   .. autofunction:: getUtility
+.. doctest::
 
-   .. autofunction:: queryUtility
+   >>> getUtility(I1, name='foo')
+   Traceback (most recent call last):
+   ...
+   ComponentLookupError:
+   (<InterfaceClass zope.component.tests.test_doctests.I1>, 'foo')
 
+   >>> queryUtility(I1, name='foo', default='<default>')
+   '<default>'
 
+Registering the utility under the correct name makes it available:
 
+.. doctest::
+
+   >>> getGlobalSiteManager().registerUtility(ob, I1, name='foo')
+   >>> getUtility(I1, 'foo') is ob
+   True
+   >>> queryUtility(I1, 'foo') is ob
+   True
+
+
+.. testcleanup::
+
+   from zope.component.testing import tearDown
+   tearDown()
+
+
+.. autofunction:: zope.component.getUtility
+
+.. autofunction:: zope.component.queryUtility
+
+
+
 :mod:`zope.component.interfaces`
 ================================
 

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:48 UTC (rev 126902)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py	2012-06-17 21:36:53 UTC (rev 126903)
@@ -492,42 +492,6 @@
       >>> tearDown()
     """
 
-def testNamedUtility():
-    """Like adapters, utilities can be named.
-
-    Just because you register an utility having no name
-
-      >>> from zope.component.testing import setUp, tearDown
-      >>> setUp()
-      >>> component.getGlobalSiteManager().registerUtility(ob, I1)
-
-    does not mean that they are available when you specify a name:
-
-      >>> component.getUtility(I1, name='foo') \\
-      ... #doctest: +NORMALIZE_WHITESPACE
-      Traceback (most recent call last):
-      ...
-      ComponentLookupError:
-      (<InterfaceClass zope.component.tests.test_doctests.I1>, 'foo')
-
-
-    ...otherwise, you get the default
-
-      >>> component.queryUtility(I1, name='foo', default='<default>')
-      '<default>'
-
-    Registering the utility under the correct name
-
-      >>> component.getGlobalSiteManager().registerUtility(
-      ...     ob, I1, name='foo')
-
-    really helps:
-
-      >>> component.getUtility(I1, 'foo') is ob
-      True
-      >>> tearDown()
-    """
-
 def test_getAllUtilitiesRegisteredFor():
     """Again, like for adapters, it is often useful to get a list of all
     utilities that have been registered for a particular interface. Utilities



More information about the checkins mailing list