diff --git a/CHANGES.txt b/CHANGES.txt index 972f655..b82174a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/setup.py b/setup.py index fd837c4..9c06620 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ def read(*rnames): extras_require=dict( test=[ 'zope.keyreference', - 'zope.testing < 4', + 'zope.testing', ], browser=[ 'zope.app.form', diff --git a/src/zc/catalog/extentcatalog.txt b/src/zc/catalog/extentcatalog.txt index 9c18e1e..7535e5d 100644 --- a/src/zc/catalog/extentcatalog.txt +++ b/src/zc/catalog/extentcatalog.txt @@ -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 @@ -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 @@ -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)) diff --git a/src/zc/catalog/setindex.txt b/src/zc/catalog/setindex.txt index 9d61679..ff4b61e 100644 --- a/src/zc/catalog/setindex.txt +++ b/src/zc/catalog/setindex.txt @@ -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 @@ -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')})) - [] diff --git a/src/zc/catalog/tests.py b/src/zc/catalog/tests.py index 04a2419..20d4de6 100644 --- a/src/zc/catalog/tests.py +++ b/src/zc/catalog/tests.py @@ -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 @@ -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( @@ -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,