Skip to content

Commit 0e1a4c8

Browse files
committed
refactor: use listify in tests
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 5a87630 commit 0e1a4c8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

test/utils.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
This file is added to the PYTHONPATH in the test runner at bin/run_test.py.
55
"""
66

7+
import functools
78
import os
89
import platform as pm
910
import subprocess
1011
import sys
11-
from collections.abc import Mapping, Sequence
12+
from collections.abc import Callable, Generator, Mapping, Sequence
1213
from pathlib import Path
1314
from tempfile import TemporaryDirectory
14-
from typing import Any, Final
15+
from typing import Any, Final, ParamSpec, TypeVar
1516

1617
import pytest
1718

@@ -151,6 +152,19 @@ def _floor_macosx(*args: str) -> str:
151152
return max(args, key=lambda x: tuple(map(int, x.split("."))))
152153

153154

155+
P = ParamSpec("P")
156+
R = TypeVar("R")
157+
158+
159+
def _listify(func: Callable[P, Generator[R, None, None]]) -> Callable[P, list[R]]:
160+
@functools.wraps(func)
161+
def listify_return(*args: P.args, **kwargs: P.kwargs) -> list[R]:
162+
return list(func(*args, **kwargs))
163+
164+
return listify_return
165+
166+
167+
@_listify
154168
def expected_wheels(
155169
package_name: str,
156170
package_version: str,
@@ -162,9 +176,9 @@ def expected_wheels(
162176
include_universal2: bool = False,
163177
single_python: bool = False,
164178
single_arch: bool = False,
165-
) -> list[str]:
179+
) -> Generator[str, None, None]:
166180
"""
167-
Returns a list of expected wheels from a run of cibuildwheel.
181+
Returns the expected wheels from a run of cibuildwheel.
168182
"""
169183
# per PEP 425 (https://www.python.org/dev/peps/pep-0425/), wheel files shall have name of the form
170184
# {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
@@ -240,13 +254,12 @@ def expected_wheels(
240254
)
241255
]
242256

243-
wheels: list[str] = []
244-
245257
if platform == "pyodide":
246258
assert len(python_abi_tags) == 1
247259
python_abi_tag = python_abi_tags[0]
248260
platform_tag = "pyodide_2024_0_wasm32"
249-
return [f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"]
261+
yield f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"
262+
return
250263

251264
for python_abi_tag in python_abi_tags:
252265
platform_tags = []
@@ -317,12 +330,8 @@ def expected_wheels(
317330
msg = f"Unsupported platform {platform!r}"
318331
raise Exception(msg)
319332

320-
wheels.extend(
321-
f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"
322-
for platform_tag in platform_tags
323-
)
324-
325-
return wheels
333+
for platform_tag in platform_tags:
334+
yield f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"
326335

327336

328337
def get_macos_version() -> tuple[int, int]:

0 commit comments

Comments
 (0)