Skip to content

Commit e3db108

Browse files
committed
Add pathlib.Path support to test WheelBuilder
1 parent 0fa5f10 commit e3db108

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/lib/wheel.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
import csv
44
import itertools
5+
import pathlib
56
from base64 import urlsafe_b64encode
67
from collections import namedtuple
78
from copy import deepcopy
@@ -252,23 +253,23 @@ def __init__(self, name: str, files: Iterable[File]) -> None:
252253
self._name = name
253254
self._files = files
254255

255-
def save_to_dir(self, path: Union[Path, str]) -> str:
256+
def save_to_dir(self, path: Union[Path, pathlib.Path, str]) -> str:
256257
"""Generate wheel file with correct name and save into the provided
257258
directory.
258259
259260
:returns the wheel file path
260261
"""
261-
p = Path(path) / self._name
262+
p = pathlib.Path(path) / self._name
262263
p.write_bytes(self.as_bytes())
263264
return str(p)
264265

265-
def save_to(self, path: Union[Path, str]) -> str:
266+
def save_to(self, path: Union[Path, pathlib.Path, str]) -> str:
266267
"""Generate wheel file, saving to the provided path. Any parent
267268
directories must already exist.
268269
269270
:returns the wheel file path
270271
"""
271-
path = Path(path)
272+
path = pathlib.Path(path)
272273
path.write_bytes(self.as_bytes())
273274
return str(path)
274275

tests/unit/metadata/test_metadata.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from pathlib import Path
23
from typing import cast
34
from unittest import mock
45

@@ -8,7 +9,6 @@
89
from pip._internal.metadata import BaseDistribution, get_wheel_distribution
910
from pip._internal.metadata.base import FilesystemWheel
1011
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, ArchiveInfo
11-
from tests.lib.path import Path
1212
from tests.lib.wheel import make_wheel
1313

1414

@@ -60,13 +60,13 @@ class FakeDistribution(BaseDistribution):
6060
assert isinstance(direct_url.info, ArchiveInfo)
6161

6262

63-
def test_json_metadata(tmpdir: Path) -> None:
63+
def test_json_metadata(tmp_path: Path) -> None:
6464
"""Basic test of BaseDistribution json_metadata.
6565
6666
More tests are available in the original pkg_metadata project where this
6767
function comes from, and which we may vendor in the future.
6868
"""
69-
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmpdir)
69+
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmp_path)
7070
wheel = FilesystemWheel(wheel_path)
7171
dist = get_wheel_distribution(wheel, "pkga")
7272
json_metadata = dist.json_metadata

0 commit comments

Comments
 (0)