Commit 86e586b2 authored by Jérome Perrin's avatar Jérome Perrin

testDynamicClassGeneration WIP

parent aa1a099b
...@@ -1907,11 +1907,18 @@ class TestZodbModuleComponent(SecurityTestCase): ...@@ -1907,11 +1907,18 @@ class TestZodbModuleComponent(SecurityTestCase):
component.setTextContent("""import unexistent_module component.setTextContent("""import unexistent_module
""" + valid_code) """ + valid_code)
self.tic() self.tic()
self.assertEqual( if six.PY2:
[m.getMessage().translate() for m in component.checkConsistency()], self.assertEqual(
["Error in Source Code: F: 1, 0: Unable to import 'unexistent_module' (import-error)"]) [m.getMessage().translate() for m in component.checkConsistency()],
self.assertEqual(component.getTextContentErrorMessageList(), ["Error in Source Code: F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
["F: 1, 0: Unable to import 'unexistent_module' (import-error)"]) self.assertEqual(component.getTextContentErrorMessageList(),
["F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
else:
self.assertEqual(
[m.getMessage().translate() for m in component.checkConsistency()],
["Error in Source Code: E: 1, 0: Unable to import 'unexistent_module' (import-error)"])
self.assertEqual(component.getTextContentErrorMessageList(),
["E: 1, 0: Unable to import 'unexistent_module' (import-error)"])
self.assertEqual(component.getTextContentWarningMessageList(), self.assertEqual(component.getTextContentWarningMessageList(),
["W: 1, 0: Unused import unexistent_module (unused-import)"]) ["W: 1, 0: Unused import unexistent_module (unused-import)"])
...@@ -2685,7 +2692,7 @@ foobar = foobar().f ...@@ -2685,7 +2692,7 @@ foobar = foobar().f
base = self.portal.getPath() base = self.portal.getPath()
for query in 'x:int=-24&y:int=66', 'x:int=41': for query in 'x:int=-24&y:int=66', 'x:int=41':
path = '%s/TestExternalMethod?%s' % (base, query) path = '%s/TestExternalMethod?%s' % (base, query)
self.assertEqual(self.publish(path).getBody(), '42') self.assertEqual(self.publish(path).getBody(), b'42')
# Test from a Python Script # Test from a Python Script
createZODBPythonScript(self.portal.portal_skins.custom, createZODBPythonScript(self.portal.portal_skins.custom,
...@@ -2819,8 +2826,8 @@ class TestWithImport(TestImported): ...@@ -2819,8 +2826,8 @@ class TestWithImport(TestImported):
from ITestGC import ITestGC from ITestGC import ITestGC
import zope.interface import zope.interface
@zope.interface.implementer(ITestGC)
class TestGC(XMLObject): class TestGC(XMLObject):
zope.interface.implements(ITestGC)
def foo(self): def foo(self):
pass pass
""") """)
...@@ -2851,12 +2858,15 @@ class TestGC(XMLObject): ...@@ -2851,12 +2858,15 @@ class TestGC(XMLObject):
self.assertEqual(gc.garbage, []) self.assertEqual(gc.garbage, [])
import erp5.component import erp5.component
gc.set_debug( debug_flags = (
gc.DEBUG_STATS | gc.DEBUG_STATS
gc.DEBUG_UNCOLLECTABLE | | gc.DEBUG_UNCOLLECTABLE
gc.DEBUG_COLLECTABLE | | gc.DEBUG_COLLECTABLE )
gc.DEBUG_OBJECTS | if six.PY2:
gc.DEBUG_INSTANCES) debug_flags |= (
gc.DEBUG_OBJECTS
| gc.DEBUG_INSTANCES)
gc.set_debug(debug_flags)
sys.stderr = stderr sys.stderr = stderr
# Still not garbage collectable as RefManager still keeps a reference # Still not garbage collectable as RefManager still keeps a reference
erp5.component.ref_manager.clear() erp5.component.ref_manager.clear()
...@@ -2939,11 +2949,11 @@ from erp5.component.document.Person import Person ...@@ -2939,11 +2949,11 @@ from erp5.component.document.Person import Person
from ITestPortalType import ITestPortalType from ITestPortalType import ITestPortalType
import zope.interface import zope.interface
zope.interface.implementer(ITestPortalType)
class TestPortalType(Person): class TestPortalType(Person):
def test42(self): def test42(self):
return 42 return 42
zope.interface.implements(ITestPortalType)
def foo(self): def foo(self):
pass pass
""") """)
...@@ -3135,7 +3145,7 @@ InitializeClass(%(class_name)s) ...@@ -3135,7 +3145,7 @@ InitializeClass(%(class_name)s)
'%s/manage_addProduct/ERP5/manage_addToolForm' % self.portal.getPath(), '%s/manage_addProduct/ERP5/manage_addToolForm' % self.portal.getPath(),
'ERP5TypeTestCase:') 'ERP5TypeTestCase:')
self.assertEqual(response.getStatus(), 200) self.assertEqual(response.getStatus(), 200)
self.assertNotIn('ERP5 Test Hook After Load Tool', response.getBody()) self.assertNotIn(b'ERP5 Test Hook After Load Tool', response.getBody())
component.validate() component.validate()
self.tic() self.tic()
...@@ -3147,7 +3157,7 @@ InitializeClass(%(class_name)s) ...@@ -3147,7 +3157,7 @@ InitializeClass(%(class_name)s)
'%s/manage_addProduct/ERP5/manage_addToolForm' % self.portal.getPath(), '%s/manage_addProduct/ERP5/manage_addToolForm' % self.portal.getPath(),
'ERP5TypeTestCase:') 'ERP5TypeTestCase:')
self.assertEqual(response.getStatus(), 200) self.assertEqual(response.getStatus(), 200)
self.assertIn('ERP5 Test Hook After Load Tool', response.getBody()) self.assertIn(b'ERP5 Test Hook After Load Tool', response.getBody())
from Products.ERP5Type.Core.TestComponent import TestComponent from Products.ERP5Type.Core.TestComponent import TestComponent
...@@ -3371,9 +3381,9 @@ ImportError: No module named non.existing.module ...@@ -3371,9 +3381,9 @@ ImportError: No module named non.existing.module
name = self._testMethodName name = self._testMethodName
types_tool = self.portal.portal_types types_tool = self.portal.portal_types
ptype = types_tool.newContent(name, type_class="File", portal_type='Base Type') ptype = types_tool.newContent(name, type_class="File", portal_type='Base Type')
file = ptype.constructInstance(self.portal, name, data="foo") file = ptype.constructInstance(self.portal, name, data=b"foo")
file_uid = file.getUid() file_uid = file.getUid()
self.assertEqual(file.size, len("foo")) self.assertEqual(file.size, len(b"foo"))
self.commit() self.commit()
try: try:
self.portal._p_jar.cacheMinimize() self.portal._p_jar.cacheMinimize()
...@@ -3389,7 +3399,7 @@ ImportError: No module named non.existing.module ...@@ -3389,7 +3399,7 @@ ImportError: No module named non.existing.module
# Check that the class is unghosted before resolving __setattr__ # Check that the class is unghosted before resolving __setattr__
self.assertRaises(BrokenModified, setattr, file, "size", 0) self.assertRaises(BrokenModified, setattr, file, "size", 0)
self.assertIsInstance(file, ERP5BaseBroken) self.assertIsInstance(file, ERP5BaseBroken)
self.assertEqual(file.size, len("foo")) self.assertEqual(file.size, len(b"foo"))
# Now if we repair the portal type definition, instances will # Now if we repair the portal type definition, instances will
# no longer be broken and be modifiable again. # no longer be broken and be modifiable again.
...@@ -3399,9 +3409,9 @@ ImportError: No module named non.existing.module ...@@ -3399,9 +3409,9 @@ ImportError: No module named non.existing.module
file = self.portal[name] file = self.portal[name]
self.assertNotIsInstance(file, ERP5BaseBroken) self.assertNotIsInstance(file, ERP5BaseBroken)
self.assertEqual(file.getUid(), file_uid) self.assertEqual(file.getUid(), file_uid)
self.assertEqual(file.getData(), "foo") self.assertEqual(file.getData(), b"foo")
file.setData("something else") file.setData(b"something else")
self.assertEqual(file.getData(), "something else") self.assertEqual(file.getData(), b"something else")
self.assertNotIn("__Broken_state__", file.__dict__) self.assertNotIn("__Broken_state__", file.__dict__)
finally: finally:
self.portal._delObject(name) self.portal._delObject(name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment