[Zope-CVS] CVS: Products/ZCTextIndex/tests - testQueryEngine.py:1.1.2.3
Guido van Rossum
guido@python.org
Wed, 1 May 2002 10:53:46 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv11211
Modified Files:
Tag: TextIndexDS9-branch
testQueryEngine.py
Log Message:
Add some more tests. Better error reporting in compareSet, by
converting the set to a dict and then calling assertEqual on that and
the expected dict.
=== Products/ZCTextIndex/tests/testQueryEngine.py 1.1.2.2 => 1.1.2.3 ===
def search(self, term):
+ b = IIBucket()
if term == "foo":
- b = IIBucket()
- b[1] = 1
- b[3] = 1
- return b
- if term == "bar":
- b = IIBucket()
- b[1] = 1
- b[2] = 1
- return b
- return IIBucket() # an empty one
+ b[1] = b[3] = 1
+ elif term == "bar":
+ b[1] = b[2] = 1
+ elif term == "ham":
+ b[1] = b[2] = b[3] = b[4] = 1
+ return b
class TestQueryEngine(TestCase):
@@ -42,9 +39,10 @@
self.index = FauxIndex()
def compareSet(self, set, dict):
- self.assertEqual(len(set), len(dict))
- for k, v in dict.items():
- self.assertEqual(set[k], v)
+ d = {}
+ for k, v in set.items():
+ d[k] = v
+ self.assertEqual(d, dict)
def compareQuery(self, query, dict):
tree = self.parser.parseQuery(query)
@@ -57,6 +55,9 @@
self.compareQuery("foo AND NOT bar", {3: 1})
self.compareQuery("foo AND foo AND foo", {1: 3, 3: 3})
self.compareQuery("foo OR foo OR foo", {1: 3, 3: 3})
+ self.compareQuery("ham AND NOT foo AND NOT bar", {4: 1})
+ self.compareQuery("ham OR foo OR bar", {1: 3, 2: 2, 3: 2, 4: 1})
+ self.compareQuery("ham AND foo AND bar", {1: 3})
def testInvalidQuery(self):
from Products.ZCTextIndex.QueryParser import NotNode, AtomNode