Skip to content

Commit 063fe8b

Browse files
dnicolodirgommers
authored andcommitted
TST: add tests for meson version discovery and error reporting
1 parent 271f7d6 commit 063fe8b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/test_pep517.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import os
6+
import re
57
import shutil
68
import subprocess
79
import sys
10+
import textwrap
811

912
from typing import List
1013

@@ -95,3 +98,48 @@ def test_validate_config_settings_list():
9598
def test_validate_config_settings_tuple():
9699
config = mesonpy._validate_config_settings({'setup-args': ('-Done=1', '-Dtwo=2')})
97100
assert config['setup-args'] == ['-Done=1', '-Dtwo=2']
101+
102+
103+
@pytest.mark.parametrize('meson', [None, 'meson'])
104+
def test_get_meson_command(monkeypatch, meson):
105+
# The MESON environment variable affects the meson executable lookup and breaks the test.
106+
monkeypatch.delenv('MESON', raising=False)
107+
assert mesonpy._get_meson_command(meson) == ['meson']
108+
109+
110+
def test_get_meson_command_bad_path(monkeypatch):
111+
# The MESON environment variable affects the meson executable lookup and breaks the test.
112+
monkeypatch.delenv('MESON', raising=False)
113+
with pytest.raises(mesonpy.ConfigError, match=re.escape('meson executable "bad" not found')):
114+
mesonpy._get_meson_command('bad')
115+
116+
117+
def test_get_meson_command_bad_python_path(monkeypatch):
118+
# The MESON environment variable affects the meson executable lookup and breaks the test.
119+
monkeypatch.delenv('MESON', raising=False)
120+
with pytest.raises(mesonpy.ConfigError, match=re.escape('Could not find the specified meson: "bad-python-path.py"')):
121+
mesonpy._get_meson_command('bad-python-path.py')
122+
123+
124+
def test_get_meson_command_wrong_version(monkeypatch, tmp_path):
125+
# The MESON environment variable affects the meson executable lookup and breaks the test.
126+
monkeypatch.delenv('MESON', raising=False)
127+
meson = tmp_path / 'meson.py'
128+
meson.write_text(textwrap.dedent('''
129+
print('0.0.1')
130+
'''))
131+
with pytest.raises(mesonpy.ConfigError, match=r'Could not find meson version [0-9\.]+ or newer, found 0\.0\.1\.'):
132+
mesonpy._get_meson_command(os.fspath(meson))
133+
134+
135+
def test_get_meson_command_error(monkeypatch, tmp_path):
136+
# The MESON environment variable affects the meson executable lookup and breaks the test.
137+
monkeypatch.delenv('MESON', raising=False)
138+
meson = tmp_path / 'meson.py'
139+
meson.write_text(textwrap.dedent('''
140+
import sys
141+
print('Just testing', file=sys.stderr)
142+
sys.exit(1)
143+
'''))
144+
with pytest.raises(mesonpy.ConfigError, match=re.escape('Could not execute meson: Just testing')):
145+
mesonpy._get_meson_command(os.fspath(meson))

0 commit comments

Comments
 (0)