[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/KeywordIndex/tests - __init__.py:1.2.4.1 testKeywordIndex.py:1.5.6.1

Casey Duncan casey@zope.com
Fri, 28 Feb 2003 10:58:19 -0500


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

Modified Files:
      Tag: Zope-2_6-branch
	testKeywordIndex.py 
Added Files:
      Tag: Zope-2_6-branch
	__init__.py 
Log Message:
Backport keyindex unique value fix (issue #828)


=== Added File Zope/lib/python/Products/PluginIndexes/KeywordIndex/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################

# This file is needed to make this a package.


=== Zope/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py 1.5 => 1.5.6.1 ===
--- Zope/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py:1.5	Wed Aug 14 18:19:30 2002
+++ Zope/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py	Fri Feb 28 10:58:19 2003
@@ -27,7 +27,15 @@
 
     __repr__ = __str__
 
-class TestCase( unittest.TestCase ):
+def sortedUnique(seq):
+    unique = {}
+    for i in seq:
+        unique[i] = None
+    unique = unique.keys()
+    unique.sort()
+    return unique
+
+class TestKeywordIndex( unittest.TestCase ):
     """
         Test KeywordIndex objects.
     """
@@ -41,7 +49,7 @@
         self._values = [ ( 0, Dummy( ['a'] ) )
                        , ( 1, Dummy( ['a','b'] ) )
                        , ( 2, Dummy( ['a','b','c'] ) )
-                       , ( 3, Dummy( ['a','b','c', 'a'] ) )
+                       , ( 3, Dummy( ['a','b','c','a'] ) )
                        , ( 4, Dummy( ['a', 'b', 'c', 'd'] ) )
                        , ( 5, Dummy( ['a', 'b', 'c', 'e'] ) )
                        , ( 6, Dummy( ['a', 'b', 'c', 'e', 'f'] ))
@@ -135,7 +143,10 @@
         self._index.unindex_object( 1234 ) # nothrow
 
         for k, v in values:
-            assert self._index.getEntryForObject( k ) == v.foo()
+            entry = self._index.getEntryForObject( k )
+            entry.sort()
+            kw = sortedUnique(v.foo())
+            self.assertEqual(entry, kw)
 
         assert (len( self._index.uniqueValues( 'foo' ) ) == len( values )-1,
                 len(values)-1)
@@ -184,7 +195,7 @@
         assert result[0] == 8
 
     def testIntersectionWithRange(self):
-        """Test an 'and' search, ensuring that 'range' doesn't mess it up."""
+        # Test an 'and' search, ensuring that 'range' doesn't mess it up.
         self._populateIndex()
 
         record = { 'foo' : { 'query'  : [ 'e', 'f' ]
@@ -199,6 +210,23 @@
         #
         record[ 'foo' ][ 'range' ] = 'min:max'
         self._checkApply( record, self._values[6:7] )
+        
+    def testDuplicateKeywords(self):
+        self._catch_log_errors()
+        try:
+            self._index.index_object(0, Dummy(['a', 'a', 'b', 'b']))
+            self._index.unindex_object(0)
+        finally:
+            self._ignore_log_errors()
 
 def test_suite():
-    return unittest.makeSuite( TestCase )
+    suite = unittest.TestSuite()
+    suite.addTest( unittest.makeSuite( TestKeywordIndex ) )
+    return suite
+    
+def main():
+    unittest.main(defaultTest='test_suite')
+
+if __name__ == '__main__':
+    main()
+