summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author?ric Araujo <merwok@netwok.org>2012-05-20 00:45:41 -0400
committer?ric Araujo <merwok@netwok.org>2012-05-20 00:45:41 -0400
commit7b719c5bc765f6e18c968f360a5fb315dcc8a1ac (patch)
tree6daab970b56fced2a2cb7762091f75a72c6bb7fc
parent0eb8b98af00570113698e39ad0627e5732a21157 (diff)
downloaddisutils2-7b719c5bc765f6e18c968f360a5fb315dcc8a1ac.tar.gz
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).
-rw-r--r--distutils2/tests/test_run.py42
1 files changed, 17 insertions, 25 deletions
diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py
index 1b49264..7f37c44 100644
--- a/distutils2/tests/test_run.py
+++ b/distutils2/tests/test_run.py
@@ -62,28 +62,32 @@ class RunTestCase(support.TempdirManager,
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, '')
@@ -97,10 +101,7 @@ class RunTestCase(support.TempdirManager,
# 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
@@ -109,28 +110,19 @@ class RunTestCase(support.TempdirManager,
'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")