Bug 1266343 - Use mozbuild.util.exec_ in the various configure tests. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Apr 2016 21:22:43 +0900
changeset 354777 049d947c79efefc4b61406b5cead791e20f3211c
parent 354749 7f64a3a95af69637ae6948b5ec340d7f1b2d0520
child 354778 9ad5a2ce5535a389797273cd3e67b20db31f17c6
push id16148
push userbmo:mh+mozilla@glandium.org
push dateThu, 21 Apr 2016 12:30:02 +0000
reviewerschmanchester
bugs1266343, 1264831
milestone48.0a1
Bug 1266343 - Use mozbuild.util.exec_ in the various configure tests. r?chmanchester Because some older python 2.7 versions throw bogus errors when using the exec statement as a function, use the function we added in bug 1264831 everywhere we use exec in the various configure tests. It doesn't take much to trigger them, and the following changes ends up doing exactly that.
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
python/mozbuild/mozbuild/test/configure/test_configure.py
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -10,16 +10,17 @@ import textwrap
 import unittest
 
 from mozunit import main
 
 from mozbuild.configure import (
     ConfigureError,
     ConfigureSandbox,
 )
+from mozbuild.util import exec_
 
 from buildconfig import topsrcdir
 
 
 class FindProgramSandbox(ConfigureSandbox):
     def __init__(self, *args, **kwargs):
         super(FindProgramSandbox, self).__init__(*args, **kwargs)
 
@@ -53,17 +54,17 @@ class FindProgramSandbox(ConfigureSandbo
 
 class TestChecksConfigure(unittest.TestCase):
     def test_checking(self):
         out = StringIO()
         sandbox = FindProgramSandbox({}, stdout=out, stderr=out)
         base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
         sandbox.include_file(os.path.join(base_dir, 'checks.configure'))
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @checking('for a thing')
             def foo(value):
                 return value
         '''), sandbox)
 
         foo = sandbox['foo']
 
         foo(True)
@@ -83,17 +84,17 @@ class TestChecksConfigure(unittest.TestC
 
         out.truncate(0)
         data = ['foo', 'bar']
         foo(data)
         self.assertEqual(out.getvalue(), 'checking for a thing... %r\n' % data)
 
         # When the function given to checking does nothing interesting, the
         # behavior is not altered
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @checking('for a thing', lambda x: x)
             def foo(value):
                 return value
         '''), sandbox)
 
         foo = sandbox['foo']
 
         out.truncate(0)
@@ -112,17 +113,17 @@ class TestChecksConfigure(unittest.TestC
         foo('foo')
         self.assertEqual(out.getvalue(), 'checking for a thing... foo\n')
 
         out.truncate(0)
         data = ['foo', 'bar']
         foo(data)
         self.assertEqual(out.getvalue(), 'checking for a thing... %r\n' % data)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             def munge(x):
                 if not x:
                     return 'not found'
                 if isinstance(x, (str, bool, int)):
                     return x
                 return ' '.join(x)
 
             @checking('for a thing', munge)
@@ -158,17 +159,17 @@ class TestChecksConfigure(unittest.TestC
         out = StringIO()
         sandbox = FindProgramSandbox(config, environ, [prog] + args, out, out)
         base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
         sandbox.include_file(os.path.join(base_dir, 'util.configure'))
         sandbox.include_file(os.path.join(base_dir, 'checks.configure'))
 
         status = 0
         try:
-            exec(command, sandbox)
+            exec_(command, sandbox)
             sandbox.run()
         except SystemExit as e:
             status = e.code
 
         return config, out.getvalue(), status
 
     def test_check_prog(self):
         config, out, status = self.get_result(
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -19,16 +19,17 @@ from mozbuild.configure.options import (
     InvalidOptionError,
     NegativeOptionValue,
     PositiveOptionValue,
 )
 from mozbuild.configure import (
     ConfigureError,
     ConfigureSandbox,
 )
+from mozbuild.util import exec_
 
 import mozpack.path as mozpath
 
 test_data_path = mozpath.abspath(mozpath.dirname(__file__))
 test_data_path = mozpath.join(test_data_path, 'data')
 
 
 class TestConfigure(unittest.TestCase):
@@ -239,100 +240,100 @@ class TestConfigure(unittest.TestCase):
         self.assertNotIn('CFLAGS', config)
 
     def test_imports(self):
         config = {}
         out = StringIO()
         sandbox = ConfigureSandbox(config, {}, [], out, out)
 
         with self.assertRaises(ImportError):
-            exec(textwrap.dedent('''
+            exec_(textwrap.dedent('''
                 @template
                 def foo():
                     import sys
                 foo()'''),
                 sandbox
             )
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports('sys')
             def foo():
                 return sys'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), sys)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports(_from='os', _import='path')
             def foo():
                 return path'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), os.path)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports(_from='os', _import='path', _as='os_path')
             def foo():
                 return os_path'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), os.path)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports('__builtin__')
             def foo():
                 return __builtin__'''),
             sandbox
         )
 
         import __builtin__
         self.assertIs(sandbox['foo'](), __builtin__)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports(_from='__builtin__', _import='open')
             def foo():
                 return open('%s')''' % os.devnull),
             sandbox
         )
 
         f = sandbox['foo']()
         self.assertEquals(f.name, os.devnull)
         f.close()
 
         # This unlocks the sandbox
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports(_import='__builtin__', _as='__builtins__')
             def foo():
                 import sys
                 return sys'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), sys)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports('__sandbox__')
             def foo():
                 return __sandbox__'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), sandbox)
 
-        exec(textwrap.dedent('''
+        exec_(textwrap.dedent('''
             @template
             @imports(_import='__sandbox__', _as='s')
             def foo():
                 return s'''),
             sandbox
         )
 
         self.assertIs(sandbox['foo'](), sandbox)