|
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', ['patchelf', None], ids=['patchelf', 'nopatchelf']) |
| 18 | +@pytest.mark.parametrize('ninja', [None, '1.8.1', '1.8.3'], ids=['noninja', '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 and 'ninja' |
| 25 | + if prog in ('ninja-build', 'samu'): |
| 26 | + return None |
| 27 | + # smoke check for the future if we add another usage |
| 28 | + raise AssertionError(f'Called with {prog}, tests not expecting that usage') |
| 29 | + |
| 30 | + def run(cmd: List[str], *args: object, **kwargs: object) -> subprocess.CompletedProcess: |
| 31 | + if cmd != ['ninja', '--version']: |
| 32 | + # smoke check for the future if we add another usage |
| 33 | + raise AssertionError(f'Called with {cmd}, tests not expecting that usage') |
| 34 | + return subprocess.CompletedProcess(cmd, 0, f'{ninja}\n', '') |
| 35 | + |
| 36 | + monkeypatch.setattr(shutil, 'which', which) |
| 37 | + monkeypatch.setattr(subprocess, 'run', run) |
| 38 | + |
| 39 | + expected = {mesonpy._depstr.wheel} |
| 40 | + if system_patchelf is None and sys.platform.startswith('linux'): |
| 41 | + expected |= {mesonpy._depstr.patchelf} |
| 42 | + if ninja is None or [int(x) for x in ninja.split('.')] < [1, 8, 2]: |
| 43 | + expected |= {mesonpy._depstr.ninja} |
32 | 44 |
|
33 | 45 | with cd_package(package): |
34 | | - assert set(mesonpy.get_requires_for_build_wheel()) == expected | { |
35 | | - mesonpy._depstr.wheel, |
36 | | - } |
| 46 | + assert set(mesonpy.get_requires_for_build_wheel()) == expected |
0 commit comments