Skip to content

Commit 952f9ab

Browse files
committed
Add tests for PEP 660 hooks
1 parent 28c027c commit 952f9ab

File tree

10 files changed

+134
-0
lines changed

10 files changed

+134
-0
lines changed

tests/samples/buildsys_pkgs/buildsys.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ def get_requires_for_build_wheel(config_settings):
1414
return ['wheelwright']
1515

1616

17+
def get_requires_for_build_editable(config_settings):
18+
return ['wheelwright', 'editables']
19+
20+
1721
def prepare_metadata_for_build_wheel(metadata_directory, config_settings):
1822
for distinfo in glob('*.dist-info'):
1923
shutil.copytree(distinfo, pjoin(metadata_directory, distinfo))
2024

2125

26+
prepare_metadata_for_build_editable = prepare_metadata_for_build_wheel
27+
28+
2229
def prepare_build_wheel_files(build_directory, config_settings):
2330
shutil.copy('pyproject.toml', build_directory)
2431
for pyfile in glob('*.py'):
@@ -37,6 +44,9 @@ def build_wheel(wheel_directory, config_settings, metadata_directory=None):
3744
return whl_file
3845

3946

47+
build_editable = build_wheel
48+
49+
4050
def get_requires_for_build_sdist(config_settings):
4151
return ['frog']
4252

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from buildsys_minimal import build_sdist, build_wheel # noqa
2+
3+
4+
build_editable = build_wheel
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Thomas Kluyver
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Metadata-Version: 1.2
2+
Name: pkg3
3+
Version: 0.5
4+
Summary: Sample package for tests
5+
Home-page: https://github.com/takluyver/pkg3
6+
License: UNKNOWN
7+
Author: Thomas Kluyver
8+
Author-email: [email protected]
9+
Classifier: License :: OSI Approved :: MIT License
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkg3.py,sha256=ZawKBtrxtdGEheOCWvwzGZsO8Q1OSzEzecGNsRz-ekc,52
2+
pkg3-0.5.dist-info/LICENSE,sha256=GyKwSbUmfW38I6Z79KhNjsBLn9-xpR02DkK0NCyLQVQ,1081
3+
pkg3-0.5.dist-info/WHEEL,sha256=jxKvNaDKHDacpaLi69-vnLKkBSynwBzmMS82pipt1T0,100
4+
pkg3-0.5.dist-info/METADATA,sha256=4zQxJqc4Rvnlf5Y-seXnRx8g-1FK-sjTuS0A1KP0ajk,251
5+
pkg3-0.5.dist-info/RECORD,,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Wheel-Version: 1.0
2+
Generator: flit 0.11.3
3+
Root-Is-Purelib: true
4+
Tag: py2-none-any
5+
Tag: py3-none-any

tests/samples/pkg3/pkg3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Sample package for tests"""
2+
3+
__version__ = '0.5'

tests/samples/pkg3/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = []
3+
build-backend = "buildsys_minimal_editable"

tests/test_call_hooks.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def test_get_requires_for_build_wheel():
4949
assert res == ['wheelwright']
5050

5151

52+
def test_get_requires_for_build_editable():
53+
hooks = get_hooks('pkg1')
54+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
55+
res = hooks.get_requires_for_build_editable({})
56+
assert res == ['wheelwright', 'editables']
57+
58+
5259
def test_get_requires_for_build_sdist():
5360
hooks = get_hooks('pkg1')
5461
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
@@ -65,6 +72,15 @@ def test_prepare_metadata_for_build_wheel():
6572
assert_isfile(pjoin(metadatadir, 'pkg1-0.5.dist-info', 'METADATA'))
6673

6774

75+
def test_prepare_metadata_for_build_editable():
76+
hooks = get_hooks('pkg1')
77+
with TemporaryDirectory() as metadatadir:
78+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
79+
hooks.prepare_metadata_for_build_editable(metadatadir, {})
80+
81+
assert_isfile(pjoin(metadatadir, 'pkg1-0.5.dist-info', 'METADATA'))
82+
83+
6884
def test_build_wheel():
6985
hooks = get_hooks('pkg1')
7086
with TemporaryDirectory() as builddir:
@@ -79,6 +95,20 @@ def test_build_wheel():
7995
assert zipfile.is_zipfile(whl_file)
8096

8197

98+
def test_build_editable():
99+
hooks = get_hooks('pkg1')
100+
with TemporaryDirectory() as builddir:
101+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
102+
whl_file = hooks.build_editable(builddir, {})
103+
104+
assert whl_file.endswith('.whl')
105+
assert os.sep not in whl_file
106+
107+
whl_file = pjoin(builddir, whl_file)
108+
assert_isfile(whl_file)
109+
assert zipfile.is_zipfile(whl_file)
110+
111+
82112
def test_build_wheel_relpath():
83113
hooks = get_hooks('pkg1')
84114
with TemporaryWorkingDirectory() as builddir:

tests/test_hook_fallbacks.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def test_get_requires_for_build_wheel():
2424
assert res == []
2525

2626

27+
def test_get_requires_for_build_editable():
28+
hooks = get_hooks('pkg2')
29+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
30+
res = hooks.get_requires_for_build_editable({})
31+
assert res == []
32+
33+
2734
def test_get_requires_for_build_sdist():
2835
hooks = get_hooks('pkg2')
2936
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
@@ -40,6 +47,28 @@ def test_prepare_metadata_for_build_wheel():
4047
assert_isfile(pjoin(metadatadir, 'pkg2-0.5.dist-info', 'METADATA'))
4148

4249

50+
def test_prepare_metadata_for_build_editable():
51+
hooks = get_hooks('pkg3')
52+
with TemporaryDirectory() as metadatadir:
53+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
54+
hooks.prepare_metadata_for_build_editable(metadatadir, {})
55+
56+
assert_isfile(pjoin(metadatadir, 'pkg3-0.5.dist-info', 'METADATA'))
57+
58+
59+
def test_prepare_metadata_for_build_editable_missing_build_editable():
60+
hooks = get_hooks('pkg2')
61+
with TemporaryDirectory() as metadatadir:
62+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
63+
# pkg2's build system does not have build_editable
64+
with pytest.raises(HookMissing) as exc_info:
65+
hooks.prepare_metadata_for_build_editable(metadatadir, {})
66+
67+
e = exc_info.value
68+
assert 'build_editable' == e.hook_name
69+
assert 'build_editable' == str(e)
70+
71+
4372
def test_prepare_metadata_for_build_wheel_no_fallback():
4473
hooks = get_hooks('pkg2')
4574

@@ -53,3 +82,18 @@ def test_prepare_metadata_for_build_wheel_no_fallback():
5382
e = exc_info.value
5483
assert 'prepare_metadata_for_build_wheel' == e.hook_name
5584
assert 'prepare_metadata_for_build_wheel' in str(e)
85+
86+
87+
def test_prepare_metadata_for_build_editable_no_fallback():
88+
hooks = get_hooks('pkg2')
89+
90+
with TemporaryDirectory() as metadatadir:
91+
with modified_env({'PYTHONPATH': BUILDSYS_PKGS}):
92+
with pytest.raises(HookMissing) as exc_info:
93+
hooks.prepare_metadata_for_build_editable(
94+
metadatadir, {}, _allow_fallback=False
95+
)
96+
97+
e = exc_info.value
98+
assert 'prepare_metadata_for_build_editable' == e.hook_name
99+
assert 'prepare_metadata_for_build_editable' in str(e)

0 commit comments

Comments
 (0)