forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bootstrap_build.py
More file actions
231 lines (175 loc) · 7.28 KB
/
Copy pathtest_bootstrap_build.py
File metadata and controls
231 lines (175 loc) · 7.28 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
import unittest
from unittest import mock
import pytest
import os
from pythonforandroid.util import load_source
def load_bootstrap_build_module():
os.environ["P4A_BUILD_IS_RUNNING_UNITTESTS"] = "1"
build_src = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../pythonforandroid/bootstraps/common/build/build.py",
)
buildpy = load_source("buildpy", build_src)
buildpy.get_bootstrap_name = mock.Mock(return_value="sdl2")
return buildpy
class TestBootstrapBuild(unittest.TestCase):
def setUp(self):
self.buildpy = load_bootstrap_build_module()
self.ap = self.buildpy.create_argument_parser()
self.common_args = [
"--package",
"org.test.app",
"--name",
"TestApp",
"--version",
"0.1",
]
class TestParsePermissions(TestBootstrapBuild):
def test_parse_permissions_with_migrations(self):
# Test that permissions declared in the old format are migrated to the
# new format.
# (Users can new declare permissions in both formats, even a mix)
self.ap = self.buildpy.create_argument_parser()
args = [
*self.common_args,
"--permission",
"INTERNET",
"--permission",
"com.android.voicemail.permission.ADD_VOICEMAIL",
"--permission",
"(name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)",
"--permission",
"(name=android.permission.BLUETOOTH_SCAN;usesPermissionFlags=neverForLocation)",
]
args = self.ap.parse_args(args)
parsed_permissions = self.buildpy.parse_permissions(args.permissions)
assert parsed_permissions == [
dict(name="android.permission.INTERNET"),
dict(name="com.android.voicemail.permission.ADD_VOICEMAIL"),
dict(name="android.permission.WRITE_EXTERNAL_STORAGE", maxSdkVersion="18"),
dict(
name="android.permission.BLUETOOTH_SCAN",
usesPermissionFlags="neverForLocation",
),
]
def test_parse_permissions_invalid_property(self):
self.ap = self.buildpy.create_argument_parser()
args = [
*self.common_args,
"--permission",
"(name=android.permission.BLUETOOTH_SCAN;propertyThatFails=neverForLocation)",
]
args = self.ap.parse_args(args)
with pytest.raises(
ValueError, match="Property 'propertyThatFails' is not supported."
):
self.buildpy.parse_permissions(args.permissions)
class TestOrientationArg(TestBootstrapBuild):
def test_no_orientation_args(self):
args = self.common_args
args = self.ap.parse_args(args)
assert (
self.buildpy.get_manifest_orientation(
args.orientation, args.manifest_orientation
)
== "unspecified"
)
assert self.buildpy.get_sdl_orientation_hint(args.orientation) == ""
def test_manifest_orientation_present(self):
args = [
*self.common_args,
"--orientation",
"landscape",
"--orientation",
"portrait",
"--manifest-orientation",
"fullSensor",
]
args = self.ap.parse_args(args)
assert (
self.buildpy.get_manifest_orientation(
args.orientation, manifest_orientation=args.manifest_orientation
)
== "fullSensor"
)
def test_manifest_orientation_supported(self):
args = [*self.common_args, "--orientation", "landscape"]
args = self.ap.parse_args(args)
assert (
self.buildpy.get_manifest_orientation(
args.orientation, manifest_orientation=args.manifest_orientation
)
== "landscape"
)
def test_android_manifest_multiple_orientation_supported(self):
args = [
*self.common_args,
"--orientation",
"landscape",
"--orientation",
"portrait",
]
args = self.ap.parse_args(args)
assert (
self.buildpy.get_manifest_orientation(
args.orientation, manifest_orientation=args.manifest_orientation
)
== "unspecified"
)
def test_sdl_orientation_hint_single(self):
args = [*self.common_args, "--orientation", "landscape"]
args = self.ap.parse_args(args)
assert (
self.buildpy.get_sdl_orientation_hint(args.orientation) == "LandscapeLeft"
)
def test_sdl_orientation_hint_multiple(self):
args = [
*self.common_args,
"--orientation",
"landscape",
"--orientation",
"portrait",
]
args = self.ap.parse_args(args)
sdl_orientation_hint = self.buildpy.get_sdl_orientation_hint(
args.orientation
).split(" ")
assert "LandscapeLeft" in sdl_orientation_hint
assert "Portrait" in sdl_orientation_hint
class TestAndroidNumericVersion:
def setup_method(self):
self.buildpy = load_bootstrap_build_module()
def test_generates_default_three_part_version_code(self):
assert self.buildpy.get_android_numeric_version("1.0.5", 24) == "102410005"
def test_accepts_and_normalizes_explicit_numeric_version(self):
assert self.buildpy.validate_android_numeric_version("0000001") == "1"
assert self.buildpy.validate_android_numeric_version(2100000000) == "2100000000"
@pytest.mark.parametrize("numeric_version", ["abc", "1.2", "", None])
def test_rejects_non_integer_explicit_numeric_versions(self, numeric_version):
with pytest.raises(ValueError, match="--numeric-version.*decimal integer"):
self.buildpy.validate_android_numeric_version(numeric_version)
@pytest.mark.parametrize("numeric_version", ["0", 0, "-1", -1])
def test_rejects_non_positive_explicit_numeric_versions(self, numeric_version):
with pytest.raises(ValueError, match="--numeric-version.*greater than 0"):
self.buildpy.validate_android_numeric_version(numeric_version)
@pytest.mark.parametrize("numeric_version", ["2100000001", 2100000001])
def test_rejects_oversized_explicit_numeric_versions(self, numeric_version):
with pytest.raises(
ValueError, match="--numeric-version.*2100000000"
):
self.buildpy.validate_android_numeric_version(numeric_version)
def test_rejects_generated_overflow_and_mentions_version_name(self):
generated_version = self.buildpy.get_android_numeric_version("1.0.5.1", 24)
with pytest.raises(
ValueError,
match="Generated Android versionCode .*--version '1\\.0\\.5\\.1'.*--numeric-version.*2100000000",
):
self.buildpy.validate_android_numeric_version(
generated_version, generated_from_version="1.0.5.1"
)
def test_rejects_non_numeric_version_name_for_generation(self):
with pytest.raises(
ValueError,
match="Could not generate Android versionCode from --version '1\\.0\\.beta'.*versionName.*--numeric-version",
):
self.buildpy.get_android_numeric_version("1.0.beta", 24)