diff options
author | ?ric Araujo <merwok@netwok.org> | 2012-05-16 00:51:01 -0400 |
---|---|---|
committer | ?ric Araujo <merwok@netwok.org> | 2012-05-16 00:51:01 -0400 |
commit | 477f787a64f10e743ba7ed66008d853156b3fed5 (patch) | |
tree | 531a7ede22e5c7a97c965ddaf19993eb883ed2aa | |
parent | 25e1a0abddeb237490a50e4d6ed4bb584ccdb91e (diff) | |
download | disutils2-477f787a64f10e743ba7ed66008d853156b3fed5.tar.gz |
Harmonize error messages and add one missing test for #13339
-rw-r--r-- | distutils2/run.py | 13 | ||||
-rw-r--r-- | distutils2/tests/test_run.py | 33 |
2 files changed, 26 insertions, 20 deletions
diff --git a/distutils2/run.py b/distutils2/run.py index 35edd06..f571baa 100644 --- a/distutils2/run.py +++ b/distutils2/run.py @@ -387,6 +387,7 @@ class Dispatcher(object): self.parser.set_negative_aliases(negative_opt) # FIXME this parses everything, including command options (e.g. "run # build -i" errors with "option -i not recognized") + # FIXME unknown options are not detected args = self.parser.getopt(args=args, object=self) # if first arg is "run", we have some commands @@ -397,9 +398,8 @@ class Dispatcher(object): allowed = [action[0] for action in actions] + [None] if self.action not in allowed: - msg = 'Unrecognized action %s' % self.action self.show_help() - self.exit_with_error_msg(msg) + sys.exit('error: action %r not recognized' % self.action) self._set_logger() self.args = args @@ -436,7 +436,7 @@ class Dispatcher(object): # Pull the current command from the head of the command line command = args[0] if not command_re.match(command): - raise SystemExit("invalid command name %r" % (command,)) + sys.exit('error: invalid command name %r' % command) self.commands.append(command) # Dig up the command class that implements this command, so we @@ -446,7 +446,7 @@ class Dispatcher(object): cmd_class = get_command_class(command) except PackagingModuleError, msg: self.show_help() - self.exit_with_error_msg(msg) + sys.exit('error: command %r not recognized' % command) # XXX We want to push this in distutils2.command # @@ -491,7 +491,7 @@ class Dispatcher(object): args, opts = parser.getopt(args[1:]) except PackagingArgError, msg: self.show_help() - self.exit_with_error_msg(msg) + sys.exit('error: %s' % msg) if hasattr(opts, 'help') and opts.help: self._show_command_help(cmd_class) @@ -536,9 +536,6 @@ class Dispatcher(object): def show_help(self): self._show_help(self.parser) - def exit_with_error_msg(self, msg): - sys.exit('error: ' + msg.__str__()) - def print_usage(self, parser): parser.set_option_table(global_options) diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py index a6e2c20..1b49264 100644 --- a/distutils2/tests/test_run.py +++ b/distutils2/tests/test_run.py @@ -94,37 +94,46 @@ class RunTestCase(support.TempdirManager, self.assertTrue(build_position, out) self.assertLess(check_position, build_position, out) - def test_unknown_run_option(self): + # 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() - ) + '--unknown', PYTHONPATH=self.get_pythonpath()) self.assertEqual(status, 1) 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 + # changed when the command line parsers are replaced by something clean self.assertEqual(err.splitlines()[-1], - 'error: option --unknown not recognized') + '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) + 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() - ) + 'invalid_command', PYTHONPATH=self.get_pythonpath()) self.assertEqual(status, 1) self.assertGreater(out, 1) self.assertEqual(err.splitlines()[-1], - 'error: Invalid command invalid_command') + "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() - ) + PYTHONPATH=self.get_pythonpath()) self.assertEqual(status, 1) self.assertGreater(out, 1) self.assertEqual(err.splitlines()[-1], - 'error: Unrecognized action invalid_action') - - # TODO test that custom commands don't break --list-commands + "error: action 'invalid_action' not recognized") def test_suite(): |