Commit e838ce08 authored by Douglas's avatar Douglas

erp5_jupyter: bugfix in ImportFixer to handle `import lib as name` cases

The ImportFixer AST processor wasn't correctly handling the alias
for imports. Now it takes them into consideration correctly. A test
to cover this case was added.
parent 24bc5c25
......@@ -667,7 +667,11 @@ class ImportFixer(ast.NodeTransformer):
for child in node.body:
if isinstance(child, ast.Import):
for alias in child.names:
self.import_func_dict[alias.name] = node.name
if getattr(alias, 'asname'):
import_name = alias.asname
else:
import_name = alias.name
self.import_func_dict[import_name] = node.name
return self.generic_visit(node)
def visit_ImportFrom(self, node):
......
......@@ -677,6 +677,34 @@ print random.randint(1,1)
self.assertTrue(error_substring in result)
self.assertTrue('second argument' in result)
def testImportFixerWithAlias(self):
self.login('dev_user')
import_code = '''
import random as rand
'''
reference = 'Test.Notebook.EnvironmentObject.ImportFixer'
result = self.portal.Base_executeJupyter(
reference=reference,
python_expression=import_code
)
self.tic()
self.assertEquals(json.loads(result)['status'], 'ok')
jupyter_code = '''
print rand.randint(1,1)
'''
result = self.portal.Base_executeJupyter(
reference=reference,
python_expression=jupyter_code
)
self.tic()
result = json.loads(result)
self.assertEquals(result['status'], 'ok')
self.assertEquals(result['code_result'].strip(), '1')
def testPivotTableJsIntegration(self):
'''
This test ensures the PivotTableJs user interface is correctly integrated
......
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