Skip to content

Commit

Permalink
Using Python's doctest module instead of deprecated ``zope.testin…
Browse files Browse the repository at this point in the history
…g.doctest``.
  • Loading branch information
menesis committed May 20, 2013
1 parent e918206 commit 6c026bf
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 93 deletions.
6 changes: 2 additions & 4 deletions CHANGES.txt
Expand Up @@ -2,13 +2,11 @@
CHANGES
=======

The 1.2 line (and higher) supports Zope 3.4/ZODB 3.8. The 1.1 line supports
Zope 3.3/ZODB 3.7.

1.6 (unreleased)
----------------

- Nothing changed yet.
- Using Python's ``doctest`` module instead of deprecated
``zope.testing.doctest``.


1.5.1 (2012-01-20)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -68,7 +68,7 @@ def read(*rnames):
extras_require=dict(
test=[
'zope.keyreference',
'zope.testing < 4',
'zope.testing',
],
browser=[
'zope.app.form',
Expand Down
139 changes: 67 additions & 72 deletions src/zc/catalog/extentcatalog.txt
Expand Up @@ -8,9 +8,70 @@ and a set that may be merged with other result sets. The filtering is
an additional feature we will discuss below; we'll begin with a simple
"do nothing" extent that only supports the second use case.

We create the state that the text needs here.

>>> import zope.keyreference.persistent
>>> import zope.component
>>> import zope.intid
>>> import zope.component
>>> import zope.component.interfaces
>>> import zope.component.persistentregistry
>>> from ZODB.tests.util import DB
>>> import transaction

>>> zope.component.provideAdapter(
... zope.keyreference.persistent.KeyReferenceToPersistent,
... adapts=(zope.interface.Interface,))
>>> zope.component.provideAdapter(
... zope.keyreference.persistent.connectionOfPersistent,
... adapts=(zope.interface.Interface,))

>>> site_manager = None
>>> def getSiteManager(context=None):
... if context is None:
... if site_manager is None:
... return zope.component.getGlobalSiteManager()
... else:
... return site_manager
... else:
... try:
... return zope.component.interfaces.IComponentLookup(context)
... except TypeError, error:
... raise zope.component.ComponentLookupError(*error.args)
...
>>> def setSiteManager(sm):
... global site_manager
... site_manager = sm
... if sm is None:
... zope.component.getSiteManager.reset()
... else:
... zope.component.getSiteManager.sethook(getSiteManager)
...
>>> def makeRoot():
... db = DB()
... conn = db.open()
... root = conn.root()
... site_manager = root['components'] = (
... zope.component.persistentregistry.PersistentComponents())
... site_manager.__bases__ = (zope.component.getGlobalSiteManager(),)
... site_manager.registerUtility(
... zope.intid.IntIds(family=btrees_family),
... provided=zope.intid.interfaces.IIntIds)
... setSiteManager(site_manager)
... transaction.commit()
... return root
...

>>> @zope.component.adapter(zope.interface.Interface)
... @zope.interface.implementer(zope.component.interfaces.IComponentLookup)
... def getComponentLookup(obj):
... return obj._p_jar.root()['components']
...
>>> zope.component.provideAdapter(getComponentLookup)

To show the extent catalog at work, we need an intid utility, an
index, some items to index. We'll do this within a real ZODB and a
real intid utility [#setup]_.
real intid utility.

>>> import zc.catalog
>>> import zc.catalog.interfaces
Expand Down Expand Up @@ -262,9 +323,12 @@ the catalog will use its uid source to look up the objects by id.
>>> uid in cat["index"].uids
True

Unregister the objects of the previous tests from intid utility:


[#cleanup]_
>>> intid = zope.component.getUtility(
... zope.intid.interfaces.IIntIds, context=root)
>>> for doc_id in matches:
... intid.unregister(intid.queryObject(doc_id))


Catalog with a filter extent
Expand Down Expand Up @@ -501,72 +565,3 @@ We'll make sure everything can be safely committed.

>>> transaction.commit()
>>> setSiteManager(None)

.. [#setup] We create the state that the text needs here.

>>> import zope.keyreference.persistent
>>> import zope.component
>>> import zope.intid
>>> import zope.component
>>> import zope.component.interfaces
>>> import zope.component.persistentregistry
>>> from ZODB.tests.util import DB
>>> import transaction

>>> zope.component.provideAdapter(
... zope.keyreference.persistent.KeyReferenceToPersistent,
... adapts=(zope.interface.Interface,))
>>> zope.component.provideAdapter(
... zope.keyreference.persistent.connectionOfPersistent,
... adapts=(zope.interface.Interface,))

>>> site_manager = None
>>> def getSiteManager(context=None):
... if context is None:
... if site_manager is None:
... return zope.component.getGlobalSiteManager()
... else:
... return site_manager
... else:
... try:
... return zope.component.interfaces.IComponentLookup(context)
... except TypeError, error:
... raise zope.component.ComponentLookupError(*error.args)
...
>>> def setSiteManager(sm):
... global site_manager
... site_manager = sm
... if sm is None:
... zope.component.getSiteManager.reset()
... else:
... zope.component.getSiteManager.sethook(getSiteManager)
...
>>> def makeRoot():
... db = DB()
... conn = db.open()
... root = conn.root()
... site_manager = root['components'] = (
... zope.component.persistentregistry.PersistentComponents())
... site_manager.__bases__ = (zope.component.getGlobalSiteManager(),)
... site_manager.registerUtility(
... zope.intid.IntIds(family=btrees_family),
... provided=zope.intid.interfaces.IIntIds)
... setSiteManager(site_manager)
... transaction.commit()
... return root
...

>>> @zope.component.adapter(zope.interface.Interface)
... @zope.interface.implementer(zope.component.interfaces.IComponentLookup)
... def getComponentLookup(obj):
... return obj._p_jar.root()['components']
...
>>> zope.component.provideAdapter(getComponentLookup)


.. [#cleanup] Unregister the objects of the previous tests from intid utility:

>>> intid = zope.component.getUtility(
... zope.intid.interfaces.IIntIds, context=root)
>>> for doc_id in matches:
... intid.unregister(intid.queryObject(doc_id))
17 changes: 8 additions & 9 deletions src/zc/catalog/setindex.txt
Expand Up @@ -104,13 +104,20 @@ and all document ids with any values is returned.

The 'all_of' argument also takes an iterable of values, but returns an
iterable of document ids that contains all of the values. The results are not
weighted [#all_of_regression_test]_.
weighted.

>>> list(index.apply({'all_of': ('a',)}))
[1, 2, 9]
>>> list(index.apply({'all_of': (3, 4)}))
[2, 9]

These tests illustrate two related reported errors that have been fixed.

>>> list(index.apply({'all_of': ('z', 3, 4)}))
[]
>>> list(index.apply({'all_of': (3, 4, 'z')}))
[]

The 'between' argument takes from 1 to four values. The first is the
minimum, and defaults to None, indicating no minimum; the second is the
maximum, and defaults to None, indicating no maximum; the next is a boolean for
Expand Down Expand Up @@ -232,11 +239,3 @@ values.
True
>>> index.containsValue(20)
False

.. [#all_of_regression_test] These tests illustrate two related reported
errors that have been fixed.

>>> list(index.apply({'all_of': ('z', 3, 4)}))
[]
>>> list(index.apply({'all_of': (3, 4, 'z')}))
[]
12 changes: 5 additions & 7 deletions src/zc/catalog/tests.py
Expand Up @@ -17,7 +17,8 @@
"""

import unittest
from zope.testing import doctest, module
import doctest
from zope.testing import module
import zope.component.testing
import zope.component.factory
import zope.component.interfaces
Expand Down Expand Up @@ -59,11 +60,9 @@ def test_suite():
tests = unittest.TestSuite((
# 32 bits
doctest.DocFileSuite(
'extentcatalog.txt', setUp=modSetUp32bit, tearDown=modTearDown,
optionflags=doctest.INTERPRET_FOOTNOTES),
'extentcatalog.txt', setUp=modSetUp32bit, tearDown=modTearDown),
doctest.DocFileSuite(
'setindex.txt', setUp=setUp32bit, tearDown=tearDown,
optionflags=doctest.INTERPRET_FOOTNOTES),
'setindex.txt', setUp=setUp32bit, tearDown=tearDown),
doctest.DocFileSuite(
'valueindex.txt', setUp=setUp32bit, tearDown=tearDown),
doctest.DocFileSuite(
Expand All @@ -75,8 +74,7 @@ def test_suite():

# 64 bits
doctest.DocFileSuite(
'extentcatalog.txt', setUp=modSetUp64bit, tearDown=modTearDown,
optionflags=doctest.INTERPRET_FOOTNOTES),
'extentcatalog.txt', setUp=modSetUp64bit, tearDown=modTearDown),
doctest.DocFileSuite('setindex.txt', setUp=setUp64bit,
tearDown=tearDown),
doctest.DocFileSuite('valueindex.txt', setUp=setUp64bit,
Expand Down

0 comments on commit 6c026bf

Please sign in to comment.