|
| 1 | +import os |
| 2 | +import sys |
1 | 3 | import unittest
|
2 | 4 | from unittest import mock
|
3 | 5 |
|
4 | 6 | import jinja2
|
5 | 7 |
|
6 |
| -from pythonforandroid.build import run_pymodules_install |
| 8 | +from pythonforandroid.build import ( |
| 9 | + Context, RECOMMENDED_TARGET_API, run_pymodules_install, |
| 10 | +) |
7 | 11 | from pythonforandroid.archs import ArchARMv7_a, ArchAarch_64
|
8 | 12 |
|
9 | 13 |
|
@@ -89,3 +93,42 @@ def test_android_manifest_xml(self):
|
89 | 93 | assert xml.count('android:debuggable="true"') == 1
|
90 | 94 | assert xml.count('<service android:name="abcd" />') == 1
|
91 | 95 | # TODO: potentially some other checks to be added here to cover other "logic" (flags and loops) in the template
|
| 96 | + |
| 97 | + |
| 98 | +class TestContext(unittest.TestCase): |
| 99 | + |
| 100 | + @mock.patch.dict('pythonforandroid.build.Context.env') |
| 101 | + @mock.patch('pythonforandroid.build.get_available_apis') |
| 102 | + @mock.patch('pythonforandroid.build.ensure_dir') |
| 103 | + def test_sdk_ndk_paths( |
| 104 | + self, |
| 105 | + mock_ensure_dir, |
| 106 | + mock_get_available_apis, |
| 107 | + ): |
| 108 | + mock_get_available_apis.return_value = [RECOMMENDED_TARGET_API] |
| 109 | + context = Context() |
| 110 | + context.setup_dirs(os.getcwd()) |
| 111 | + context.prepare_build_environment( |
| 112 | + user_sdk_dir='sdk', |
| 113 | + user_ndk_dir='ndk', |
| 114 | + user_android_api=None, |
| 115 | + user_ndk_api=None, |
| 116 | + ) |
| 117 | + |
| 118 | + # The context was supplied with relative SDK and NDK dirs. Check |
| 119 | + # that it resolved them to absolute paths. |
| 120 | + real_sdk_dir = os.path.join(os.getcwd(), 'sdk') |
| 121 | + real_ndk_dir = os.path.join(os.getcwd(), 'ndk') |
| 122 | + assert context.sdk_dir == real_sdk_dir |
| 123 | + assert context.ndk_dir == real_ndk_dir |
| 124 | + |
| 125 | + py_platform = sys.platform |
| 126 | + if py_platform in ['linux2', 'linux3']: |
| 127 | + py_platform = 'linux' |
| 128 | + |
| 129 | + context_paths = context.env['PATH'].split(':') |
| 130 | + assert context_paths[0:3] == [ |
| 131 | + f'{real_ndk_dir}/toolchains/llvm/prebuilt/{py_platform}-x86_64/bin', |
| 132 | + real_ndk_dir, |
| 133 | + f'{real_sdk_dir}/tools' |
| 134 | + ] |
0 commit comments