Skip to content

Commit

Permalink
Handles unknown command/target error gracefully, closes #812
Browse files Browse the repository at this point in the history
Running `buildozer unknown_command` should show a meaningful error and
exit. Fixes regression introduced in 4936d31 and adds unit tests.

Also updates other tests `assert` keyword rather than `self.assert*` in
order to keep style consistent.

Last, minor `Dockerfile` documentation update as per recent @tshirtman
feedback.
  • Loading branch information
AndreMiras committed Mar 12, 2019
1 parent 2b40461 commit 831d85a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Expand Up @@ -8,13 +8,13 @@
# Run with (e.g. `buildozer --version`):
# docker run \
# --volume "$HOME/.buildozer":/home/user/.buildozer \
# --volume "$(pwd)":/home/user/hostcwd \
# --volume "$PWD":/home/user/hostcwd \
# kivy/buildozer --version
#
# Or for interactive shell:
# docker run --interactive --tty --rm \
# --volume "$HOME/.buildozer":/home/user/.buildozer \
# --volume "$(pwd)":/home/user/hostcwd \
# --volume "$PWD":/home/user/hostcwd \
# --entrypoint /bin/bash \
# kivy/buildozer
#
Expand Down
2 changes: 1 addition & 1 deletion buildozer/__init__.py
Expand Up @@ -1056,7 +1056,7 @@ def run_command(self, args):
# maybe it's a target?
targets = [x[0] for x in self.targets()]
if command not in targets:
print('Unknown command/target {}'.format(self.translate_target(command, inverse=True)))
print('Unknown command/target {}'.format(command))
exit(1)

self.set_target(command)
Expand Down
21 changes: 17 additions & 4 deletions tests/test_buildozer.py
Expand Up @@ -59,16 +59,16 @@ def test_buildozer_base(self):
Basic test making sure the Buildozer object can be instanciated.
"""
buildozer = Buildozer()
self.assertEqual(buildozer.specfilename, 'buildozer.spec')
assert buildozer.specfilename == 'buildozer.spec'
# spec file doesn't have to exist
self.assertFalse(os.path.exists(buildozer.specfilename))
assert os.path.exists(buildozer.specfilename) is False

def test_buildozer_read_spec(self):
"""
Initializes Buildozer object from existing spec file.
"""
buildozer = Buildozer(filename=self.default_specfile_path())
self.assertTrue(os.path.exists(buildozer.specfilename))
assert os.path.exists(buildozer.specfilename) is True

def test_buildozer_help(self):
"""
Expand All @@ -78,7 +78,7 @@ def test_buildozer_help(self):
buildozer = Buildozer()
with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
buildozer.usage()
self.assertIn('Usage:', mock_stdout.getvalue())
assert 'Usage:' in mock_stdout.getvalue()

def test_log_get_set(self):
"""
Expand Down Expand Up @@ -121,3 +121,16 @@ def test_log_print(self):
assert 'debug message' in mock_stdout.getvalue()
assert 'info message' in mock_stdout.getvalue()
assert 'error message' in mock_stdout.getvalue()

def test_run_command_unknown(self):
"""
Makes sure the unknown command/target is handled gracefully, refs:
https://github.com/kivy/buildozer/issues/812
"""
buildozer = Buildozer()
command = 'foobar'
args = [command, 'debug']
with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
with self.assertRaises(SystemExit):
buildozer.run_command(args)
assert mock_stdout.getvalue() == 'Unknown command/target {}\n'.format(command)

0 comments on commit 831d85a

Please sign in to comment.