Skip to content

Commit e96a3e7

Browse files
committed
TST: make test more general and more efficient
1 parent 76a2f5f commit e96a3e7

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

tests/test_editable.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-License-Identifier: MIT
44

55
import os
6-
import shutil
76

87
import mesonpy
98

@@ -27,29 +26,3 @@ def test_editable(
2726
plat.write_text(plat_text)
2827

2928

30-
def test_editable_broken_non_existent_build_dir(
31-
package_imports_itself_during_build,
32-
editable_imports_itself_during_build,
33-
venv,
34-
tmp_path,
35-
):
36-
# Start from a clean slate, copy the package to temp path
37-
# Ensure there is no .mesonpy directory (could be generated by test_editable)
38-
shutil.rmtree(tmp_path) # copytree requires dest not to exist
39-
shutil.copytree(package_imports_itself_during_build, tmp_path)
40-
mesonpy_dir = os.path.join(package_imports_itself_during_build, '.mesonpy')
41-
if os.path.isdir(mesonpy_dir):
42-
venv.pip('uninstall', '-y', 'imports-itself-during-build')
43-
shutil.rmtree(mesonpy_dir)
44-
45-
venv.pip('install', os.path.join(tmp_path, mesonpy.build_editable(tmp_path)))
46-
47-
# Try corrupting the build dir,
48-
# removing the build dir after an install will trigger it
49-
if os.path.isdir(mesonpy_dir):
50-
venv.pip('uninstall', '-y', 'imports-itself-during-build')
51-
shutil.rmtree(mesonpy_dir)
52-
53-
venv.pip('install', os.path.join(tmp_path, mesonpy.build_editable(tmp_path)))
54-
55-
assert venv.python('-c', 'import plat; print(plat.foo())').strip() == 'bar'

tests/test_project.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
import platform
6+
import shutil
67
import sys
78
import textwrap
89

@@ -147,3 +148,44 @@ def test_validate_pyproject_config_empty():
147148
pyproject_config = tomllib.loads(textwrap.dedent(''))
148149
config = mesonpy._validate_pyproject_config(pyproject_config)
149150
assert config == {}
151+
152+
153+
@pytest.mark.skipif(
154+
sys.version_info < (3, 8),
155+
reason="unittest.mock doesn't support the required APIs for this test",
156+
)
157+
def test_invalid_build_dir(package_pure, tmp_path, mocker):
158+
meson = mocker.spy(mesonpy.Project, '_run')
159+
160+
# configure the project
161+
project = mesonpy.Project(package_pure, tmp_path)
162+
assert len(meson.call_args_list) == 1
163+
assert meson.call_args_list[0].args[1][1] == 'setup'
164+
assert '--reconfigure' not in meson.call_args_list[0].args[1]
165+
project.build()
166+
meson.reset_mock()
167+
168+
# subsequent builds with the same build directory result in a setup --reconfigure
169+
project = mesonpy.Project(package_pure, tmp_path)
170+
assert len(meson.call_args_list) == 1
171+
assert meson.call_args_list[0].args[1][1] == 'setup'
172+
assert '--reconfigure' in meson.call_args_list[0].args[1]
173+
project.build()
174+
meson.reset_mock()
175+
176+
# corrupting the build direcory setup is run again
177+
tmp_path.joinpath('build/meson-private/coredata.dat').unlink()
178+
project = mesonpy.Project(package_pure, tmp_path)
179+
assert len(meson.call_args_list) == 1
180+
assert meson.call_args_list[0].args[1][1] == 'setup'
181+
assert '--reconfigure' not in meson.call_args_list[0].args[1]
182+
project.build()
183+
meson.reset_mock()
184+
185+
# removing the build directory things should still work
186+
shutil.rmtree(tmp_path.joinpath('build'))
187+
project = mesonpy.Project(package_pure, tmp_path)
188+
assert len(meson.call_args_list) == 1
189+
assert meson.call_args_list[0].args[1][1] == 'setup'
190+
assert '--reconfigure' not in meson.call_args_list[0].args[1]
191+
project.build()

0 commit comments

Comments
 (0)