[Checkins] SVN: Products.GenericSetup/trunk/ Forward-port fix for ZCTextIndex from 1.6 branch.

Tres Seaver cvs-admin at zope.org
Tue Feb 5 14:19:08 UTC 2013


Log message for revision 129133:
  Forward-port fix for ZCTextIndex from 1.6 branch.

Changed:
  _U  Products.GenericSetup/trunk/
  U   Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/exportimport.py
  U   Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/tests/test_exportimport.py

-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/exportimport.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/exportimport.py	2013-02-05 14:17:23 UTC (rev 129132)
+++ Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/exportimport.py	2013-02-05 14:19:08 UTC (rev 129133)
@@ -55,11 +55,13 @@
                       child.getAttribute('group').encode('utf-8'),
                       child.getAttribute('name').encode('utf-8'))
                 pipeline.append(element)
-        self.context._pipeline = tuple(pipeline)
-        #clear lexicon
-        self.context._wids = OIBTree()
-        self.context._words = IOBTree()
-        self.context.length = Length()
+        pipeline = tuple(pipeline)
+        if self.context._pipeline != pipeline:
+            self.context._pipeline = pipeline
+            #clear lexicon
+            self.context._wids = OIBTree()
+            self.context._words = IOBTree()
+            self.context.length = Length()
 
     node = property(_exportNode, _importNode)
 
@@ -107,7 +109,8 @@
             if child.nodeName == 'indexed_attr':
                 indexed_attrs.append(
                                   child.getAttribute('value').encode('utf-8'))
-        self.context._indexed_attrs = indexed_attrs
-        self.context.clear()
+        if self.context._indexed_attrs != indexed_attrs:
+            self.context._indexed_attrs = indexed_attrs
+            self.context.clear()
 
     node = property(_exportNode, _importNode)

Modified: Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/tests/test_exportimport.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/tests/test_exportimport.py	2013-02-05 14:17:23 UTC (rev 129132)
+++ Products.GenericSetup/trunk/Products/GenericSetup/ZCTextIndex/tests/test_exportimport.py	2013-02-05 14:19:08 UTC (rev 129133)
@@ -99,8 +99,73 @@
         self._XML = _ZCTEXT_XML
 
 
+class UnchangedTests(unittest.TestCase):
+
+    layer = ExportImportZCMLLayer
+
+    def test_ZCLexicon(self):
+        from xml.dom.minidom import parseString
+        from Products.GenericSetup.testing import DummySetupEnviron
+        from Products.ZCTextIndex.PipelineFactory import element_factory
+        from Products.GenericSetup.ZCTextIndex.exportimport \
+                import ZCLexiconNodeAdapter
+
+        _XML = """\
+        <object name="foo_plexicon" meta_type="ZCTextIndex Lexicon">
+        <element name="foo" group="gs"/>
+        <element name="bar" group="gs"/>
+        </object>
+        """
+        environ = DummySetupEnviron()
+        _before = object(), object(), object()
+        class DummyLexicon(object):
+            _wids, _words, length = _before
+        lex = DummyLexicon()
+        lex._pipeline = foo, bar = object(), object()
+        adapted = ZCLexiconNodeAdapter(lex, environ)
+        element_factory._groups['gs'] = {'foo': lambda: foo,
+                                         'bar': lambda: bar,
+                                        }
+        try:
+            adapted.node = parseString(_XML).documentElement # no raise
+        finally:
+            del element_factory._groups['gs']
+        self.assertTrue(lex._wids is _before[0])
+        self.assertTrue(lex._words is _before[1])
+        self.assertTrue(lex.length is _before[2])
+
+    def test_ZCTextIndex(self):
+        from xml.dom.minidom import parseString
+        from Products.ZCTextIndex.ZCTextIndex import PLexicon
+        from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
+        from Products.GenericSetup.testing import DummySetupEnviron
+        from Products.GenericSetup.ZCTextIndex.exportimport \
+                import ZCTextIndexNodeAdapter
+        _XML = """\
+        <index name="foo_zctext" meta_type="ZCTextIndex">
+        <indexed_attr value="bar"/>
+        <extra name="index_type" value="Okapi BM25 Rank"/>
+        <extra name="lexicon_id" value="foo_plexicon"/>
+        </index>
+        """
+        environ = DummySetupEnviron()
+        def _no_clear(*a):
+            raise AssertionError("Don't clear me!")
+        catalog = DummyCatalog()
+        catalog.foo_plexicon = PLexicon('foo_plexicon')
+        extra = _extra()
+        extra.lexicon_id = 'foo_plexicon'
+        extra.index_type='Okapi BM25 Rank'
+        index = ZCTextIndex('foo_field', extra=extra, field_name='bar',
+                            caller=catalog).__of__(catalog)
+        index.clear = _no_clear 
+        adapted = ZCTextIndexNodeAdapter(index, environ)
+        adapted.node = parseString(_XML).documentElement # no raise
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(ZCLexiconNodeAdapterTests),
         unittest.makeSuite(ZCTextIndexNodeAdapterTests),
-        ))
+        unittest.makeSuite(UnchangedTests),
+    ))



More information about the checkins mailing list