1
+ import io
1
2
import sys
2
3
import pytest
3
4
import mock
5
+ from pythonforandroid .recipe import Recipe
4
6
from pythonforandroid .toolchain import ToolchainCL
5
7
from pythonforandroid .util import BuildInterruptingException
6
8
@@ -13,6 +15,10 @@ def patch_argparse_print_help():
13
15
return mock .patch ('argparse.ArgumentParser.print_help' )
14
16
15
17
18
+ def patch_sys_stdout ():
19
+ return mock .patch ('sys.stdout' , new_callable = io .StringIO )
20
+
21
+
16
22
def raises_system_exit ():
17
23
return pytest .raises (SystemExit )
18
24
@@ -51,6 +57,8 @@ def test_create(self):
51
57
'create' ,
52
58
'--sdk-dir=/tmp/android-sdk' ,
53
59
'--ndk-dir=/tmp/android-ndk' ,
60
+ '--bootstrap=service_only' ,
61
+ '--requirements=python3' ,
54
62
'--dist-name=test_toolchain' ,
55
63
]
56
64
with patch_sys_argv (argv ), mock .patch (
@@ -62,8 +70,11 @@ def test_create(self):
62
70
) as m_get_ndk_platform_dir , mock .patch (
63
71
'pythonforandroid.build.get_cython_path'
64
72
) as m_get_cython_path , mock .patch (
65
- 'pythonforandroid.toolchain.build_dist_from_args'
66
- ) as m_build_dist_from_args :
73
+ 'pythonforandroid.toolchain.build_recipes'
74
+ ) as m_build_recipes , mock .patch (
75
+ 'pythonforandroid.bootstraps.service_only.'
76
+ 'ServiceOnlyBootstrap.run_distribute'
77
+ ) as m_run_distribute :
67
78
m_get_available_apis .return_value = [27 ]
68
79
m_get_toolchain_versions .return_value = (['4.9' ], True )
69
80
m_get_ndk_platform_dir .return_value = (
@@ -74,16 +85,54 @@ def test_create(self):
74
85
assert m_get_toolchain_versions .call_args_list == [
75
86
mock .call ('/tmp/android-ndk' , mock .ANY )]
76
87
assert m_get_cython_path .call_args_list == [mock .call ()]
77
- assert m_build_dist_from_args .call_count == 1
88
+ build_order = [
89
+ 'hostpython3' , 'libffi' , 'openssl' , 'sqlite3' , 'python3' ,
90
+ 'genericndkbuild' , 'setuptools' , 'six' , 'pyjnius' , 'android' ,
91
+ ]
92
+ python_modules = []
93
+ context = mock .ANY
94
+ project_dir = None
95
+ assert m_build_recipes .call_args_list == [
96
+ mock .call (
97
+ build_order ,
98
+ python_modules ,
99
+ context ,
100
+ project_dir ,
101
+ ignore_project_setup_py = False
102
+ )
103
+ ]
104
+ assert m_run_distribute .call_args_list == [mock .call ()]
78
105
79
106
def test_create_no_sdk_dir (self ):
80
107
"""
81
108
The `--sdk-dir` is mandatory to `create` a distribution.
82
109
"""
83
110
argv = ['toolchain.py' , 'create' ]
84
- with mock . patch ( 'sys.argv' , argv ), pytest .raises (
111
+ with patch_sys_argv ( argv ), pytest .raises (
85
112
BuildInterruptingException
86
113
) as ex_info :
87
114
ToolchainCL ()
88
115
assert ex_info .value .message == (
89
116
'Android SDK dir was not specified, exiting.' )
117
+
118
+ @pytest .mark .skipif (sys .version_info < (3 , 0 ), reason = "requires python3" )
119
+ def test_recipes (self ):
120
+ """
121
+ Checks the `recipes` command prints out recipes information without crashing.
122
+ """
123
+ argv = ['toolchain.py' , 'recipes' ]
124
+ with patch_sys_argv (argv ), patch_sys_stdout () as m_stdout :
125
+ ToolchainCL ()
126
+ # check if we have common patterns in the output
127
+ expected_strings = (
128
+ 'conflicts:' ,
129
+ 'depends:' ,
130
+ 'kivy' ,
131
+ 'optional depends:' ,
132
+ 'python3' ,
133
+ 'sdl2' ,
134
+ )
135
+ for expected_string in expected_strings :
136
+ assert expected_string in m_stdout .getvalue ()
137
+ # deletes static attribute to not mess with other tests
138
+ del Recipe .recipes
0 commit comments