Skip to content

Increases toolchain.py test coverage #1933

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

Merged
merged 1 commit into from
Jul 27, 2019
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
9 changes: 9 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,15 @@ def _read_configuration():
sys.argv.append(arg)

def recipes(self, args):
"""
Prints recipes basic info, e.g.
```
python3 3.7.1
depends: ['hostpython3', 'sqlite3', 'openssl', 'libffi']
conflicts: ['python2']
optional depends: ['sqlite3', 'libffi', 'openssl']
```
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I'm not sure how it will be rendered this docstring in sphinx...maybe I would use a code-block directive, something like:

        Prints recipes basic info, e.g.
        .. code-block:: bash

            python3      3.7.1
            depends: ['hostpython3', 'sqlite3', 'openssl', 'libffi']
            conflicts: ['python2']
            optional depends: ['sqlite3', 'libffi', 'openssl']

But, @AndreMiras, don't need to change this, if I remember well, I think that we don't have enabled the build of technical documentation, so it wont be visible for now.

Apart from this, I would like to mention that overall it looks good, clean and very readable.Also, I made tox test on my machine, with current develop branch , since it's already merged, without any issue.

@AndreMiras, thanks for this PR, good job, as usual 👍

and @Jonast, thanks for your review, I was out for the weekend and I was unable to take care of the review, so yours sped up the merging 😄

Copy link
Member Author

@AndreMiras AndreMiras Jul 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how I missed that comment. I'd be happy to address it still.
Edit: covered as part of #1948

ctx = self.ctx
if args.compact:
print(" ".join(set(Recipe.list_recipes(ctx))))
Expand Down
57 changes: 53 additions & 4 deletions tests/test_toolchain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import io
import sys
import pytest
import mock
from pythonforandroid.recipe import Recipe
from pythonforandroid.toolchain import ToolchainCL
from pythonforandroid.util import BuildInterruptingException

Expand All @@ -13,6 +15,10 @@ def patch_argparse_print_help():
return mock.patch('argparse.ArgumentParser.print_help')


def patch_sys_stdout():
return mock.patch('sys.stdout', new_callable=io.StringIO)


def raises_system_exit():
return pytest.raises(SystemExit)

Expand Down Expand Up @@ -51,6 +57,8 @@ def test_create(self):
'create',
'--sdk-dir=/tmp/android-sdk',
'--ndk-dir=/tmp/android-ndk',
'--bootstrap=service_only',
'--requirements=python3',
'--dist-name=test_toolchain',
]
with patch_sys_argv(argv), mock.patch(
Expand All @@ -62,8 +70,11 @@ def test_create(self):
) as m_get_ndk_platform_dir, mock.patch(
'pythonforandroid.build.get_cython_path'
) as m_get_cython_path, mock.patch(
'pythonforandroid.toolchain.build_dist_from_args'
) as m_build_dist_from_args:
'pythonforandroid.toolchain.build_recipes'
) as m_build_recipes, mock.patch(
'pythonforandroid.bootstraps.service_only.'
'ServiceOnlyBootstrap.run_distribute'
) as m_run_distribute:
m_get_available_apis.return_value = [27]
m_get_toolchain_versions.return_value = (['4.9'], True)
m_get_ndk_platform_dir.return_value = (
Expand All @@ -74,16 +85,54 @@ def test_create(self):
assert m_get_toolchain_versions.call_args_list == [
mock.call('/tmp/android-ndk', mock.ANY)]
assert m_get_cython_path.call_args_list == [mock.call()]
assert m_build_dist_from_args.call_count == 1
build_order = [
'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3',
'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android',
]
python_modules = []
context = mock.ANY
project_dir = None
assert m_build_recipes.call_args_list == [
mock.call(
build_order,
python_modules,
context,
project_dir,
ignore_project_setup_py=False
)
]
assert m_run_distribute.call_args_list == [mock.call()]

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(
with patch_sys_argv(argv), pytest.raises(
BuildInterruptingException
) as ex_info:
ToolchainCL()
assert ex_info.value.message == (
'Android SDK dir was not specified, exiting.')

@pytest.mark.skipif(sys.version_info < (3, 0), reason="requires python3")
def test_recipes(self):
"""
Checks the `recipes` command prints out recipes information without crashing.
"""
argv = ['toolchain.py', 'recipes']
with patch_sys_argv(argv), patch_sys_stdout() as m_stdout:
ToolchainCL()
# check if we have common patterns in the output
expected_strings = (
'conflicts:',
'depends:',
'kivy',
'optional depends:',
'python3',
'sdl2',
)
for expected_string in expected_strings:
assert expected_string in m_stdout.getvalue()
# deletes static attribute to not mess with other tests
del Recipe.recipes