[Checkins] SVN: zope.index/trunk/src/zope/index/text/ 100% coverage for zope.index.text.baseindex module.
Tres Seaver
tseaver at palladion.com
Wed Jun 10 16:23:23 EDT 2009
Log message for revision 100812:
100% coverage for zope.index.text.baseindex module.
Make subclass contracts clearer for 'wordCount' / 'documentCount'.
Call 'clear' from '__init__', rather than vice versa.
Changed:
U zope.index/trunk/src/zope/index/text/baseindex.py
A zope.index/trunk/src/zope/index/text/tests/test_base.py
-=-
Modified: zope.index/trunk/src/zope/index/text/baseindex.py
===================================================================
--- zope.index/trunk/src/zope/index/text/baseindex.py 2009-06-10 20:21:29 UTC (rev 100811)
+++ zope.index/trunk/src/zope/index/text/baseindex.py 2009-06-10 20:23:22 UTC (rev 100812)
@@ -21,18 +21,16 @@
from zope.interface import implements
import BTrees
-
from BTrees import Length
from BTrees.IOBTree import IOBTree
-from zope.index.interfaces import IInjection, IStatistics
-
+from zope.index.interfaces import IInjection
+from zope.index.interfaces import IStatistics
from zope.index.text.interfaces import IExtendedQuerying
from zope.index.text import widcode
-from zope.index.text.setops import mass_weightedIntersection, \
- mass_weightedUnion
+from zope.index.text.setops import mass_weightedIntersection
+from zope.index.text.setops import mass_weightedUnion
-
class BaseIndex(Persistent):
implements(IInjection, IStatistics, IExtendedQuerying)
@@ -42,7 +40,9 @@
if family is not None:
self.family = family
self._lexicon = lexicon
+ self.clear()
+ def clear(self):
# wid -> {docid -> weight}; t -> D -> w(D, t)
# Different indexers have different notions of term weight, but we
# expect each indexer to use ._wordinfo to map wids to its notion
@@ -74,22 +74,20 @@
self.wordCount = Length.Length()
self.documentCount = Length.Length()
- def clear(self):
- self.__init__(self._lexicon)
-
def wordCount(self):
"""Return the number of words in the index."""
- # This is overridden per instance
- return len(self._wordinfo)
+ # This must be overridden by subclasses which do not set the
+ # attribute on their instances.
+ raise NotImplementedError
def documentCount(self):
"""Return the number of documents in the index."""
- # overridden per instance
- return len(self._docweight)
+ # This must be overridden by subclasses which do not set the
+ # attribute on their instances.
+ raise NotImplementedError
def get_words(self, docid):
"""Return a list of the wordids for a given docid."""
- # Note this is overridden in the instance
return widcode.decode(self._docwords[docid])
# A subclass may wish to extend or override this.
@@ -105,7 +103,7 @@
self.documentCount.change(1)
except AttributeError:
# upgrade documentCount to Length object
- self.documentCount = Length.Length(self.documentCount())
+ self.documentCount = Length.Length(len(self._docweight))
return len(wids)
# A subclass may wish to extend or override this. This is for adjusting
@@ -174,7 +172,7 @@
self.documentCount.change(-1)
except AttributeError:
# upgrade documentCount to Length object
- self.documentCount = Length.Length(self.documentCount())
+ self.documentCount = Length.Length(len(self._docweight))
def search(self, term):
wids = self._lexicon.termToWordIds(term)
@@ -254,8 +252,13 @@
# holds up to 120 key-value pairs in a single bucket.
doc2score = self._wordinfo.get(wid)
if doc2score is None:
- doc2score = {}
- self.wordCount.change(1)
+ doc2score = {} # XXX Holy ConflictError, Batman!
+ try:
+ self.wordCount.change(1)
+ except AttributeError:
+ # upgrade wordCount to Length object
+ self.wordCount = Length.Length(len(self._wordinfo))
+ self.wordCount.change(1)
else:
# _add_wordinfo() is called for each update. If the map
# size exceeds the DICT_CUTOFF, convert to an IFBTree.
@@ -290,7 +293,11 @@
doc2score = self.family.IF.BTree(doc2score)
doc2score[docid] = weight
self._wordinfo[wid] = doc2score # not redundant: Persistency!
- self.wordCount.change(new_word_count)
+ try:
+ self.wordCount.change(new_word_count)
+ except AttributeError:
+ # upgrade wordCount to Length object
+ self.wordCount = Length.Length(len(self._wordinfo))
def _del_wordinfo(self, wid, docid):
doc2score = self._wordinfo[wid]
@@ -299,7 +306,11 @@
self._wordinfo[wid] = doc2score # not redundant: Persistency!
else:
del self._wordinfo[wid]
- self.wordCount.change(-1)
+ try:
+ self.wordCount.change(-1)
+ except AttributeError:
+ # upgrade wordCount to Length object
+ self.wordCount = Length.Length(len(self._wordinfo))
def inverse_doc_frequency(term_count, num_items):
"""Return the inverse doc frequency for a term,
Copied: zope.index/trunk/src/zope/index/text/tests/test_base.py (from rev 100807, zope.index/trunk/src/zope/index/text/tests/test_cosine.py)
===================================================================
--- zope.index/trunk/src/zope/index/text/tests/test_base.py (rev 0)
+++ zope.index/trunk/src/zope/index/text/tests/test_base.py 2009-06-10 20:23:22 UTC (rev 100812)
@@ -0,0 +1,477 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation 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.
+#
+##############################################################################
+"""Text Index Tests
+
+$Id: test_index.py 100805 2009-06-10 17:58:58Z tseaver $
+"""
+import unittest
+
+class BaseIndexTestBase:
+ # Subclasses must define '_getBTreesFamily'
+ def _getTargetClass(self):
+ from zope.index.text.baseindex import BaseIndex
+ return BaseIndex
+
+ def _makeOne(self, family=None):
+ from zope.index.text.lexicon import Lexicon
+ from zope.index.text.lexicon import Splitter
+ if family is None:
+ family = self._getBTreesFamily()
+ lexicon = Lexicon(Splitter())
+ return self._getTargetClass()(lexicon, family=family)
+
+ def test_class_conforms_to_IInjection(self):
+ from zope.interface.verify import verifyClass
+ from zope.index.interfaces import IInjection
+ verifyClass(IInjection, self._getTargetClass())
+
+ def test_instance_conforms_to_IInjection(self):
+ from zope.interface.verify import verifyObject
+ from zope.index.interfaces import IInjection
+ verifyObject(IInjection, self._makeOne())
+
+ def test_class_conforms_to_IStatistics(self):
+ from zope.interface.verify import verifyClass
+ from zope.index.interfaces import IStatistics
+ verifyClass(IStatistics, self._getTargetClass())
+
+ def test_instance_conforms_to_IStatistics(self):
+ from zope.interface.verify import verifyObject
+ from zope.index.interfaces import IStatistics
+ verifyObject(IStatistics, self._makeOne())
+
+ def test_class_conforms_to_IExtendedQuerying(self):
+ from zope.interface.verify import verifyClass
+ from zope.index.text.interfaces import IExtendedQuerying
+ verifyClass(IExtendedQuerying, self._getTargetClass())
+
+ def test_instance_conforms_to_IExtendedQuerying(self):
+ from zope.interface.verify import verifyObject
+ from zope.index.text.interfaces import IExtendedQuerying
+ verifyObject(IExtendedQuerying, self._makeOne())
+
+ def test_empty(self):
+ index = self._makeOne()
+ self.assertEqual(len(index._wordinfo), 0)
+ self.assertEqual(len(index._docweight), 0)
+ self.assertEqual(len(index._docwords), 0)
+ self.assertEqual(index.wordCount(), 0)
+ self.assertEqual(index.documentCount(), 0)
+ self.failIf(index.has_doc(1))
+
+ def test_clear_doesnt_lose_family(self):
+ import BTrees
+ index = self._makeOne(family=BTrees.family64)
+ index.clear()
+ self.failUnless(index.family is BTrees.family64)
+
+ def test_wordCount_method_raises_NotImplementedError(self):
+ class DerviedDoesntSet_wordCount(self._getTargetClass()):
+ def __init__(self):
+ pass
+ index = DerviedDoesntSet_wordCount()
+ self.assertRaises(NotImplementedError, index.wordCount)
+
+ def test_documentCount_method_raises_NotImplementedError(self):
+ class DerviedDoesntSet_documentCount(self._getTargetClass()):
+ def __init__(self):
+ pass
+ index = DerviedDoesntSet_documentCount()
+ self.assertRaises(NotImplementedError, index.documentCount)
+
+ def test_index_doc_simple(self):
+ index = self._makeOne()
+
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+
+ count = index.index_doc(1, 'one two three')
+
+ self.assertEqual(count, 3)
+ self.assertEqual(index.wordCount(), 3)
+ self.failUnless(index._lexicon._wids['one'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['two'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['three'] in index._wordinfo)
+ self.assertEqual(index.documentCount(), 1)
+ self.failUnless(index.has_doc(1))
+ self.failUnless(1 in index._docwords)
+ self.failUnless(1 in index._docweight)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 3)
+ self.failUnless(index._lexicon._wids['one'] in wids)
+ self.failUnless(index._lexicon._wids['two'] in wids)
+ self.failUnless(index._lexicon._wids['three'] in wids)
+
+ def test_index_doc_existing_docid(self):
+ index = self._makeOne()
+
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+
+ index.index_doc(1, 'one two three')
+ count = index.index_doc(1, 'two three four')
+
+ self.assertEqual(count, 3)
+ self.assertEqual(index.wordCount(), 3)
+ self.failIf(index._lexicon._wids['one'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['two'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['three'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['four'] in index._wordinfo)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 3)
+ self.failIf(index._lexicon._wids['one'] in wids)
+ self.failUnless(index._lexicon._wids['two'] in wids)
+ self.failUnless(index._lexicon._wids['three'] in wids)
+ self.failUnless(index._lexicon._wids['four'] in wids)
+
+ def test_index_doc_upgrades_wordCount_documentCount(self):
+ index = self._makeOne()
+
+ # Simulate old instances which didn't have these as attributes
+ del index.wordCount
+ del index.documentCount
+
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+
+ count = index.index_doc(1, 'one two three')
+
+ self.assertEqual(count, 3)
+ self.assertEqual(index.wordCount(), 3)
+ self.assertEqual(index.documentCount(), 1)
+
+ def test__reindex_doc_identity(self):
+ index = self._makeOne()
+
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+
+ index.index_doc(1, 'one two three')
+
+ # Don't mutate _wordinfo if no changes
+ def _dont_go_here(*args, **kw):
+ assert 0
+ index._add_wordinfo = index._del_wordinfo = _dont_go_here
+
+ count = index._reindex_doc(1, 'one two three')
+
+ self.assertEqual(count, 3)
+ self.assertEqual(index.wordCount(), 3)
+ self.failUnless(index._lexicon._wids['one'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['two'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['three'] in index._wordinfo)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 3)
+ self.failUnless(index._lexicon._wids['one'] in wids)
+ self.failUnless(index._lexicon._wids['two'] in wids)
+ self.failUnless(index._lexicon._wids['three'] in wids)
+
+ def test__reindex_doc_disjoint(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ index._get_frequencies = _faux_get_frequencies
+
+ index.index_doc(1, 'one two three')
+ count = index._reindex_doc(1, 'four five six')
+
+ self.assertEqual(count, 3)
+ self.assertEqual(index.wordCount(), 3)
+ self.failIf(index._lexicon._wids['one'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['two'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['three'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['four'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['five'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['six'] in index._wordinfo)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 3)
+ self.failIf(index._lexicon._wids['one'] in wids)
+ self.failIf(index._lexicon._wids['two'] in wids)
+ self.failIf(index._lexicon._wids['three'] in wids)
+ self.failUnless(index._lexicon._wids['four'] in wids)
+ self.failUnless(index._lexicon._wids['five'] in wids)
+ self.failUnless(index._lexicon._wids['six'] in wids)
+
+ def test__reindex_doc_subset(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ index._get_frequencies = _faux_get_frequencies
+
+ index.index_doc(1, 'one two three')
+ count = index._reindex_doc(1, 'two three')
+
+ self.assertEqual(count, 2)
+ self.assertEqual(index.wordCount(), 2)
+ self.failIf(index._lexicon._wids['one'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['two'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['three'] in index._wordinfo)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 2)
+ self.failIf(index._lexicon._wids['one'] in wids)
+ self.failUnless(index._lexicon._wids['two'] in wids)
+ self.failUnless(index._lexicon._wids['three'] in wids)
+
+ def test__reindex_doc_superset(self): # TODO
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ index._get_frequencies = _faux_get_frequencies
+
+ index.index_doc(1, 'one two three')
+ count = index._reindex_doc(1, 'one two three four five six')
+
+ self.assertEqual(count, 6)
+ self.assertEqual(index.wordCount(), 6)
+ self.failUnless(index._lexicon._wids['one'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['two'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['three'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['four'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['five'] in index._wordinfo)
+ self.failUnless(index._lexicon._wids['six'] in index._wordinfo)
+ wids = index.get_words(1)
+ self.assertEqual(len(wids), 6)
+ self.failUnless(index._lexicon._wids['one'] in wids)
+ self.failUnless(index._lexicon._wids['two'] in wids)
+ self.failUnless(index._lexicon._wids['three'] in wids)
+ self.failUnless(index._lexicon._wids['four'] in wids)
+ self.failUnless(index._lexicon._wids['five'] in wids)
+ self.failUnless(index._lexicon._wids['six'] in wids)
+
+ def test__get_frequencies_raises_NotImplementedError(self):
+ index = self._makeOne()
+ self.assertRaises(NotImplementedError, index._get_frequencies, ())
+
+ def test_unindex_doc_simple(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ index._get_frequencies = _faux_get_frequencies
+ index.index_doc(1, 'one two three')
+ index.unindex_doc(1)
+ self.assertEqual(index.wordCount(), 0)
+ self.failIf(index._lexicon._wids['one'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['two'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['three'] in index._wordinfo)
+ self.assertEqual(index.documentCount(), 0)
+ self.failIf(index.has_doc(1))
+ self.failIf(1 in index._docwords)
+ self.failIf(1 in index._docweight)
+ self.assertRaises(KeyError, index.get_words, 1)
+
+ def test_unindex_doc_upgrades_wordCount_documentCount(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ # Fake out _get_frequencies, which is supposed to be overridden.
+ index._get_frequencies = _faux_get_frequencies
+ index.index_doc(1, 'one two three')
+ # Simulate old instances which didn't have these as attributes
+ del index.wordCount
+ del index.documentCount
+ index.unindex_doc(1)
+ self.assertEqual(index.wordCount(), 0)
+ self.failIf(index._lexicon._wids['one'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['two'] in index._wordinfo)
+ self.failIf(index._lexicon._wids['three'] in index._wordinfo)
+ self.assertEqual(index.documentCount(), 0)
+ self.failIf(index.has_doc(1))
+ self.failIf(1 in index._docwords)
+ self.failIf(1 in index._docweight)
+ self.assertRaises(KeyError, index.get_words, 1)
+
+ def test_search_w_empty_term(self):
+ index = self._makeOne()
+ self.assertEqual(index.search(''), None)
+
+ def test_search_w_oov_term(self):
+ index = self._makeOne()
+ def _faux_search_wids(wids):
+ assert len(wids) == 0
+ return []
+ index._search_wids = _faux_search_wids
+ self.assertEqual(dict(index.search('nonesuch')), {})
+
+ def test_search_hit(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+ def _faux_search_wids(wids):
+ assert len(wids) == 1
+ assert index._lexicon._wids['hit'] in wids
+ result = index.family.IF.Bucket()
+ result[1] = 1.0
+ return [(result, 1)]
+ index._search_wids = _faux_search_wids
+ index.index_doc(1, 'hit')
+ self.assertEqual(dict(index.search('hit')), {1: 1.0})
+
+ def test_search_glob_w_empty_term(self):
+ index = self._makeOne()
+ def _faux_search_wids(wids):
+ assert len(wids) == 0
+ return []
+ index._search_wids = _faux_search_wids
+ self.assertEqual(dict(index.search_glob('')), {})
+
+ def test_search_glob_w_oov_term(self):
+ index = self._makeOne()
+ def _faux_search_wids(wids):
+ assert len(wids) == 0
+ return []
+ index._search_wids = _faux_search_wids
+ self.assertEqual(dict(index.search_glob('nonesuch*')), {})
+
+ def test_search_glob_hit(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+ def _faux_search_wids(wids):
+ assert len(wids) == 1
+ assert index._lexicon._wids['hitter'] in wids
+ result = index.family.IF.Bucket()
+ result[1] = 1.0
+ return [(result, 1)]
+ index._search_wids = _faux_search_wids
+ index.index_doc(1, 'hitter')
+ self.assertEqual(dict(index.search_glob('hit*')), {1: 1.0})
+
+ def test_search_phrase_w_empty_term(self):
+ index = self._makeOne()
+ def _faux_search_wids(wids):
+ assert len(wids) == 0
+ return []
+ index._search_wids = _faux_search_wids
+ self.assertEqual(dict(index.search_phrase('')), {})
+
+ def test_search_phrase_w_oov_term(self):
+ index = self._makeOne()
+ self.assertEqual(dict(index.search_phrase('nonesuch')), {})
+
+ def test_search_phrase_hit(self):
+ index = self._makeOne()
+ def _faux_get_frequencies(wids):
+ return dict([(y, x) for x, y in enumerate(wids)]), 1
+ index._get_frequencies = _faux_get_frequencies
+ def _faux_search_wids(wids):
+ assert len(wids) == 3
+ assert index._lexicon._wids['hit'] in wids
+ assert index._lexicon._wids['the'] in wids
+ assert index._lexicon._wids['nail'] in wids
+ result = index.family.IF.Bucket()
+ result[1] = 1.0
+ return [(result, 1)]
+ index._search_wids = _faux_search_wids
+ index.index_doc(1, 'hit the nail on the head')
+ self.assertEqual(dict(index.search_phrase('hit the nail')), {1: 1.0})
+
+ def test__search_wids_raises_NotImplementedError(self):
+ index = self._makeOne()
+ self.assertRaises(NotImplementedError, index._search_wids, ())
+
+ def test_query_weight_raises_NotImplementedError(self):
+ index = self._makeOne()
+ self.assertRaises(NotImplementedError, index.query_weight, ())
+
+ def test__add_wordinfo_simple(self):
+ index = self._makeOne()
+ # Simulate old instances which didn't have these as attributes
+ index._add_wordinfo(123, 4, 1)
+ self.assertEqual(index.wordCount(), 1)
+ self.assertEqual(index._wordinfo[123], {1: 4})
+
+ def test__add_wordinfo_upgrades_wordCount(self):
+ index = self._makeOne()
+ # Simulate old instances which didn't have these as attributes
+ del index.wordCount
+ index._add_wordinfo(123, 4, 1)
+ self.assertEqual(index.wordCount(), 1)
+
+ def test__add_wordinfo_promotes_dict_to_tree_at_DICT_CUTOFF(self):
+ index = self._makeOne()
+ index.DICT_CUTOFF = 2
+ index._add_wordinfo(123, 4, 1)
+ index._add_wordinfo(123, 5, 2)
+ self.failUnless(isinstance(index._wordinfo[123], dict))
+ index._add_wordinfo(123, 6, 3)
+ self.failUnless(isinstance(index._wordinfo[123],
+ index.family.IF.BTree))
+ self.assertEqual(dict(index._wordinfo[123]), {1: 4, 2: 5, 3: 6})
+
+ def test__mass_add_wordinfo_promotes_dict_to_tree_at_DICT_CUTOFF(self):
+ index = self._makeOne()
+ index.DICT_CUTOFF = 2
+ index._add_wordinfo(123, 4, 1)
+ index._add_wordinfo(123, 5, 2)
+ index._mass_add_wordinfo({123: 6, 124: 1}, 3)
+ self.failUnless(isinstance(index._wordinfo[123],
+ index.family.IF.BTree))
+ self.assertEqual(dict(index._wordinfo[123]), {1: 4, 2: 5, 3: 6})
+
+ def test__del_wordinfo_no_residual_docscore(self):
+ index = self._makeOne()
+ # Simulate old instances which didn't have these as attributes
+ index._add_wordinfo(123, 4, 1)
+ index._del_wordinfo(123, 1)
+ self.assertEqual(index.wordCount(), 0)
+ self.assertRaises(KeyError, index._wordinfo.__getitem__, 123)
+
+ def test__del_wordinfo_w_residual_docscore(self):
+ index = self._makeOne()
+ # Simulate old instances which didn't have these as attributes
+ index._add_wordinfo(123, 4, 1)
+ index._add_wordinfo(123, 5, 2)
+ index._del_wordinfo(123, 1)
+ self.assertEqual(index.wordCount(), 1)
+ self.assertEqual(index._wordinfo[123], {2: 5})
+
+ def test__del_wordinfo_upgrades_wordCount(self):
+ index = self._makeOne()
+ index._add_wordinfo(123, 4, 1)
+ # Simulate old instances which didn't have these as attributes
+ del index.wordCount
+ index._del_wordinfo(123, 1)
+ self.assertEqual(index.wordCount(), 0)
+
+class BaseIndexTest32(BaseIndexTestBase, unittest.TestCase):
+
+ def _getBTreesFamily(self):
+ import BTrees
+ return BTrees.family32
+
+class BaseIndexTest64(BaseIndexTestBase, unittest.TestCase):
+
+ def _getBTreesFamily(self):
+ import BTrees
+ return BTrees.family64
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(BaseIndexTest32),
+ unittest.makeSuite(BaseIndexTest64),
+ ))
More information about the Checkins
mailing list