|
1 | 1 | # SPDX-License-Identifier: MIT
|
2 | 2 |
|
3 |
| -import platform |
| 3 | +import shutil |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | + |
| 7 | +from typing import List |
4 | 8 |
|
5 | 9 | import pytest
|
6 | 10 |
|
|
9 | 13 | from .conftest import cd_package
|
10 | 14 |
|
11 | 15 |
|
12 |
| -if platform.system() == 'Linux': |
13 |
| - VENDORING_DEPS = {mesonpy._depstr.patchelf} |
14 |
| -else: |
15 |
| - VENDORING_DEPS = set() |
16 |
| - |
17 |
| - |
18 |
| -@pytest.mark.parametrize( |
19 |
| - ('package', 'system_patchelf', 'expected'), |
20 |
| - [ |
21 |
| - ('pure', True, set()), # pure and system patchelf |
22 |
| - ('library', True, set()), # not pure and system patchelf |
23 |
| - ('pure', False, set()), # pure and no system patchelf |
24 |
| - ('library', False, VENDORING_DEPS), # not pure and no system patchelf |
25 |
| - ] |
26 |
| -) |
27 |
| -def test_get_requires_for_build_wheel(mocker, package, expected, system_patchelf): |
28 |
| - mock = mocker.patch('shutil.which', return_value=system_patchelf) |
29 |
| - |
30 |
| - if mock.called: # sanity check for the future if we add another usage |
31 |
| - mock.assert_called_once_with('patchelf') |
| 16 | +@pytest.mark.parametrize('package', ['pure', 'library']) |
| 17 | +@pytest.mark.parametrize('system_patchelf', [True, False], ids=['patchelf', 'nopatchelf']) |
| 18 | +@pytest.mark.parametrize('ninja', [None, '1.6', '1.10'], ids=['noninjga', 'oldninja', 'newninja']) |
| 19 | +def test_get_requires_for_build_wheel(monkeypatch, package, system_patchelf, ninja): |
| 20 | + def which(prog: str) -> bool: |
| 21 | + if prog == 'patchelf': |
| 22 | + return system_patchelf |
| 23 | + if prog == 'ninja': |
| 24 | + return ninja is not None |
| 25 | + # smoke check for the future if we add another usage |
| 26 | + raise AssertionError(f'Called with {prog}, tests not expecting that usage') |
| 27 | + |
| 28 | + def run(cmd: List[str], *args: object, **kwargs: object) -> subprocess.CompletedProcess: |
| 29 | + if cmd != ['ninja', '--version']: |
| 30 | + # smoke check for the future if we add another usage |
| 31 | + raise AssertionError(f'Called with {cmd}, tests not expecting that usage') |
| 32 | + return subprocess.CompletedProcess(cmd, 0, f'{ninja}\n', '') |
| 33 | + |
| 34 | + monkeypatch.setattr(shutil, 'which', which) |
| 35 | + monkeypatch.setattr(subprocess, 'run', run) |
| 36 | + |
| 37 | + expected = {mesonpy._depstr.wheel} |
| 38 | + if system_patchelf and sys.platform.startswith('linux'): |
| 39 | + expected |= {mesonpy._depstr.patchelf} |
| 40 | + if ninja is None or float(ninja) < 1.7: |
| 41 | + expected |= {mesonpy._depstr.ninja} |
32 | 42 |
|
33 | 43 | with cd_package(package):
|
34 |
| - assert set(mesonpy.get_requires_for_build_wheel()) == expected | { |
35 |
| - mesonpy._depstr.wheel, |
36 |
| - } |
| 44 | + assert set(mesonpy.get_requires_for_build_wheel()) == expected |
0 commit comments