-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First simple set of tests for toolchain.py Also refactors `Context.prepare_build_environment()` slightly. Splits concerns to improve readability and ease unit testing.
- Loading branch information
1 parent
f6f6f19
commit f00fa53
Showing
2 changed files
with
76 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
import pytest | ||
import mock | ||
from pythonforandroid.toolchain import ToolchainCL | ||
from pythonforandroid.util import BuildInterruptingException | ||
|
||
|
||
class TestToolchainCL: | ||
|
||
def test_help(self): | ||
""" | ||
Calling with `--help` should print help and exit 0. | ||
""" | ||
argv = ['toolchain.py', '--help', '--storage-dir=/tmp'] | ||
with mock.patch('sys.argv', argv), pytest.raises(SystemExit) as ex_info, \ | ||
mock.patch('argparse.ArgumentParser.print_help') as m_print_help: | ||
ToolchainCL() | ||
assert m_print_help.call_args_list == [mock.call()] | ||
assert ex_info.value.code == 0 | ||
|
||
@pytest.mark.skipif(sys.version_info < (3, 0), reason="requires python3") | ||
def test_unknown(self): | ||
""" | ||
Calling with unknown args should print help and exit 1. | ||
""" | ||
argv = ['toolchain.py', '--unknown'] | ||
with mock.patch('sys.argv', argv), pytest.raises(SystemExit) as ex_info, \ | ||
mock.patch('argparse.ArgumentParser.print_help') as m_print_help: | ||
ToolchainCL() | ||
assert m_print_help.call_args_list == [mock.call()] | ||
assert ex_info.value.code == 1 | ||
|
||
def test_create(self): | ||
""" | ||
Basic `create` distribution test. | ||
""" | ||
argv = ['toolchain.py', 'create', '--sdk-dir=/tmp/android-sdk'] | ||
with mock.patch('sys.argv', argv), \ | ||
mock.patch('pythonforandroid.build.get_available_apis') as m_get_available_apis, \ | ||
mock.patch('pythonforandroid.toolchain.build_dist_from_args') as m_build_dist_from_args: | ||
m_get_available_apis.return_value = [27] | ||
ToolchainCL() | ||
assert m_get_available_apis.call_args_list == [mock.call('/tmp/android-sdk')] | ||
assert m_build_dist_from_args.call_count == 1 | ||
|
||
def test_create_no_sdk_dir(self): | ||
""" | ||
The `--sdk-dir` is mandatory to `create` a distribution. | ||
""" | ||
argv = ['toolchain.py', 'create'] | ||
with mock.patch('sys.argv', argv), pytest.raises(BuildInterruptingException) as ex_info: | ||
ToolchainCL() | ||
assert ex_info.value.message == 'Android SDK dir was not specified, exiting.' |