Bug 1254374 - Remove TestConfigure.get_result. r?nalexander draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 12 Apr 2016 15:11:07 +0900
changeset 349791 2c9fc838c1b991a8af81ffa710becc4570ef43b8
parent 349790 2fa9891a56e2e3fc9684e2225c6cb56fa1344a8a
child 349792 63f0979433d09595d493c16fbcfc6af331d34ba8
push id15177
push userbmo:mh+mozilla@glandium.org
push dateTue, 12 Apr 2016 09:20:20 +0000
reviewersnalexander
bugs1254374
milestone48.0a1
Bug 1254374 - Remove TestConfigure.get_result. r?nalexander
python/mozbuild/mozbuild/test/configure/test_configure.py
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -24,29 +24,26 @@ from mozbuild.configure import (
 
 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):
-    def get_result(self, args=[], environ={}, configure='moz.configure',
+    def get_config(self, options=[], env={}, configure='moz.configure',
                    prog='/bin/configure'):
         config = {}
         out = StringIO()
-        sandbox = ConfigureSandbox(config, environ, [prog] + args, out, out)
+        sandbox = ConfigureSandbox(config, env, [prog] + options, out, out)
 
         sandbox.run(mozpath.join(test_data_path, configure))
 
-        return config, out.getvalue()
-
-    def get_config(self, options=[], env={}, **kwargs):
-        config, out = self.get_result(options, environ=env, **kwargs)
-        self.assertEquals('', out)
+        if '--help' not in options:
+            self.assertEquals('', out.getvalue())
         return config
 
     def test_defaults(self):
         config = self.get_config()
         self.maxDiff = None
         self.assertEquals({
             'CHOICES': NegativeOptionValue(),
             'DEFAULTED': PositiveOptionValue(('not-simple',)),
@@ -56,17 +53,22 @@ class TestConfigure(unittest.TestCase):
             'SIMPLE': NegativeOptionValue(),
             'VALUES': NegativeOptionValue(),
             'VALUES2': NegativeOptionValue(),
             'VALUES3': NegativeOptionValue(),
             'WITH_ENV': NegativeOptionValue(),
         }, config)
 
     def test_help(self):
-        config, out = self.get_result(['--help'])
+        config = {}
+        out = StringIO()
+        sandbox = ConfigureSandbox(config, {}, ['configure', '--help'],
+                                   out, out)
+        sandbox.run(mozpath.join(test_data_path, 'moz.configure'))
+
         self.assertEquals({}, config)
         self.maxDiff = None
         self.assertEquals(
             'Usage: configure [options]\n'
             '\n'
             'Options: [defaults in brackets after descriptions]\n'
             '  --help                    print this message\n'
             '  --enable-simple           Enable simple\n'
@@ -79,17 +81,17 @@ class TestConfigure(unittest.TestCase):
             '  --returned-choices        Choices\n'
             '  --enable-imports-in-template\n'
             '                            Imports in template\n'
             '  --enable-include          Include\n'
             '  --with-imports            Imports\n'
             '\n'
             'Environment variables:\n'
             '  CC                        C Compiler\n',
-            out
+            out.getvalue()
         )
 
     def test_unknown(self):
         with self.assertRaises(InvalidOptionError):
             self.get_config(['--unknown'])
 
     def test_simple(self):
         for config in (
@@ -366,18 +368,17 @@ class TestConfigure(unittest.TestCase):
         self.assertNotIn('FOO', sandbox)
         self.assertNotIn('BAR', sandbox)
         self.assertNotIn('QUX', sandbox)
 
     def test_set_config(self):
         def get_config(*args):
             return self.get_config(*args, configure='set_config.configure')
 
-        config, out = self.get_result(['--help'],
-                                      configure='set_config.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config(['--set-foo'])
         self.assertIn('FOO', config)
         self.assertEquals(config['FOO'], True)
 
         config = get_config(['--set-bar'])
         self.assertNotIn('FOO', config)
@@ -399,18 +400,17 @@ class TestConfigure(unittest.TestCase):
             # Both --set-foo and --set-name=FOO are going to try to
             # set_config('FOO'...)
             get_config(['--set-foo', '--set-name=FOO'])
 
     def test_set_define(self):
         def get_config(*args):
             return self.get_config(*args, configure='set_define.configure')
 
-        config, out = self.get_result(['--help'],
-                                      configure='set_define.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {'DEFINES': {}})
 
         config = get_config(['--set-foo'])
         self.assertIn('FOO', config['DEFINES'])
         self.assertEquals(config['DEFINES']['FOO'], True)
 
         config = get_config(['--set-bar'])
         self.assertNotIn('FOO', config['DEFINES'])
@@ -433,18 +433,17 @@ class TestConfigure(unittest.TestCase):
             # set_define('FOO'...)
             get_config(['--set-foo', '--set-name=FOO'])
 
     def test_imply_option_simple(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/simple.configure')
 
-        config, out = self.get_result(
-            ['--help'], configure='imply_option/simple.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], PositiveOptionValue())
@@ -457,18 +456,17 @@ class TestConfigure(unittest.TestCase):
             "'--enable-bar' implied by '--enable-foo' conflicts with "
             "'--disable-bar' from the command-line")
 
     def test_imply_option_negative(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/negative.configure')
 
-        config, out = self.get_result(
-            ['--help'], configure='imply_option/negative.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], NegativeOptionValue())
@@ -493,18 +491,17 @@ class TestConfigure(unittest.TestCase):
             "'--disable-bar' implied by '--disable-hoge' conflicts with "
             "'--enable-bar' from the command-line")
 
     def test_imply_option_values(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/values.configure')
 
-        config, out = self.get_result(
-            ['--help'], configure='imply_option/values.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo=a'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], PositiveOptionValue(('a',)))
@@ -521,18 +518,17 @@ class TestConfigure(unittest.TestCase):
             "'--enable-bar=a,b' implied by '--enable-foo' conflicts with "
             "'--disable-bar' from the command-line")
 
     def test_imply_option_infer(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/infer.configure')
 
-        config, out = self.get_result(
-            ['--help'], configure='imply_option/infer.configure')
+        config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         with self.assertRaises(InvalidOptionError) as e:
             get_config(['--enable-foo', '--disable-bar'])