forked from astropy/extension-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
97 lines (70 loc) · 3.09 KB
/
Copy pathtest_utils.py
File metadata and controls
97 lines (70 loc) · 3.09 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
import os
import time
import pytest
from .._utils import (
abi_to_versions,
get_limited_api_option,
import_file,
write_if_different,
)
@pytest.mark.parametrize("path_type", ("str", "path"))
def test_import_file(tmp_path, path_type):
filepath = tmp_path / "spam.py"
if path_type == "str":
filepath = str(filepath)
with open(filepath, "w") as f:
f.write("magic = 12345")
module = import_file(filepath)
assert module.magic == 12345
@pytest.mark.parametrize("path_type", ("str", "path"))
def test_write_if_different(tmp_path, path_type):
filepath = tmp_path / "test.txt"
if path_type == "str":
filepath = str(filepath)
write_if_different(filepath, b"abc")
time1 = os.path.getmtime(filepath)
time.sleep(0.01)
write_if_different(filepath, b"abc")
time2 = os.path.getmtime(filepath)
assert time2 == time1
time.sleep(0.01)
write_if_different(filepath, b"abcd")
time3 = os.path.getmtime(filepath)
assert time3 > time1
class TestGetLimitedAPIOption:
def test_nofiles(self, tmp_path):
assert get_limited_api_option(tmp_path) is None
def test_empty_setup_cfg(self, tmp_path):
(tmp_path / "setup.cfg").write_text("")
assert get_limited_api_option(tmp_path) is None
def test_empty_pyproject_toml(self, tmp_path):
(tmp_path / "pyproject.toml").write_text("")
assert get_limited_api_option(tmp_path) is None
def test_setup_cfg(self, tmp_path):
(tmp_path / "setup.cfg").write_text("[bdist_wheel]\npy_limited_api=cp311")
assert get_limited_api_option(tmp_path) == "cp311"
# Make sure things still work even if an empty pyproject.toml file is present
(tmp_path / "pyproject.toml").write_text("")
assert get_limited_api_option(tmp_path) == "cp311"
# And if the pyproject.toml has the right section but not the right option
(tmp_path / "setup.cfg.toml").write_text("[tool.distutils.bdist_wheel]\nspam=1\n")
assert get_limited_api_option(tmp_path) == "cp311"
def test_pyproject(self, tmp_path):
(tmp_path / "pyproject.toml").write_text(
'[tool.distutils.bdist_wheel]\npy-limited-api="cp312"\n'
)
assert get_limited_api_option(tmp_path) == "cp312"
# Make sure things still work even if an empty setup.cfg file is present
(tmp_path / "setup.cfg.toml").write_text("\n")
assert get_limited_api_option(tmp_path) == "cp312"
# And if the setup.cfg has the right section but not the right option
(tmp_path / "setup.cfg.toml").write_text("[bdist_wheel]\nspam=1\n")
assert get_limited_api_option(tmp_path) == "cp312"
def test_abi_to_versions_invalid():
assert abi_to_versions("spam") == (None, None)
def test_abi_to_versions_valid():
assert abi_to_versions("cp39") == ((3, 9), "0x03090000")
assert abi_to_versions("cp310") == ((3, 10), "0x030A0000")
assert abi_to_versions("cp311") == ((3, 11), "0x030B0000")
assert abi_to_versions("cp312") == ((3, 12), "0x030C0000")
assert abi_to_versions("cp313") == ((3, 13), "0x030D0000")