зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1266343 - Avoid _apply_imports happening twice for the same function. r=chmanchester
This commit is contained in:
Родитель
24fc0c73b9
Коммит
24ce400759
|
@ -735,7 +735,9 @@ class ConfigureSandbox(dict):
|
|||
))
|
||||
@wraps(new_func)
|
||||
def wrapped(*args, **kwargs):
|
||||
self._apply_imports(func, glob)
|
||||
if func in self._imports:
|
||||
self._apply_imports(func, glob)
|
||||
del self._imports[func]
|
||||
return new_func(*args, **kwargs)
|
||||
|
||||
self._prepared_functions.add(wrapped)
|
||||
|
|
|
@ -342,6 +342,31 @@ class TestConfigure(unittest.TestCase):
|
|||
self.assertEquals(sandbox.keys(), ['__builtins__', 'foo'])
|
||||
self.assertEquals(sandbox['__builtins__'], ConfigureSandbox.BUILTINS)
|
||||
|
||||
def test_apply_imports(self):
|
||||
imports = []
|
||||
|
||||
class CountApplyImportsSandbox(ConfigureSandbox):
|
||||
def _apply_imports(self, *args, **kwargs):
|
||||
imports.append((args, kwargs))
|
||||
super(CountApplyImportsSandbox, self)._apply_imports(
|
||||
*args, **kwargs)
|
||||
|
||||
config = {}
|
||||
out = StringIO()
|
||||
sandbox = CountApplyImportsSandbox(config, {}, [], out, out)
|
||||
|
||||
exec_(textwrap.dedent('''
|
||||
@template
|
||||
@imports('sys')
|
||||
def foo():
|
||||
return sys
|
||||
foo()
|
||||
foo()'''),
|
||||
sandbox
|
||||
)
|
||||
|
||||
self.assertEquals(len(imports), 1)
|
||||
|
||||
def test_os_path(self):
|
||||
config = self.get_config(['--with-imports=%s' % __file__])
|
||||
self.assertIn('IS_FILE', config)
|
||||
|
|
Загрузка…
Ссылка в новой задаче