Skip to content

Commit

Permalink
Add pathlib.Path support to test WheelBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jun 6, 2022
1 parent 0fa5f10 commit e3db108
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions tests/lib/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
import csv
import itertools
import pathlib
from base64 import urlsafe_b64encode
from collections import namedtuple
from copy import deepcopy
Expand Down Expand Up @@ -252,23 +253,23 @@ def __init__(self, name: str, files: Iterable[File]) -> None:
self._name = name
self._files = files

def save_to_dir(self, path: Union[Path, str]) -> str:
def save_to_dir(self, path: Union[Path, pathlib.Path, str]) -> str:
"""Generate wheel file with correct name and save into the provided
directory.
:returns the wheel file path
"""
p = Path(path) / self._name
p = pathlib.Path(path) / self._name
p.write_bytes(self.as_bytes())
return str(p)

def save_to(self, path: Union[Path, str]) -> str:
def save_to(self, path: Union[Path, pathlib.Path, str]) -> str:
"""Generate wheel file, saving to the provided path. Any parent
directories must already exist.
:returns the wheel file path
"""
path = Path(path)
path = pathlib.Path(path)
path.write_bytes(self.as_bytes())
return str(path)

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/metadata/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from pathlib import Path
from typing import cast
from unittest import mock

Expand All @@ -8,7 +9,6 @@
from pip._internal.metadata import BaseDistribution, get_wheel_distribution
from pip._internal.metadata.base import FilesystemWheel
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, ArchiveInfo
from tests.lib.path import Path
from tests.lib.wheel import make_wheel


Expand Down Expand Up @@ -60,13 +60,13 @@ class FakeDistribution(BaseDistribution):
assert isinstance(direct_url.info, ArchiveInfo)


def test_json_metadata(tmpdir: Path) -> None:
def test_json_metadata(tmp_path: Path) -> None:
"""Basic test of BaseDistribution json_metadata.
More tests are available in the original pkg_metadata project where this
function comes from, and which we may vendor in the future.
"""
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmpdir)
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmp_path)
wheel = FilesystemWheel(wheel_path)
dist = get_wheel_distribution(wheel, "pkga")
json_metadata = dist.json_metadata
Expand Down

0 comments on commit e3db108

Please sign in to comment.