[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex/tests - testTextIndex.py:1.5.16.3

Shane Hathaway shane@cvs.zope.org
Thu, 12 Sep 2002 12:15:22 -0400


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv28169

Modified Files:
      Tag: Zope-2_5-branch
	testTextIndex.py 
Log Message:
Merged from the head: Cleaned up the TextIndex tests.

- Used a MappingStorage instead of a FileStorage, to avoid writing to disk.

- Removed unnecessary docstrings and converted useful docstrings to comments
to clean up the unit test output.

- Updated to use unittest.main().


=== Zope/lib/python/Products/PluginIndexes/TextIndex/tests/testTextIndex.py 1.5.16.2 => 1.5.16.3 === (427/527 lines abridged)
--- Zope/lib/python/Products/PluginIndexes/TextIndex/tests/testTextIndex.py:1.5.16.2	Thu Feb 28 08:46:31 2002
+++ Zope/lib/python/Products/PluginIndexes/TextIndex/tests/testTextIndex.py	Thu Sep 12 12:15:22 2002
@@ -1,18 +1,17 @@
 ##############################################################################
 #
 # 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 sys, os, unittest
-from glob import glob
 import zLOG
 
 def log_write(subsystem, severity, summary, detail, error):
@@ -20,7 +19,8 @@
         assert 0, "%s(%s): %s" % (subsystem, severity, summary)
 
 
-import ZODB, ZODB.DemoStorage, ZODB.FileStorage
+import ZODB
+from ZODB.MappingStorage import MappingStorage
 from Products.PluginIndexes.TextIndex import TextIndex
 from Products.PluginIndexes.TextIndex import GlobbingLexicon
 
@@ -31,267 +31,240 @@
 
     def text( self ):
         return self._text
-    
+
     def __str__( self ):
         return '<Dummy: %s>' % self._text
-    
+
     __repr__ = __str__
 
+
 class Tests(unittest.TestCase):
 
-   def setUp(self):
-       self.index=TextIndex.TextIndex('text')

[-=- -=- -=- 427 lines omitted -=- -=- -=-]

+    # same tests, unicode strings
+    def checkStarQueryUnicode(self):
+        self.globTest({'text':u'm*n'}, [0,2])
+
+    def checkAndQueryUnicode(self):
+        self.globTest({'text':u'time and country'}, [0,])
+
+    def checkOrQueryUnicode(self):
+        self.globTest({'text':u'time or country'}, [0,1,6])
+
+    def checkDefaultOrQueryUnicode(self):
+        self.globTest({'text':u'time country'}, [0,1,6])
+
+    def checkNearQueryUnicode(self):
+        # Check a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!) (unicode)
+        # NEAR never worked, so Zopes post-2.3.1b3 define near to mean AND
+        self.globTest({'text':u'time ... country'}, [0,])
+
+    def checkQuotesQueryUnicode(self):
+        ai = self.globTest({'text':u'"This is the time"'}, [0,])
+
+        r = list(ai({'text':'"now is the time"'})[0].keys())
+        assert  r == [], r
+
+    def checkAndNotQueryUnicode(self):
+        self.globTest({'text':u'time and not country'}, [6,])
+
+    def checkParenMatchingQueryUnicode(self):
+        ai = self.globTest({'text':u'(time and country) men'}, [0,])
+
+        r = list(ai({'text':u'(time and not country) or men'})[0].keys())
+        assert  r == [0, 6], r
+
+    def checkTextIndexOperatorQueryUnicode(self):
+        self.globTest({'text': {u'query': u'time men', 'operator':'and'}},
+                      [0,])
+
+    def checkNonExistentWordUnicode(self):
+        self.globTest({'text':u'zop'}, [])
+
+    def checkComplexQuery1Unicode(self):
+        self.globTest({'text':u'((?ount* or get) and not wait) '
+                       '"been *ert*"'}, [0, 1, 5, 6])
+
+
+def test_suite():
+    return unittest.makeSuite(Tests, 'check')
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')