[Zope-Checkins] CVS: Zope/lib/python/SearchIndex/tests - testSplitter.py:1.6 testUnKeywordIndex.py:1.9 testUnTextIndex.py:1.13 test_UnIndex.py:1.8
Martijn Pieters
mj@zope.com
Wed, 14 Aug 2002 17:46:24 -0400
Update of /cvs-repository/Zope/lib/python/SearchIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv16076/tests
Modified Files:
testSplitter.py testUnKeywordIndex.py testUnTextIndex.py
test_UnIndex.py
Log Message:
Clean up indentation and trailing whitespace.
=== Zope/lib/python/SearchIndex/tests/testSplitter.py 1.5 => 1.6 ===
--- Zope/lib/python/SearchIndex/tests/testSplitter.py:1.5 Wed Jun 12 16:39:19 2002
+++ Zope/lib/python/SearchIndex/tests/testSplitter.py Wed Aug 14 17:46:24 2002
@@ -1,44 +1,44 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
-#
+#
##############################################################################
import unittest
from SearchIndex.Splitter import Splitter
class Tests(unittest.TestCase):
- def testSplitNormalText(self):
- text = 'this is a long string of words'
- a = Splitter(text)
- r = map(None, a)
- assert r == ['this', 'is', 'long', 'string', 'of', 'words']
-
- def testDropNumeric(self):
- text = '123 456 789 foobar without you nothing'
- a = Splitter(text)
- r = map(None, a)
- assert r == ['foobar', 'without', 'you', 'nothing'], r
-
- def testDropSingleLetterWords(self):
- text = 'without you I nothing'
- a = Splitter(text)
- r = map(None, a)
- assert r == ['without', 'you', 'nothing'], r
-
- def testSplitOnNonAlpha(self):
- text = 'without you I\'m nothing'
- a = Splitter(text)
- r = map(None, a)
- assert r == ['without', 'you', 'nothing'], r
-
+ def testSplitNormalText(self):
+ text = 'this is a long string of words'
+ a = Splitter(text)
+ r = map(None, a)
+ assert r == ['this', 'is', 'long', 'string', 'of', 'words']
+
+ def testDropNumeric(self):
+ text = '123 456 789 foobar without you nothing'
+ a = Splitter(text)
+ r = map(None, a)
+ assert r == ['foobar', 'without', 'you', 'nothing'], r
+
+ def testDropSingleLetterWords(self):
+ text = 'without you I nothing'
+ a = Splitter(text)
+ r = map(None, a)
+ assert r == ['without', 'you', 'nothing'], r
+
+ def testSplitOnNonAlpha(self):
+ text = 'without you I\'m nothing'
+ a = Splitter(text)
+ r = map(None, a)
+ assert r == ['without', 'you', 'nothing'], r
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
=== Zope/lib/python/SearchIndex/tests/testUnKeywordIndex.py 1.8 => 1.9 ===
--- Zope/lib/python/SearchIndex/tests/testUnKeywordIndex.py:1.8 Wed Jun 12 16:39:19 2002
+++ Zope/lib/python/SearchIndex/tests/testUnKeywordIndex.py Wed Aug 14 17:46:24 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
-#
+#
##############################################################################
import unittest
@@ -22,10 +22,10 @@
def foo( self ):
return self._foo
-
+
def __str__( self ):
return '<Dummy: %s>' % self._foo
-
+
__repr__ = __str__
class Tests( unittest.TestCase ):
@@ -45,7 +45,7 @@
, ( 4, Dummy( ['a', 'b', 'c', 'd'] ) )
, ( 5, Dummy( ['a', 'b', 'c', 'e'] ) )
, ( 6, Dummy( ['a', 'b', 'c', 'e', 'f'] ))
- , ( 7, Dummy( [0] ) )
+ , ( 7, Dummy( [0] ) )
]
self._noop_req = { 'bar': 123 }
self._all_req = { 'foo': ['a'] }
@@ -90,7 +90,7 @@
self._index.index_object(999, None)
finally:
zLOG.log_write=old_log_write
-
+
def testEmpty( self ):
assert len( self._index ) == 0
assert len( self._index.referencedObjects() ) == 0
@@ -109,7 +109,7 @@
self._checkApply( self._some_req, [] )
self._checkApply( self._overlap_req, [] )
self._checkApply( self._string_req, [] )
-
+
def testPopulated( self ):
self._populateIndex()
values = self._values
@@ -154,7 +154,7 @@
)
result = result.keys()
assert 6 not in result
-
+
def testReindexNoChange(self):
self._populateIndex()
expected = Dummy(['foo', 'bar'])
=== Zope/lib/python/SearchIndex/tests/testUnTextIndex.py 1.12 => 1.13 ===
--- Zope/lib/python/SearchIndex/tests/testUnTextIndex.py:1.12 Wed Jun 12 16:39:19 2002
+++ Zope/lib/python/SearchIndex/tests/testUnTextIndex.py Wed Aug 14 17:46:24 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
-#
+#
##############################################################################
import unittest
@@ -20,190 +20,190 @@
class Tests(unittest.TestCase):
- def setUp(self):
- self.index=SearchIndex.UnTextIndex.UnTextIndex('text')
- self.doc=Dummy(text='this is the time, when all good zopes')
- catch_log_errors()
-
- def dbopen(self):
- db = self.db = makeDB()
- self.jar=db.open()
- if not self.jar.root().has_key('index'):
- self.jar.root()['index']=SearchIndex.UnTextIndex.UnTextIndex('text')
- get_transaction().commit()
- return self.jar.root()['index']
-
- def dbclose(self):
- self.jar.close()
- self.db.close()
- del self.jar
- del self.db
-
- def tearDown(self):
- ignore_log_errors()
- get_transaction().abort()
- if hasattr(self, 'jar'):
- self.dbclose()
- cleanDB()
- self.__dict__.clear()
-
- def testSimpleAddDelete(self):
- "Test that we can add and delete an object without error"
- self.index.index_object(0, self.doc)
- self.index.index_object(1, self.doc)
- self.doc.text='spam is good, spam is fine, span span span'
- self.index.index_object(0, self.doc)
- self.index.unindex_object(0)
-
- def testPersistentUpdate1(self):
- "Test simple persistent indexing"
- index=self.dbopen()
-
- self.doc.text='this is the time, when all good zopes'
- index.index_object(0, self.doc)
- get_transaction().commit()
-
- self.doc.text='time waits for no one'
- index.index_object(1, self.doc)
- get_transaction().commit()
- self.dbclose()
-
- index=self.dbopen()
-
- r = index._apply_index({})
- assert r==None
-
- r = index._apply_index({'text': 'python'})
- assert len(r) == 2 and r[1]==('text',), 'incorrectly not used'
- assert not r[0], "should have no results"
-
- r = index._apply_index({'text': 'time'})
- r=list(r[0].keys())
- assert r == [0,1], r
-
- def testPersistentUpdate2(self):
- "Test less simple persistent indexing"
- index=self.dbopen()
-
- self.doc.text='this is the time, when all good zopes'
- index.index_object(0, self.doc)
- get_transaction().commit()
-
- self.doc.text='time waits for no one'
- index.index_object(1, self.doc)
- get_transaction().commit()
-
- self.doc.text='the next task is to test'
- index.index_object(3, self.doc)
- get_transaction().commit()
-
- self.doc.text='time time'
- index.index_object(2, self.doc)
- get_transaction().commit()
- self.dbclose()
-
- index=self.dbopen()
-
- r = index._apply_index({})
- assert r==None
-
- r = index._apply_index({'text': 'python'})
- assert len(r) == 2 and r[1]==('text',), 'incorrectly not used'
- assert not r[0], "should have no results"
-
- r = index._apply_index({'text': 'time'})
- r=list(r[0].keys())
- assert r == [0,1,2], r
-
-
-
- sample_texts = [
- """This is the time for all good men to come to
- the aid of their country""",
- """ask not what your country can do for you,
- ask what you can do for your country""",
- """Man, I can't wait to get to Montross!""",
- """Zope Public License (ZPL) Version 1.0""",
- """Copyright (c) Digital Creations. All rights reserved.""",
- """This license has been certified as Open Source(tm).""",
- """I hope I get to work on time""",
- ]
-
- def globTest(self, qmap, rlist):
- "Test a glob query"
- index = getattr(self, '_v_index', None)
- if index is None:
- index=self.dbopen()
- index._lexicon = SearchIndex.GlobbingLexicon.GlobbingLexicon()
-
- for i in range(len(self.sample_texts)):
- self.doc.text=self.sample_texts[i]
- index.index_object(i, self.doc)
- get_transaction().commit()
-
- self.dbclose()
-
- index = self._v_index = self.dbopen()
-
- r = list(index._apply_index(qmap)[0].keys())
- assert r == rlist, r
-
- def testStarQuery(self):
- "Test a star query"
- self.globTest({'text':'m*n'}, [0,2])
-
- def testAndQuery(self):
- "Test an AND query"
- self.globTest({'text':'time and country'}, [0,])
-
- def testOrQuery(self):
- "Test an OR query"
- self.globTest({'text':'time or country'}, [0,1,6])
-
- def testDefOrQuery(self):
- "Test a default OR query"
- self.globTest({'text':'time country'}, [0,1,6])
- self.globTest({'text':'time good country'}, [0,1,6])
-
- def testNearQuery(self):
- """Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)"""
- # NEAR never worked, so Zopes post-2.3.1b3 define near to mean AND
- self.globTest({'text':'time ... country'}, [0,])
-
- def testQuotesQuery(self):
- """Test a quoted query"""
- self.globTest({'text':'"This is the time"'}, [0,])
- self.globTest({'text':'"now is the time"'}, [])
-
- def testAndNotQuery(self):
- "Test an ANDNOT query"
- self.globTest({'text':'time and not country'}, [6,])
-
- def testParenMatchingQuery(self):
- "Test a query with parens"
- self.globTest({'text':'(time and country) men'}, [0,])
- self.globTest({'text':'(time and not country) or men'}, [0, 6])
-
- def testTextIndexOperatorQuery(self):
- "Test a query with 'textindex_operator' in the request"
- self.globTest({'text':'time men', 'textindex_operator':'and'}, [0,])
-
- def testNonExistentWord(self):
- """ Test for nonexistent word """
- self.globTest({'text':'zop'}, [])
-
- def testShortWord(self):
- """ Test for short word """
- self.globTest({'text':'to'}, [0, 2, 6])
- self.globTest({'text':'*to'}, [0, 2, 6])
- self.globTest({'text':'to*'}, [0, 2, 6])
- self.globTest({'text':'*to*'}, [0, 2, 6])
-
- def testComplexQuery1(self):
- """ Test complex query 1 """
- self.globTest({'text':'((?ount* or get) and not wait) '
- '"been *ert*"'}, [0, 1, 5, 6])
-
+ def setUp(self):
+ self.index=SearchIndex.UnTextIndex.UnTextIndex('text')
+ self.doc=Dummy(text='this is the time, when all good zopes')
+ catch_log_errors()
+
+ def dbopen(self):
+ db = self.db = makeDB()
+ self.jar=db.open()
+ if not self.jar.root().has_key('index'):
+ self.jar.root()['index']=SearchIndex.UnTextIndex.UnTextIndex('text')
+ get_transaction().commit()
+ return self.jar.root()['index']
+
+ def dbclose(self):
+ self.jar.close()
+ self.db.close()
+ del self.jar
+ del self.db
+
+ def tearDown(self):
+ ignore_log_errors()
+ get_transaction().abort()
+ if hasattr(self, 'jar'):
+ self.dbclose()
+ cleanDB()
+ self.__dict__.clear()
+
+ def testSimpleAddDelete(self):
+ "Test that we can add and delete an object without error"
+ self.index.index_object(0, self.doc)
+ self.index.index_object(1, self.doc)
+ self.doc.text='spam is good, spam is fine, span span span'
+ self.index.index_object(0, self.doc)
+ self.index.unindex_object(0)
+
+ def testPersistentUpdate1(self):
+ "Test simple persistent indexing"
+ index=self.dbopen()
+
+ self.doc.text='this is the time, when all good zopes'
+ index.index_object(0, self.doc)
+ get_transaction().commit()
+
+ self.doc.text='time waits for no one'
+ index.index_object(1, self.doc)
+ get_transaction().commit()
+ self.dbclose()
+
+ index=self.dbopen()
+
+ r = index._apply_index({})
+ assert r==None
+
+ r = index._apply_index({'text': 'python'})
+ assert len(r) == 2 and r[1]==('text',), 'incorrectly not used'
+ assert not r[0], "should have no results"
+
+ r = index._apply_index({'text': 'time'})
+ r=list(r[0].keys())
+ assert r == [0,1], r
+
+ def testPersistentUpdate2(self):
+ "Test less simple persistent indexing"
+ index=self.dbopen()
+
+ self.doc.text='this is the time, when all good zopes'
+ index.index_object(0, self.doc)
+ get_transaction().commit()
+
+ self.doc.text='time waits for no one'
+ index.index_object(1, self.doc)
+ get_transaction().commit()
+
+ self.doc.text='the next task is to test'
+ index.index_object(3, self.doc)
+ get_transaction().commit()
+
+ self.doc.text='time time'
+ index.index_object(2, self.doc)
+ get_transaction().commit()
+ self.dbclose()
+
+ index=self.dbopen()
+
+ r = index._apply_index({})
+ assert r==None
+
+ r = index._apply_index({'text': 'python'})
+ assert len(r) == 2 and r[1]==('text',), 'incorrectly not used'
+ assert not r[0], "should have no results"
+
+ r = index._apply_index({'text': 'time'})
+ r=list(r[0].keys())
+ assert r == [0,1,2], r
+
+
+
+ sample_texts = [
+ """This is the time for all good men to come to
+ the aid of their country""",
+ """ask not what your country can do for you,
+ ask what you can do for your country""",
+ """Man, I can't wait to get to Montross!""",
+ """Zope Public License (ZPL) Version 1.0""",
+ """Copyright (c) Digital Creations. All rights reserved.""",
+ """This license has been certified as Open Source(tm).""",
+ """I hope I get to work on time""",
+ ]
+
+ def globTest(self, qmap, rlist):
+ "Test a glob query"
+ index = getattr(self, '_v_index', None)
+ if index is None:
+ index=self.dbopen()
+ index._lexicon = SearchIndex.GlobbingLexicon.GlobbingLexicon()
+
+ for i in range(len(self.sample_texts)):
+ self.doc.text=self.sample_texts[i]
+ index.index_object(i, self.doc)
+ get_transaction().commit()
+
+ self.dbclose()
+
+ index = self._v_index = self.dbopen()
+
+ r = list(index._apply_index(qmap)[0].keys())
+ assert r == rlist, r
+
+ def testStarQuery(self):
+ "Test a star query"
+ self.globTest({'text':'m*n'}, [0,2])
+
+ def testAndQuery(self):
+ "Test an AND query"
+ self.globTest({'text':'time and country'}, [0,])
+
+ def testOrQuery(self):
+ "Test an OR query"
+ self.globTest({'text':'time or country'}, [0,1,6])
+
+ def testDefOrQuery(self):
+ "Test a default OR query"
+ self.globTest({'text':'time country'}, [0,1,6])
+ self.globTest({'text':'time good country'}, [0,1,6])
+
+ def testNearQuery(self):
+ """Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)"""
+ # NEAR never worked, so Zopes post-2.3.1b3 define near to mean AND
+ self.globTest({'text':'time ... country'}, [0,])
+
+ def testQuotesQuery(self):
+ """Test a quoted query"""
+ self.globTest({'text':'"This is the time"'}, [0,])
+ self.globTest({'text':'"now is the time"'}, [])
+
+ def testAndNotQuery(self):
+ "Test an ANDNOT query"
+ self.globTest({'text':'time and not country'}, [6,])
+
+ def testParenMatchingQuery(self):
+ "Test a query with parens"
+ self.globTest({'text':'(time and country) men'}, [0,])
+ self.globTest({'text':'(time and not country) or men'}, [0, 6])
+
+ def testTextIndexOperatorQuery(self):
+ "Test a query with 'textindex_operator' in the request"
+ self.globTest({'text':'time men', 'textindex_operator':'and'}, [0,])
+
+ def testNonExistentWord(self):
+ """ Test for nonexistent word """
+ self.globTest({'text':'zop'}, [])
+
+ def testShortWord(self):
+ """ Test for short word """
+ self.globTest({'text':'to'}, [0, 2, 6])
+ self.globTest({'text':'*to'}, [0, 2, 6])
+ self.globTest({'text':'to*'}, [0, 2, 6])
+ self.globTest({'text':'*to*'}, [0, 2, 6])
+
+ def testComplexQuery1(self):
+ """ Test complex query 1 """
+ self.globTest({'text':'((?ount* or get) and not wait) '
+ '"been *ert*"'}, [0, 1, 5, 6])
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
=== Zope/lib/python/SearchIndex/tests/test_UnIndex.py 1.7 => 1.8 ===
--- Zope/lib/python/SearchIndex/tests/test_UnIndex.py:1.7 Wed Jun 12 16:39:19 2002
+++ Zope/lib/python/SearchIndex/tests/test_UnIndex.py Wed Aug 14 17:46:24 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
-#
+#
##############################################################################
import unittest
@@ -23,10 +23,10 @@
def foo( self ):
return self._foo
-
+
def __str__( self ):
return '<Dummy: %s>' % self._foo
-
+
__repr__ = __str__
class Tests( unittest.TestCase ):
@@ -54,7 +54,7 @@
self._backward[k] = v
keys = self._forward.get( v, [] )
self._forward[v] = keys
-
+
self._noop_req = { 'bar': 123 }
self._request = { 'foo': 'abce' }
self._min_req = { 'foo': 'abc'
@@ -77,7 +77,7 @@
def _populateIndex( self ):
for k, v in self._values:
self._index.index_object( k, v )
-
+
def _checkApply( self, req, expectedValues ):
result, used = self._index._apply_index( req )
if hasattr(result, 'keys'):
@@ -87,7 +87,7 @@
'%s | %s' % ( map( None, result ), expectedValues )
for k, v in expectedValues:
assert k in result
-
+
def testEmpty( self ):
"Test an empty FieldIndex."
@@ -108,7 +108,7 @@
self._checkApply( self._min_req, [] )
self._checkApply( self._max_req, [] )
self._checkApply( self._range_req, [] )
-
+
def testPopulated( self ):
""" Test a populated FieldIndex """
self._populateIndex()
@@ -166,10 +166,10 @@
40, 41, 42, 43, 50, 51, 52, 53, 60, 61, 62, 63, 70, 71, 72, 73,
80, 81, 82, 83, 90, 91, 92, 93
]
-
- assert r==expect, r
-
-
+
+ assert r==expect, r
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),