Commit 3e46998e authored by Arnaud Fontaine's avatar Arnaud Fontaine

Do not set namespace dict where exec is executed into as a default parameter dict.

When load() was called in checkConsistency where namespace_dict was not given
and thus equal to the default function parameter value, exec would set the
function namespace_dict parameter, thus the next call would have
namespace_dict already set when it was given.

This fixes testInvalidSourceCode when being ran for TestZodbExtensionComponent
and TestZodbDocumentComponent in the same runUnitTest.
parent 1de396b2
...@@ -201,7 +201,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -201,7 +201,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
else: else:
message = None message = None
try: try:
self.load(text_content=text_content) self.load({}, text_content=text_content)
except SyntaxError, e: except SyntaxError, e:
mapping = dict(error_message=str(e), mapping = dict(error_message=str(e),
line_number=e.lineno, line_number=e.lineno,
...@@ -266,14 +266,18 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -266,14 +266,18 @@ class ComponentMixin(PropertyRecordableMixin, Base):
for error in current_workflow.get('error_message', [])] for error in current_workflow.get('error_message', [])]
security.declareProtected(Permissions.ModifyPortalContent, 'load') security.declareProtected(Permissions.ModifyPortalContent, 'load')
def load(self, namespace_dict={}, validated_only=False, text_content=None): def load(self, namespace_dict, validated_only=False, text_content=None):
""" """
Load the source code into the given dict. Using exec() rather than Load the source code into the given dict. Using exec() rather than
imp.load_source() as the latter would required creating an intermediary imp.load_source() as the latter would required creating an intermediary
file. Also, for traceback readability sake, the destination module file. Also, for traceback readability sake, the destination module
__dict__ is given rather than creating an empty dict and returning __dict__ is given rather than creating an empty dict and returning it.
it. By default namespace_dict is an empty dict to allow checking the
source code before validate. Initially, namespace_dict default parameter value was an empty dict to
allow checking the source code before validate, but this introduces a bug
when namespace_dict was not given because the first call would exec
directly into function namespace_dict default parameter, thus the second
call would have namespace_dict default value to the previous call.
""" """
if text_content is None: if text_content is None:
text_content = self.getTextContent(validated_only=validated_only) text_content = self.getTextContent(validated_only=validated_only)
......
...@@ -1474,12 +1474,14 @@ class _TestZodbComponent(SecurityTestCase): ...@@ -1474,12 +1474,14 @@ class _TestZodbComponent(SecurityTestCase):
self.assertEquals(component.getTextContent(validated_only=True), valid_code) self.assertEquals(component.getTextContent(validated_only=True), valid_code)
self.assertModuleImportable('TestComponentWithSyntaxError') self.assertModuleImportable('TestComponentWithSyntaxError')
invalid_code_dict = { # Make sure that foobar NameError is at the end to make sure that after
None: ComponentMixin._message_text_content_not_set, # defining foobar function, the symbol is not available anymore
'def foobar(*args, **kwargs)\n return 42': 'Syntax error in source code:', invalid_code_dict = (
'foobar': 'Source code:'} (None, ComponentMixin._message_text_content_not_set),
('def foobar(*args, **kwargs)\n return 42', 'Syntax error in source code:'),
for invalid_code, error_message in invalid_code_dict.iteritems(): ('foobar', 'Source code:'))
for invalid_code, error_message in invalid_code_dict:
ComponentTool.reset = assertResetNotCalled ComponentTool.reset = assertResetNotCalled
try: try:
component.setTextContent(invalid_code) component.setTextContent(invalid_code)
......
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