Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles unknown command/target error gracefully, closes #812 #853

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)