Commit a177f5a4 authored by Jérome Perrin's avatar Jérome Perrin

testDynamicClassGeneration: more py3 fixes

parent 963f23dd
......@@ -2358,17 +2358,21 @@ _ = ZBigArray
module2_with_version=imported_module2_with_version)) +
component.getTextContent())
must_be_in_cache_set = set()
if six.PY2:
must_be_in_cache_set.add(namespace)
self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace},
must_be_in_cache_set=must_be_in_cache_set,
must_not_be_in_cache_set={'%s.erp5_version' % namespace,
imported_module1,
imported_module1_with_version,
imported_module2,
imported_module2_with_version})
component.checkSourceCode()
if six.PY2:
must_be_in_cache_set.add('%s.erp5_version' % namespace)
self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace,
'%s.erp5_version' % namespace},
must_be_in_cache_set=must_be_in_cache_set,
must_not_be_in_cache_set={imported_module1,
imported_module1_with_version,
imported_module2,
......@@ -2469,7 +2473,7 @@ _ = ZBigArray
self.tic()
must_be_in_cache_set = set()
if six.PY2:
must_be_in_cache_set.add(str(namespace))
must_be_in_cache_set.add(namespace)
self._assertAstroidCacheContent(
must_be_in_cache_set=must_be_in_cache_set,
must_not_be_in_cache_set={'%s.erp5_version' % namespace,
......@@ -2760,7 +2764,7 @@ def foobar(self, a, b="portal_type"):
external_method.manage_setGuard({'guard_roles': 'Member'})
self.assertEqual(self.portal.TestPythonScript(a='portal_ids'), 'Id Tool')
self.assertEqual(self.publish(base + '/portal_types/TestExternalMethod?'
'a=Types Tool&b=type_class', 'ERP5TypeTestCase:').getBody(), 'TypesTool')
'a=Types Tool&b=type_class', 'ERP5TypeTestCase:').getBody(), b'TypesTool')
sm = getSecurityManager()
try:
......@@ -2785,7 +2789,7 @@ def foobar(self, a, b="portal_type"):
cfg.extensions = tempfile.mkdtemp()
try:
with open(os.path.join(cfg.extensions, module + '.py'), "w") as f:
f.write("foobar = lambda **kw: sorted(kw.iteritems())")
f.write("foobar = lambda **kw: sorted(kw.items())")
self.assertEqual(external_method(z=1, a=0), [('a', 0), ('z', 1)])
finally:
shutil.rmtree(cfg.extensions)
......@@ -2999,7 +3003,7 @@ from erp5.component.document.Person import Person
from ITestPortalType import ITestPortalType
import zope.interface
zope.interface.implementer(ITestPortalType)
@zope.interface.implementer(ITestPortalType)
class TestPortalType(Person):
def test42(self):
return 42
......@@ -3234,13 +3238,11 @@ class Test(ERP5TypeTestCase):
"""
Dummy mail host has already been set up when running tests
"""
pass
def _restoreMailHost(self):
"""
Dummy mail host has already been set up when running tests
"""
pass
def test_01_sampleTest(self):
self.assertEqual(0, 0)
......@@ -3336,7 +3338,7 @@ class Test(ERP5TypeTestCase):
reset_portal_type_at_transaction_boundary=True)
output = runLiveTest('testRunLiveTest')
expected_msg_re = re.compile('Ran 2 tests.*FAILED \(failures=1\)', re.DOTALL)
expected_msg_re = re.compile(r'Ran 2 tests.*FAILED \(failures=1\)', re.DOTALL)
self.assertRegex(output, expected_msg_re)
# Now try addCleanup
......@@ -3412,18 +3414,29 @@ break_at_import()
return self._component_tool.readTestOutput()
output = runLiveTest('testRunLiveTestImportError')
self.assertIn('''
if six.PY2:
expected_output = '''
File "<portal_components/test.erp5.testRunLiveTestImportError>", line 4, in <module>
break_at_import()
File "<portal_components/test.erp5.testRunLiveTestImportError>", line 3, in break_at_import
import non.existing.module # pylint:disable=import-error
ImportError: No module named non.existing.module
''', output)
'''
else:
expected_output = '''
File "<portal_components/test.erp5.testRunLiveTestImportError>", line 4, in <module>
break_at_import()
File "<portal_components/test.erp5.testRunLiveTestImportError>", line 3, in break_at_import
import non.existing.module # pylint:disable=import-error
ModuleNotFoundError: No module named 'non'
'''
self.assertIn(expected_output, output)
output = runLiveTest('testDoesNotExist_import_error_because_module_does_not_exist')
self.assertIn(
"ImportError: No module named testDoesNotExist_import_error_because_module_does_not_exist",
output)
if six.PY2:
expected_output = "ImportError: No module named testDoesNotExist_import_error_because_module_does_not_exist"
else:
expected_output = "ModuleNotFoundError: No module named 'testDoesNotExist_import_error_because_module_does_not_exist'"
self.assertIn(expected_output, output)
def testERP5Broken(self):
# Create a broken ghost object
......@@ -3661,6 +3674,8 @@ class TestZodbDocumentComponentReload(ERP5TypeTestCase):
component = self.portal.portal_components['document.erp5.BusinessProcess']
component.setTextContent(value)
self.tic()
self.assertEqual(component.checkConsistency(), [])
self.assertEqual(component.getValidationState(), 'validated')
def testAsComposedDocumentCacheIsCorrectlyFlushed(self):
component = self.portal.portal_components['document.erp5.BusinessProcess']
......
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