Commit 0a6ff11b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: change fromlist for __import__() in Python 3.

parent 8980514d
......@@ -27,6 +27,7 @@
##############################################################################
from zope.interface.verify import verifyClass
import six
import unittest
implements_tuple_list = [
......@@ -59,7 +60,7 @@ def makeTestMethod(import_tuple, interface):
"""Common method which checks if documents implements interface"""
def testMethod(self):
Klass = getattr(
__import__(import_tuple[0], globals(), locals(), [import_tuple[0]]),
__import__(import_tuple[0], globals(), locals(), [import_tuple[0]] if six.PY2 else ['erp5']),
import_tuple[1])
import Products.ERP5Type.interfaces
......@@ -68,7 +69,7 @@ def makeTestMethod(import_tuple, interface):
except AttributeError:
InterfaceModuleName = 'erp5.component.interface.%s' % interface
Interface = getattr(
__import__(InterfaceModuleName, globals(), locals(), [InterfaceModuleName]),
__import__(InterfaceModuleName, globals(), locals(), [InterfaceModuleName] if six.PY2 else ['erp5']),
interface)
verifyClass(Interface, Klass)
......
......@@ -30,6 +30,7 @@ from Acquisition import aq_base, aq_parent
from zLOG import LOG, INFO, ERROR
from io import BytesIO
from Products.ERP5Type import Permissions
import six
security = ClassSecurityInfo()
DA.security = security
......@@ -279,7 +280,7 @@ def getObjectMeta(original_function):
# imported, which is enough to use a ZODB Extension as a brain.
try:
m = __import__('erp5.component.extension.%s' % module, globals(),
{}, 'erp5.component.extension')
{}, ['erp5.component.extension'] if six.PY2 else ['erp5'])
o = getattr(m, name, None)
if o is None:
......
......@@ -300,7 +300,7 @@ class ERP5TypeTestLoader(unittest.TestLoader):
def _importZodbTestComponent(self, name):
import erp5.component.test
module = __import__('erp5.component.test.' + name,
fromlist=['erp5.component.test'],
fromlist=['erp5.component.test'] if six.PY2 else ['erp5'],
level=0)
try:
self._test_component_ref_list.append(module)
......
......@@ -1454,7 +1454,7 @@ class TestZodbModuleComponent(SecurityTestCase):
def afterSetUp(self):
self._component_tool = self.portal.portal_components
self._module = __import__(self._document_class._getDynamicModuleNamespace(),
fromlist=['erp5.component'])
fromlist=['erp5.component'] if six.PY2 else ['erp5'])
self._component_tool.reset(force=True,
reset_portal_type_at_transaction_boundary=True)
......@@ -1524,7 +1524,10 @@ class TestZodbModuleComponent(SecurityTestCase):
if expected_default_version is not None:
top_module_name = self._document_class._getDynamicModuleNamespace()
top_module = __import__(top_module_name, level=0, fromlist=[top_module_name])
top_module = __import__(
top_module_name,
level=0,
fromlist=[top_module_name] if six.PY2 else ['erp5'])
# The module must be available in its default version
self.assertHasAttribute(top_module, expected_default_version)
......@@ -1555,7 +1558,8 @@ class TestZodbModuleComponent(SecurityTestCase):
module_name = self._getComponentFullModuleName(module_name)
module = __import__(
module_name,
fromlist=[self._document_class._getDynamicModuleNamespace()],
fromlist=[self._document_class._getDynamicModuleNamespace()]
if six.PY2 else ['erp5'],
level=0)
self.assertIn(module_name, sys.modules)
return module
......@@ -2042,7 +2046,7 @@ def bar(*args, **kwargs):
self.assertModuleImportable('erp5_version.%s' % imported_reference)
top_module = __import__(top_module_name, level=0,
fromlist=[top_module_name])
fromlist=[top_module_name] if six.PY2 else ['erp5'])
self._importModule('erp5_version.%s' % imported_reference)
......@@ -2105,7 +2109,7 @@ def function_foo(*args, **kwargs):
top_module_name = self._document_class._getDynamicModuleNamespace()
top_module = __import__(top_module_name, level=0,
fromlist=[top_module_name])
fromlist=[top_module_name] if six.PY2 else ['erp5'])
self._importModule(reference)
module = getattr(top_module, reference)
......
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