[Zope-CVS] CVS: Products/ZCTextIndex/tests - testZCTextIndex.py:1.1.2.1 testIndex.py:1.1.2.3
Jeremy Hylton
jeremy@zope.com
Thu, 2 May 2002 11:57:40 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv28733/tests
Modified Files:
Tag: TextIndexDS9-branch
testIndex.py
Added Files:
Tag: TextIndexDS9-branch
testZCTextIndex.py
Log Message:
Add tests of ZCTextIndex based on testIndex.
Modify testIndex tests to use the lexicon API rather than depending on
the internal implementation of SimpleLexicon in testIndex. This
change allows the tests to work with either the stub SimpleLexicon or
a real Lexicon.
=== Added File Products/ZCTextIndex/tests/testZCTextIndex.py ===
from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
from Products.ZCTextIndex.tests import testIndex
import unittest
class ZCTextIndexTests(testIndex.IndexTest):
def setUp(self):
self.zc_index = ZCTextIndex()
# setup the attrs that the testIndex tests expect
self.index = self.zc_index.index
self.lexicon = self.zc_index.lexicon
def test_suite():
return unittest.makeSuite(ZCTextIndexTests)
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
=== Products/ZCTextIndex/tests/testIndex.py 1.1.2.2 => 1.1.2.3 ===
def test_index_document(self, DOCID=1):
- doc = Indexable("this is a simple document")
+ doc = Indexable("this doc is simple document")
self.index.index_object(DOCID, doc)
self.assert_(self.index._docweight[DOCID])
self.assertEqual(len(self.index._wordinfo), 5)
@@ -81,14 +81,16 @@
def test_index_two_documents(self):
self.test_index_document()
- doc = MethodIndexable('not the same document')
+ doc = MethodIndexable("not the same document")
DOCID = 2
self.index.index_object(DOCID, doc)
self.assert_(self.index._docweight[DOCID])
self.assertEqual(len(self.index._wordinfo), 8)
self.assertEqual(len(self.index._docwords), 2)
self.assertEqual(len(self.index._docwords[DOCID]), 4)
- document_wid = self.lexicon._words["document"]
+ wids = self.lexicon.termToWordIds("document")
+ self.assertEqual(len(wids), 1)
+ document_wid = wids[0]
for wid, map in self.index._wordinfo.items():
if wid == document_wid:
self.assertEqual(len(map), 2)
@@ -112,13 +114,15 @@
self.assert_(map.has_key(DOCID))
def test_index_duplicated_words(self, DOCID=1):
- doc = Indexable("this is a repititive repititive repititive document")
+ doc = Indexable("the doc is repetitive repetitive repetitive document")
self.index.index_object(DOCID, doc)
self.assert_(self.index._docweight[DOCID])
self.assertEqual(len(self.index._wordinfo), 5)
self.assertEqual(len(self.index._docwords), 1)
self.assertEqual(len(self.index._docwords[DOCID]), 5)
- repititive_wid = self.lexicon._words["repititive"]
+ wids = self.lexicon.termToWordIds("repetitive")
+ self.assertEqual(len(wids), 1)
+ repititive_wid = wids[0]
for wid, map in self.index._wordinfo.items():
self.assertEqual(len(map), 1)
self.assert_(map.has_key(DOCID))