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