Skip to content

Commit

Permalink
Add a test for and fix behavior with bogus arguments
Browse files Browse the repository at this point in the history
We should have been using %s, not %r here.
  • Loading branch information
toofishes committed Nov 2, 2011
1 parent 37d35ed commit f36fb92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion celery/bin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def handle_argv(self, prog_name, argv):
options, args = self.parse_options(prog_name, argv)
if not self.supports_args and args:
sys.stderr.write(
"\nUnrecognized command line arguments: %r\n" % (
"\nUnrecognized command line arguments: %s\n" % (
", ".join(args), ))
sys.stderr.write("\nTry --help?\n")
sys.exit(1)
Expand Down
13 changes: 10 additions & 3 deletions celery/tests/test_bin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class MyApp(object):


class MockCommand(Command):
mock_args = ("arg1", "arg2", "arg3")

def parse_options(self, prog_name, arguments):
options = Object()
options.foo = "bar"
options.prog_name = prog_name
return options, (10, 20, 30)
return options, self.mock_args

def run(self, *args, **kwargs):
return args, kwargs
Expand All @@ -43,14 +44,20 @@ def test_run_interface(self):
def test_execute_from_commandline(self):
cmd = MockCommand()
args1, kwargs1 = cmd.execute_from_commandline() # sys.argv
self.assertTupleEqual(args1, (10, 20, 30))
self.assertTupleEqual(args1, cmd.mock_args)
self.assertDictContainsSubset({"foo": "bar"}, kwargs1)
self.assertTrue(kwargs1.get("prog_name"))
args2, kwargs2 = cmd.execute_from_commandline(["foo"]) # pass list
self.assertTupleEqual(args2, (10, 20, 30))
self.assertTupleEqual(args2, cmd.mock_args)
self.assertDictContainsSubset({"foo": "bar", "prog_name": "foo"},
kwargs2)

def test_with_bogus_args(self):
cmd = MockCommand()
cmd.supports_args = False
self.assertRaises(SystemExit,
cmd.execute_from_commandline, argv=["--bogus"])

def test_with_custom_config_module(self):
prev = os.environ.pop("CELERY_CONFIG_MODULE", None)
try:
Expand Down

0 comments on commit f36fb92

Please sign in to comment.