[Erp5-report] r38633 jm - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Sep 24 18:06:22 CEST 2010


Author: jm
Date: Fri Sep 24 18:06:22 2010
New Revision: 38633

URL: http://svn.erp5.org?rev=38633&view=rev
Log:
BusinessTemplate: remove dead code

This reverts most fixes to r28422. They are not useful anymore since objects
are not modified anymore during download.

Modified:
    erp5/trunk/products/ERP5/Document/BusinessTemplate.py
    erp5/trunk/products/ERP5/tests/testBusinessTemplate.py

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=38633&r1=38632&r2=38633&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Fri Sep 24 18:06:22 2010
@@ -4852,42 +4852,22 @@ Business Template is a set of definition
 
       # Create temporary modules/classes for classes defined by this BT.
       # This is required if the BT contains instances of one of these classes.
-      orig_module_dict = {}
-      instance_oid_list = []
+      module_id_list = []
       for template_id in self.getTemplateDocumentIdList():
-          module_id = 'Products.ERP5Type.Document.' + template_id
-          orig_module_dict[module_id] = sys.modules.get(module_id)
-          # Always redefine the module, so that 'instance_oid_list' contains
-          # the full list of oid to remove from pickle cache.
+        module_id = 'Products.ERP5Type.Document.' + template_id
+        if module_id not in sys.modules:
+          module_id_list.append(module_id)
           sys.modules[module_id] = module = imp.new_module(module_id)
-          module.SimpleItem = SimpleItem.SimpleItem
-          module.instance_oid_list = instance_oid_list
-          exec """class %s(SimpleItem):
-            def __setstate__(self, state):
-              instance_oid_list.append(self._p_oid)
-              return SimpleItem.__setstate__(self, state)""" % template_id \
-            in module.__dict__
+          setattr(module, template_id, type(template_id,
+            (SimpleItem.SimpleItem,), {'__module__': module_id}))
 
       for item_name in self._item_name_list:
         getattr(self, item_name).importFile(bta)
 
-      if instance_oid_list:
-        # If a temporary class was used, we must force all instances using it
-        # to be reloaded (i.e. unpickle) on next access (at installation).
-        # Doing a savepoint will pickle them to a temporary storage so that all
-        # references to it can be freed.
-        transaction.savepoint(optimistic=True)
-        self._p_jar.cacheMinimize()
-        gc.collect()
-
       # Remove temporary modules created above to allow import of real modules
       # (during the installation).
-      # Restore original module if any, in case the new one is not installed.
-      for module_id, module in orig_module_dict.iteritems():
-        if module is None:
-          del sys.modules[module_id]
-        else:
-          sys.modules[module_id] = module
+      for module_id in module_id_list:
+        del sys.modules[module_id]
 
     def getItemsList(self):
       """Return list of items in business template

Modified: erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBusinessTemplate.py?rev=38633&r1=38632&r2=38633&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] Fri Sep 24 18:06:22 2010
@@ -6630,12 +6630,15 @@ class TestBusinessTemplate(ERP5TypeTestC
     sequence_list.play(self, quiet=quiet)
 
   def test_167_InstanceAndRelatedClassDefinedInSameBT(self):
+    # This test does too much since we don't modify objects anymore during
+    # download. Objects are cleaned up during installation, which does not
+    # require any specific action about garbage collection or pickle cache.
     from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem
     portal = self.portal
     BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties
     marker_list = []
     def removeProperties(self, obj, export):
-      # Check it works if the object is modified during download.
+      # Check it works if the object is modified during install.
       obj.int_index = marker_list.pop()
       return obj
     SimpleItem_getCopy = SimpleItem._getCopy
@@ -6655,15 +6658,16 @@ class TestBusinessTemplate(ERP5TypeTestC
       del self.logged[:]
       # check its class has not yet been overriden
       self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False))
-      for i in xrange(6):
+      for i in (0, 1):
         marker_list.append(i)
         gc.disable()
         bt = template_tool.download(bt_path)
-        assert not marker_list
-        if i in (2, 4, 5):
+        assert marker_list
+        if i:
           transaction.commit()
           self.tic()
         bt.install(force=1)
+        assert not marker_list
         gc.enable()
         self.assertEqual(portal.some_file.int_index, i)
         transaction.commit()




More information about the Erp5-report mailing list