Skip to content

Commit 120ce25

Browse files
authored
tests: clean up a few collections.namedtuple (#1070)
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent 7c03071 commit 120ce25

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

tests/test_markers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
from __future__ import annotations
66

7-
import collections
87
import itertools
98
import os
109
import platform
1110
import sys
12-
from typing import cast
11+
from typing import NamedTuple, cast
1312
from unittest import mock
1413

1514
import pytest
@@ -110,9 +109,12 @@ def test_allows_prerelease(self) -> None:
110109
)
111110

112111

113-
FakeVersionInfo = collections.namedtuple(
114-
"FakeVersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]
115-
)
112+
class FakeVersionInfo(NamedTuple):
113+
major: int
114+
minor: int
115+
micro: int
116+
releaselevel: str
117+
serial: int
116118

117119

118120
class TestDefaultEnvironment:

tests/test_musllinux.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import collections
43
import pathlib
54
import subprocess
65
import typing
@@ -14,6 +13,11 @@
1413
if typing.TYPE_CHECKING:
1514
from collections.abc import Generator
1615

16+
17+
class Proc(typing.NamedTuple):
18+
stderr: str
19+
20+
1721
MUSL_AMD64 = "musl libc (x86_64)\nVersion 1.2.2\n"
1822
MUSL_I386 = "musl libc (i386)\nVersion 1.2.1\n"
1923
MUSL_AARCH64 = "musl libc (aarch64)\nVersion 1.1.24\n"
@@ -71,8 +75,8 @@ def test_get_musl_version(
7175
version: _MuslVersion | None,
7276
ld_musl: str | None,
7377
) -> None:
74-
def mock_run(*args: object, **kwargs: object) -> tuple[object, ...]:
75-
return collections.namedtuple("Proc", "stderr")(output)
78+
def mock_run(*args: object, **kwargs: object) -> Proc:
79+
return Proc(stderr=output)
7680

7781
run_recorder = pretend.call_recorder(mock_run)
7882
monkeypatch.setattr(_musllinux.subprocess, "run", run_recorder) # type: ignore[attr-defined]

tests/test_tags.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
from collections.abc import Callable
3434

3535

36+
class AndroidVer(typing.NamedTuple):
37+
release: str
38+
api_level: int
39+
manufacturer: str
40+
model: str
41+
device: str
42+
is_emulator: bool
43+
44+
3645
@pytest.fixture
3746
def example_tag() -> tags.Tag:
3847
return tags.Tag("py3", "none", "any")
@@ -89,9 +98,6 @@ def mock_android(monkeypatch: pytest.MonkeyPatch) -> None:
8998
monkeypatch.setattr(platform, "system", lambda: "Android")
9099
monkeypatch.setattr(sysconfig, "get_platform", lambda: "android-21-arm64_v8a")
91100

92-
AndroidVer = collections.namedtuple(
93-
"AndroidVer", "release api_level manufacturer model device is_emulator"
94-
)
95101
monkeypatch.setattr(
96102
platform,
97103
"android_ver",

0 commit comments

Comments
 (0)