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
87 lines (71 loc) · 2.74 KB
/
test_bootstrap_build.py
File metadata and controls
87 lines (71 loc) · 2.74 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
import unittest
import pytest
import os
import argparse
from pythonforandroid.util import load_source
class TestParsePermissions(unittest.TestCase):
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)
os.environ["P4A_BUILD_IS_RUNNING_UNITTESTS"] = "1"
ap = argparse.ArgumentParser()
ap.add_argument(
"--permission",
dest="permissions",
action="append",
default=[],
help="The permissions to give this app.",
nargs="+",
)
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 = ap.parse_args(args)
build_src = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../pythonforandroid/bootstraps/common/build/build.py",
)
buildpy = load_source("buildpy", build_src)
parsed_permissions = 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):
os.environ["P4A_BUILD_IS_RUNNING_UNITTESTS"] = "1"
ap = argparse.ArgumentParser()
ap.add_argument(
"--permission",
dest="permissions",
action="append",
default=[],
help="The permissions to give this app.",
nargs="+",
)
args = [
"--permission",
"(name=android.permission.BLUETOOTH_SCAN;propertyThatFails=neverForLocation)",
]
args = ap.parse_args(args)
build_src = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../pythonforandroid/bootstraps/common/build/build.py",
)
buildpy = load_source("buildpy", build_src)
with pytest.raises(
ValueError, match="Property 'propertyThatFails' is not supported."
):
buildpy.parse_permissions(args.permissions)