Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (21)
Tags (11)
master
develop
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
tito-patch-1
fix-libffi-system-python3
py2-fixes
dump_restore_manifest
stable
old_toolchain
recipes_task
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
master
Branches (21)
Tags (11)
master
develop
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
tito-patch-1
fix-libffi-system-python3
py2-fixes
dump_restore_manifest
stable
old_toolchain
recipes_task
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (21)
Tags (11)
master
develop
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
tito-patch-1
fix-libffi-system-python3
py2-fixes
dump_restore_manifest
stable
old_toolchain
recipes_task
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
python-for-android
/
tests
/
test_pythonpackage_basic.py
python-for-android
/
tests
/
test_pythonpackage_basic.py
test_pythonpackage_basic.py 11.68 KB
Copy Edit Raw Blame History
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
"""
ONLY BASIC TEST SET. The additional ones are in test_pythonpackage.py.
These are in a separate file because these were picked to run in github-actions,
while the other additional ones aren't (for build time reasons).
"""
import os
import shutil
import sys
import subprocess
import tempfile
import textwrap
from unittest import mock
from pythonforandroid.pythonpackage import (
_extract_info_from_package,
get_dep_names_of_package,
get_package_name,
_get_system_python_executable,
is_filesystem_path,
parse_as_folder_reference,
transform_dep_for_pip,
)
def local_repo_folder():
return os.path.abspath(os.path.join(
os.path.dirname(__file__), ".."
))
def fake_metadata_extract(dep_name, output_folder, debug=False):
# Helper function to write out fake metadata.
with open(os.path.join(output_folder, "METADATA"), "w") as f:
f.write(textwrap.dedent("""\
Metadata-Version: 2.1
Name: testpackage
Version: 0.1
Requires-Dist: testpkg
Requires-Dist: testpkg2
Lorem Ipsum"""
))
with open(os.path.join(output_folder, "metadata_source"), "w") as f:
f.write(u"wheel") # since we have no pyproject.toml
def test__extract_info_from_package():
import pythonforandroid.pythonpackage # noqa
with mock.patch("pythonforandroid.pythonpackage."
"extract_metainfo_files_from_package",
fake_metadata_extract):
assert _extract_info_from_package(
"whatever", extract_type="name"
) == "testpackage"
assert set(_extract_info_from_package(
"whatever", extract_type="dependencies"
)) == {"testpkg", "testpkg2"}
def test_get_package_name():
# TEST 1 from external ref
with mock.patch("pythonforandroid.pythonpackage."
"extract_metainfo_files_from_package",
fake_metadata_extract):
assert get_package_name("TeStPackaGe") == "testpackage"
# TEST 2 from a local folder, for which we'll create a fake package:
temp_d = tempfile.mkdtemp(prefix="p4a-pythonpackage-test-tmp-")
try:
with open(os.path.join(temp_d, "setup.py"), "w") as f:
f.write(textwrap.dedent("""\
from setuptools import setup
setup(name="testpackage")
"""
))
pkg_name = get_package_name(temp_d)
assert pkg_name == "testpackage"
finally:
shutil.rmtree(temp_d)
def test_get_dep_names_of_package():
# TEST 1 from external ref:
# Check that colorama is returned without the install condition when
# just getting the names (it has a "; ..." conditional originally):
dep_names = get_dep_names_of_package("python-for-android")
assert "colorama" in dep_names
assert "setuptools" not in dep_names
try:
dep_names = get_dep_names_of_package(
"python-for-android", include_build_requirements=True,
verbose=True,
)
except NotImplementedError as e:
# If python-for-android was fetched as wheel then build requirements
# cannot be obtained (since that is not implemented for wheels).
# Check for the correct error message:
assert "wheel" in str(e)
# (And yes it would be better to do a local test with something
# that is guaranteed to be a wheel and not remote on pypi,
# but that might require setting up a full local pypiserver.
# Not worth the test complexity for now, but if anyone has an
# idea in the future feel free to replace this subtest.)
else:
# We managed to obtain build requirements!
# Check setuptools is in here:
assert "setuptools" in dep_names
# TEST 2 from local folder:
assert "colorama" in get_dep_names_of_package(local_repo_folder())
# Now test that exact version pins are kept, but others aren't:
test_fake_package = tempfile.mkdtemp()
try:
with open(os.path.join(test_fake_package, "setup.py"), "w") as f:
f.write(textwrap.dedent("""\
from setuptools import setup
setup(name='fakeproject',
description='fake for testing',
install_requires=['buildozer==0.39',
'python-for-android>=0.5.1'],
)
"""))
# See that we get the deps with the exact version pin kept but
# the other version restriction gone:
assert set(get_dep_names_of_package(
test_fake_package, recursive=False,
keep_version_pins=True, verbose=True
)) == {"buildozer==0.39", "python-for-android"}
# Make sure we also can get the fully cleaned up variant:
assert set(get_dep_names_of_package(
test_fake_package, recursive=False,
keep_version_pins=False, verbose=True
)) == {"buildozer", "python-for-android"}
# Test with build requirements included:
dep_names = get_dep_names_of_package(
test_fake_package, recursive=False,
keep_version_pins=False, verbose=True,
include_build_requirements=True
)
assert len(
{"buildozer", "python-for-android", "setuptools"}.intersection(
dep_names
)
) == 3 # all three must be included
finally:
shutil.rmtree(test_fake_package)
def test_transform_dep_for_pip():
# A reminder, this entire function we test here is just a workaround
# for https://github.com/pypa/pip/issues/6097 (and not a nice one.)
# As soon as upstream fixes it, we should throw it & this test out
transformed = (
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip"
),
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip" +
"#egg=python-for-android-master"
),
transform_dep_for_pip(
"python-for-android @ https://github.com/kivy/" +
"python-for-android/archive/master.zip" +
"#" # common hack variant used by others to make pip parse it
),
)
expected = (
"https://github.com/kivy/python-for-android/archive/master.zip" +
"#egg=python-for-android"
)
assert transformed == (expected, expected, expected)
assert transform_dep_for_pip("https://a@b/") == "https://a@b/"
def test_is_filesystem_path():
assert is_filesystem_path("/some/test")
assert not is_filesystem_path("https://blubb")
assert not is_filesystem_path("test @ bla")
assert is_filesystem_path("/abc/c@d")
assert not is_filesystem_path("https://user:pw@host/")
assert is_filesystem_path(".")
assert is_filesystem_path("")
def test_parse_as_folder_reference():
assert parse_as_folder_reference("file:///a%20test") == "/a test"
assert parse_as_folder_reference("https://github.com") is None
assert parse_as_folder_reference("/a/folder") == "/a/folder"
assert parse_as_folder_reference("test @ /abc") == "/abc"
assert parse_as_folder_reference("test @ https://bla") is None
class TestGetSystemPythonExecutable():
""" This contains all tests for _get_system_python_executable().
ULTRA IMPORTANT THING TO UNDERSTAND: (if you touch this)
This code runs things with other python interpreters NOT in the tox
environment/virtualenv.
E.g. _get_system_python_executable() is outside in the regular
host environment! That also means all dependencies can be possibly
not present!
This is kind of absurd that we need this to run the test at all,
but we can't test this inside tox's virtualenv:
"""
def test_basic(self):
# Tests function inside tox env with no further special setup.
# Get system-wide python bin:
pybin = _get_system_python_executable()
# The python binary needs to match our major version to be correct:
pyversion = subprocess.check_output([
pybin, "-c", "import sys; print(sys.version)"
], stderr=subprocess.STDOUT).decode("utf-8", "replace")
assert pyversion.strip() == sys.version.strip()
def run__get_system_python_executable(self, pybin):
""" Helper function to run our function.
We want to see what _get_system_python_executable() does given
a specific python, so we need to make it import it and run it,
with that TARGET python, which this function does.
"""
cmd = [
pybin,
"-c",
"import importlib\n"
"import json\n"
"import os\n"
"import sys\n"
"sys.path = [os.path.dirname(sys.argv[1])] + sys.path\n"
"m = importlib.import_module(\n"
" os.path.basename(sys.argv[1]).partition('.')[0]\n"
")\n"
"print(m._get_system_python_executable())",
os.path.join(os.path.dirname(__file__), "..",
"pythonforandroid", "pythonpackage.py"),
]
# Actual call to python:
try:
return subprocess.check_output(
cmd, stderr=subprocess.STDOUT
).decode("utf-8", "replace").strip()
except subprocess.CalledProcessError as e:
raise RuntimeError("call failed, with output: " + str(e.output))
def test_systemwide_python(self):
# Get system-wide python bin seen from here first:
pybin = _get_system_python_executable()
# (this call was not a test, we really just need the path here)
# Check that in system-wide python, the system-wide python is returned:
# IMPORTANT: understand that this runs OUTSIDE of any virtualenv.
try:
p1 = os.path.normpath(
self.run__get_system_python_executable(pybin)
)
p2 = os.path.normpath(pybin)
assert p1 == p2
except RuntimeError as e:
if "pep517" in str(e.args):
# System python probably doesn't have pep517 available!
# (remember this is not in a virtualenv)
# Not much we can do in that case since pythonpackage needs it,
# so we'll skip this particular check.
pass
else:
raise
def test_venv(self):
""" Verifies that _get_system_python_executable() works correctly
in a 'venv' (Python 3 only feature).
"""
# Get system-wide python bin seen from here first:
pybin = _get_system_python_executable()
# (this call was not a test, we really just need the path here)
test_dir = tempfile.mkdtemp()
try:
# Check that in a venv/pyvenv, the system-wide python is returned:
subprocess.check_output([
pybin, "-m", "venv", "--",
os.path.join(test_dir, "venv")
])
subprocess.check_output([
os.path.join(test_dir, "venv", "bin", "pip"),
"install", "-U", "pip"
])
subprocess.check_output([
os.path.join(test_dir, "venv", "bin", "pip"),
"install", "-U", "pep517<0.7.0"
])
subprocess.check_output([
os.path.join(test_dir, "venv", "bin", "pip"),
"install", "-U", "toml"
])
sys_python_path = self.run__get_system_python_executable(
os.path.join(test_dir, "venv", "bin", "python")
)
assert os.path.normpath(sys_python_path).startswith(
os.path.normpath(pybin)
)
finally:
shutil.rmtree(test_dir)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/feifei1014/python-for-android.git
git@gitee.com:feifei1014/python-for-android.git
feifei1014
python-for-android
python-for-android
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /