Commits

Éric Araujo committed 1c09e0c

Factor out repeated code used to call pysetup from tests.

The whole assert_python_* business was unfriendly for readers, now the
code needed to have the equivalent of pysetup run from tests is moved to
helper methods and the tests can have much clearer code.

Also remove Python 2.4 compatibility (using -c instead of -m).

Comments (0)

Files changed (1)

distutils2/tests/test_run.py

 
     def get_pythonpath(self):
         pythonpath = os.environ.get('PYTHONPATH')
-        d2parent = os.path.dirname(os.path.dirname(__file__))
+        d2parent = os.path.dirname(os.path.dirname(__file__))  # XXX buggy
         if pythonpath is not None:
             pythonpath = os.pathsep.join((pythonpath, d2parent))
         else:
             pythonpath = d2parent
         return pythonpath
 
+    def call_pysetup(self, *args):
+        _, out, err = assert_python_ok('-m', 'distutils2.run', *args,
+                                       PYTHONPATH=self.get_pythonpath())
+        return out, err
+
+    def call_pysetup_fail(self, *args):
+        _, out, err = assert_python_failure('-m', 'distutils2.run', *args,
+                                            PYTHONPATH=self.get_pythonpath())
+        return out, err
+
     def test_show_help(self):
         # smoke test, just makes sure some help is displayed
-        status, out, err = assert_python_ok(
-            '-c', 'from distutils2.run import main; main()', '--help',
-            PYTHONPATH=self.get_pythonpath())
-        self.assertEqual(status, 0)
+        out, err = self.call_pysetup('--help')
         self.assertGreater(out, '')
         self.assertEqual(err, '')
 
     def test_list_commands(self):
-        status, out, err = assert_python_ok(
-            '-c', 'from distutils2.run import main; main()', 'run',
-            '--list-commands', PYTHONPATH=self.get_pythonpath())
+        out, err = self.call_pysetup('run', '--list-commands')
         # check that something is displayed
-        self.assertEqual(status, 0)
         self.assertGreater(out, '')
         self.assertEqual(err, '')
 
     # TODO test that custom commands don't break --list-commands
 
     def test_unknown_command_option(self):
-        status, out, err = assert_python_failure(
-            '-c', 'from distutils2.run import main; main()', 'run', 'build',
-            '--unknown', PYTHONPATH=self.get_pythonpath())
-        self.assertEqual(status, 1)
+        out, err = self.call_pysetup_fail('run', 'build', '--unknown')
         self.assertGreater(out, '')
         # sadly this message comes straight from the getopt module and can't be
         # modified to use repr instead of str for the unknown option; to be
                          'error: option --unknown not recognized')
 
     def test_invalid_command(self):
-        status, out, err = assert_python_failure(
-            '-c', 'from distutils2.run import main; main()', 'run',
-            'com#mand', PYTHONPATH=self.get_pythonpath())
-        self.assertEqual(status, 1)
+        out, err = self.call_pysetup_fail('run', 'com#mand')
         self.assertGreater(out, 1)
         self.assertEqual(err.splitlines()[-1],
                          "error: invalid command name 'com#mand'")
 
     def test_unknown_command(self):
-        status, out, err = assert_python_failure(
-            '-c', 'from distutils2.run import main; main()', 'run',
-            'invalid_command', PYTHONPATH=self.get_pythonpath())
-        self.assertEqual(status, 1)
+        out, err = self.call_pysetup_fail('run', 'invalid_command')
         self.assertGreater(out, 1)
         self.assertEqual(err.splitlines()[-1],
                          "error: command 'invalid_command' not recognized")
 
     def test_unknown_action(self):
-        status, out, err = assert_python_failure(
-            '-c', 'from distutils2.run import main; main()', 'invalid_action',
-            PYTHONPATH=self.get_pythonpath())
-        self.assertEqual(status, 1)
+        out, err = self.call_pysetup_fail('invalid_action')
         self.assertGreater(out, 1)
         self.assertEqual(err.splitlines()[-1],
                          "error: action 'invalid_action' not recognized")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.