Merge pull request #853 from AndreMiras/feature/ticket812_fix_AttributeError_translate_target
Handles unknown command/target error gracefully, closes #812
This commit is contained in:
commit
4c2152b36e
3 changed files with 20 additions and 7 deletions
|
@ -8,13 +8,13 @@
|
||||||
# Run with (e.g. `buildozer --version`):
|
# Run with (e.g. `buildozer --version`):
|
||||||
# docker run \
|
# docker run \
|
||||||
# --volume "$HOME/.buildozer":/home/user/.buildozer \
|
# --volume "$HOME/.buildozer":/home/user/.buildozer \
|
||||||
# --volume "$(pwd)":/home/user/hostcwd \
|
# --volume "$PWD":/home/user/hostcwd \
|
||||||
# kivy/buildozer --version
|
# kivy/buildozer --version
|
||||||
#
|
#
|
||||||
# Or for interactive shell:
|
# Or for interactive shell:
|
||||||
# docker run --interactive --tty --rm \
|
# docker run --interactive --tty --rm \
|
||||||
# --volume "$HOME/.buildozer":/home/user/.buildozer \
|
# --volume "$HOME/.buildozer":/home/user/.buildozer \
|
||||||
# --volume "$(pwd)":/home/user/hostcwd \
|
# --volume "$PWD":/home/user/hostcwd \
|
||||||
# --entrypoint /bin/bash \
|
# --entrypoint /bin/bash \
|
||||||
# kivy/buildozer
|
# kivy/buildozer
|
||||||
#
|
#
|
||||||
|
|
|
@ -1056,7 +1056,7 @@ class Buildozer(object):
|
||||||
# maybe it's a target?
|
# maybe it's a target?
|
||||||
targets = [x[0] for x in self.targets()]
|
targets = [x[0] for x in self.targets()]
|
||||||
if command not in 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)
|
exit(1)
|
||||||
|
|
||||||
self.set_target(command)
|
self.set_target(command)
|
||||||
|
|
|
@ -59,16 +59,16 @@ class TestBuildozer(unittest.TestCase):
|
||||||
Basic test making sure the Buildozer object can be instanciated.
|
Basic test making sure the Buildozer object can be instanciated.
|
||||||
"""
|
"""
|
||||||
buildozer = Buildozer()
|
buildozer = Buildozer()
|
||||||
self.assertEqual(buildozer.specfilename, 'buildozer.spec')
|
assert buildozer.specfilename == 'buildozer.spec'
|
||||||
# spec file doesn't have to exist
|
# 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):
|
def test_buildozer_read_spec(self):
|
||||||
"""
|
"""
|
||||||
Initializes Buildozer object from existing spec file.
|
Initializes Buildozer object from existing spec file.
|
||||||
"""
|
"""
|
||||||
buildozer = Buildozer(filename=self.default_specfile_path())
|
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):
|
def test_buildozer_help(self):
|
||||||
"""
|
"""
|
||||||
|
@ -78,7 +78,7 @@ class TestBuildozer(unittest.TestCase):
|
||||||
buildozer = Buildozer()
|
buildozer = Buildozer()
|
||||||
with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
|
with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
|
||||||
buildozer.usage()
|
buildozer.usage()
|
||||||
self.assertIn('Usage:', mock_stdout.getvalue())
|
assert 'Usage:' in mock_stdout.getvalue()
|
||||||
|
|
||||||
def test_log_get_set(self):
|
def test_log_get_set(self):
|
||||||
"""
|
"""
|
||||||
|
@ -121,3 +121,16 @@ class TestBuildozer(unittest.TestCase):
|
||||||
assert 'debug message' in mock_stdout.getvalue()
|
assert 'debug message' in mock_stdout.getvalue()
|
||||||
assert 'info message' in mock_stdout.getvalue()
|
assert 'info message' in mock_stdout.getvalue()
|
||||||
assert 'error 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)
|
||||||
|
|
Loading…
Reference in a new issue