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

Exits with error code on build exception, fixes #674 #882

Merged
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
3 changes: 2 additions & 1 deletion buildozer/scripts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def main():
except BuildozerCommandException:
# don't show the exception in the command line. The log already show
# the command failed.
pass
sys.exit(1)
except BuildozerException as error:
Buildozer().error('%s' % error)
sys.exit(1)

if __name__ == '__main__':
main()
Empty file added tests/scripts/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/scripts/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
import mock
import unittest
from buildozer import BuildozerCommandException
from buildozer.scripts import client


class TestClient(unittest.TestCase):

def test_run_command_called(self):
"""
Checks Buildozer.run_command() is being called with arguments from command line.
"""
with mock.patch('buildozer.Buildozer.run_command') as m_run_command:
client.main()
assert m_run_command.call_args_list == [mock.call(sys.argv[1:])]

def test_exit_code(self):
"""
Makes sure the CLI exits with error code on BuildozerCommandException, refs #674.
"""
with mock.patch('buildozer.Buildozer.run_command') as m_run_command:
m_run_command.side_effect = BuildozerCommandException()
with self.assertRaises(SystemExit) as context:
client.main()
assert context.exception.code == 1