forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_patching.py
More file actions
326 lines (255 loc) · 10.2 KB
/
test_patching.py
File metadata and controls
326 lines (255 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
from unittest import mock
from pythonforandroid.patching import (
is_platform,
is_linux,
is_darwin,
is_windows,
is_arch,
is_api,
is_api_gt,
is_api_gte,
is_api_lt,
is_api_lte,
is_ndk,
is_version_gt,
is_version_lt,
version_starts_with,
will_build,
check_all,
check_any,
)
class TestPlatformChecks:
"""Test platform detection functions."""
@mock.patch('pythonforandroid.patching.uname')
def test_is_platform_linux(self, mock_uname):
"""Test is_platform returns check function for Linux."""
mock_uname.return_value = mock.Mock(system='Linux')
check_fn = is_platform('Linux')
assert check_fn(None, None)
@mock.patch('pythonforandroid.patching.uname')
def test_is_platform_darwin(self, mock_uname):
"""Test is_platform returns check function for Darwin."""
mock_uname.return_value = mock.Mock(system='Darwin')
check_fn = is_platform('Darwin')
assert check_fn(None, None)
@mock.patch('pythonforandroid.patching.uname')
def test_is_platform_case_insensitive(self, mock_uname):
"""Test is_platform is case insensitive."""
mock_uname.return_value = mock.Mock(system='LINUX')
check_fn = is_platform('linux')
assert check_fn(None, None)
@mock.patch('pythonforandroid.patching.uname')
def test_is_platform_mismatch(self, mock_uname):
"""Test is_platform returns False for mismatched platform."""
mock_uname.return_value = mock.Mock(system='Linux')
check_fn = is_platform('Windows')
assert not check_fn(None, None)
def test_is_linux(self):
"""Test is_linux constant function is defined."""
# is_linux is defined at module import time based on real platform
# We can only verify it's callable
assert callable(is_linux)
def test_is_darwin(self):
"""Test is_darwin constant function is defined."""
# is_darwin is defined at module import time based on real platform
# We can only verify it's callable
assert callable(is_darwin)
def test_is_windows(self):
"""Test is_windows constant function is defined."""
# is_windows is defined at module import time based on real platform
# We can only verify it's callable
assert callable(is_windows)
class TestArchChecks:
"""Test architecture check functions."""
def test_is_arch_match(self):
"""Test is_arch returns True for matching architecture."""
mock_arch = mock.Mock(arch='armeabi-v7a')
check_fn = is_arch('armeabi-v7a')
assert check_fn(mock_arch)
def test_is_arch_mismatch(self):
"""Test is_arch returns False for mismatched architecture."""
mock_arch = mock.Mock(arch='armeabi-v7a')
check_fn = is_arch('arm64-v8a')
assert not check_fn(mock_arch)
class TestAndroidAPIChecks:
"""Test Android API level comparison functions."""
def test_is_api_equal(self):
"""Test is_api for equal API level."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 21
check_fn = is_api(21)
assert check_fn(None, mock_recipe)
def test_is_api_not_equal(self):
"""Test is_api for unequal API level."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 21
check_fn = is_api(27)
assert not check_fn(None, mock_recipe)
def test_is_api_gt(self):
"""Test is_api_gt for greater than comparison."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 27
check_fn = is_api_gt(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 21
assert not check_fn(None, mock_recipe)
def test_is_api_gte(self):
"""Test is_api_gte for greater than or equal comparison."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 27
check_fn = is_api_gte(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 21
check_fn = is_api_gte(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 19
assert not check_fn(None, mock_recipe)
def test_is_api_lt(self):
"""Test is_api_lt for less than comparison."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 19
check_fn = is_api_lt(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 21
assert not check_fn(None, mock_recipe)
def test_is_api_lte(self):
"""Test is_api_lte for less than or equal comparison."""
mock_recipe = mock.Mock()
mock_recipe.ctx.android_api = 19
check_fn = is_api_lte(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 21
check_fn = is_api_lte(21)
assert check_fn(None, mock_recipe)
mock_recipe.ctx.android_api = 27
assert not check_fn(None, mock_recipe)
class TestNDKChecks:
"""Test NDK version check functions."""
def test_is_ndk_equal(self):
"""Test is_ndk for equal NDK version."""
mock_ndk = mock.Mock(name='ndk_r21e')
mock_recipe = mock.Mock()
mock_recipe.ctx.ndk = mock_ndk
check_fn = is_ndk(mock_ndk)
assert check_fn(None, mock_recipe)
def test_is_ndk_not_equal(self):
"""Test is_ndk for unequal NDK version."""
mock_ndk1 = mock.Mock(name='ndk_r21e')
mock_ndk2 = mock.Mock(name='ndk_r25c')
mock_recipe = mock.Mock()
mock_recipe.ctx.ndk = mock_ndk1
check_fn = is_ndk(mock_ndk2)
assert not check_fn(None, mock_recipe)
class TestVersionChecks:
"""Test recipe version comparison functions."""
def test_is_version_gt(self):
"""Test is_version_gt for version comparison."""
mock_recipe = mock.Mock(version='2.0.0')
check_fn = is_version_gt('1.0.0')
assert check_fn(None, mock_recipe)
mock_recipe.version = '1.0.0'
assert not check_fn(None, mock_recipe)
def test_is_version_lt(self):
"""Test is_version_lt for version comparison."""
mock_recipe = mock.Mock(version='1.0.0')
check_fn = is_version_lt('2.0.0')
assert check_fn(None, mock_recipe)
mock_recipe.version = '2.0.0'
assert not check_fn(None, mock_recipe)
def test_version_starts_with(self):
"""Test version_starts_with for version prefix matching."""
mock_recipe = mock.Mock(version='1.15.2')
check_fn = version_starts_with('1.15')
assert check_fn(None, mock_recipe)
check_fn = version_starts_with('1.14')
assert not check_fn(None, mock_recipe)
check_fn = version_starts_with('2')
assert not check_fn(None, mock_recipe)
class TestWillBuild:
"""Test will_build function."""
def test_will_build_present(self):
"""Test will_build returns True when recipe is in build order."""
mock_recipe = mock.Mock()
mock_recipe.ctx.recipe_build_order = ['python3', 'numpy', 'kivy']
check_fn = will_build('numpy')
assert check_fn(None, mock_recipe)
def test_will_build_absent(self):
"""Test will_build returns False when recipe is not in build order."""
mock_recipe = mock.Mock()
mock_recipe.ctx.recipe_build_order = ['python3', 'numpy', 'kivy']
check_fn = will_build('scipy')
assert not check_fn(None, mock_recipe)
class TestConjunctions:
"""Test logical conjunction functions."""
def test_check_all_all_true(self):
"""Test check_all returns True when all checks pass."""
def check1(_arch, _recipe):
return True
def check2(_arch, _recipe):
return True
def check3(_arch, _recipe):
return True
check_fn = check_all(check1, check2, check3)
assert check_fn(None, None)
def test_check_all_one_false(self):
"""Test check_all returns False when one check fails."""
def check1(_arch, _recipe):
return True
def check2(_arch, _recipe):
return False
def check3(_arch, _recipe):
return True
check_fn = check_all(check1, check2, check3)
assert not check_fn(None, None)
def test_check_all_all_false(self):
"""Test check_all returns False when all checks fail."""
def check1(_arch, _recipe):
return False
def check2(_arch, _recipe):
return False
check_fn = check_all(check1, check2)
assert not check_fn(None, None)
def test_check_any_one_true(self):
"""Test check_any returns True when one check passes."""
def check1(_arch, _recipe):
return False
def check2(_arch, _recipe):
return True
def check3(_arch, _recipe):
return False
check_fn = check_any(check1, check2, check3)
assert check_fn(None, None)
def test_check_any_all_false(self):
"""Test check_any returns False when all checks fail."""
def check1(_arch, _recipe):
return False
def check2(_arch, _recipe):
return False
check_fn = check_any(check1, check2)
assert not check_fn(None, None)
def test_check_any_all_true(self):
"""Test check_any returns True when all checks pass."""
def check1(_arch, _recipe):
return True
def check2(_arch, _recipe):
return True
check_fn = check_any(check1, check2)
assert check_fn(None, None)
@mock.patch('pythonforandroid.patching.uname')
def test_combined_checks(self, mock_uname):
"""Test combining multiple check functions with check_all and check_any."""
# Test check_all with is_platform and is_version_gt
mock_uname.return_value = mock.Mock(system='Linux')
mock_recipe = mock.Mock(version='2.0.0')
check_fn = check_all(
is_platform('Linux'),
is_version_gt('1.0.0')
)
assert check_fn(None, mock_recipe)
# Test check_any with is_platform and is_version_gt
mock_uname.return_value = mock.Mock(system='Windows')
check_fn = check_any(
is_platform('Linux'),
is_version_gt('1.0.0')
)
assert check_fn(None, mock_recipe)