|
1 | 1 | import logging
|
| 2 | +import os |
2 | 3 | from pathlib import Path
|
3 | 4 | from typing import cast
|
4 | 5 | from unittest import mock
|
|
9 | 10 | from pip._internal.metadata import (
|
10 | 11 | BaseDistribution,
|
11 | 12 | get_directory_distribution,
|
| 13 | + get_environment, |
12 | 14 | get_wheel_distribution,
|
13 | 15 | )
|
14 | 16 | from pip._internal.metadata.base import FilesystemWheel
|
@@ -102,3 +104,28 @@ def test_metadata_dict(tmp_path: Path) -> None:
|
102 | 104 | metadata_dict = dist.metadata_dict
|
103 | 105 | assert metadata_dict["name"] == "pkga"
|
104 | 106 | assert metadata_dict["version"] == "1.0.1"
|
| 107 | + |
| 108 | + |
| 109 | +def test_no_dist_found_in_wheel(tmp_path: Path) -> None: |
| 110 | + location = os.fspath(tmp_path.joinpath("pkg-1-py3-none-any.whl")) |
| 111 | + make_wheel(name="pkg", version="1").save_to(location) |
| 112 | + assert get_environment([location]).get_distribution("pkg") is None |
| 113 | + |
| 114 | + |
| 115 | +def test_dist_found_in_directory_named_whl(tmp_path: Path) -> None: |
| 116 | + dir_path = tmp_path.joinpath("pkg-1-py3-none-any.whl") |
| 117 | + info_path = dir_path.joinpath("pkg-1.dist-info") |
| 118 | + info_path.mkdir(parents=True) |
| 119 | + info_path.joinpath("METADATA").write_text("Name: pkg") |
| 120 | + location = os.fspath(dir_path) |
| 121 | + dist = get_environment([location]).get_distribution("pkg") |
| 122 | + assert dist is not None and dist.location is not None |
| 123 | + assert Path(dist.location) == Path(location) |
| 124 | + |
| 125 | + |
| 126 | +def test_dist_found_in_zip(tmp_path: Path) -> None: |
| 127 | + location = os.fspath(tmp_path.joinpath("pkg.zip")) |
| 128 | + make_wheel(name="pkg", version="1").save_to(location) |
| 129 | + dist = get_environment([location]).get_distribution("pkg") |
| 130 | + assert dist is not None and dist.location is not None |
| 131 | + assert Path(dist.location) == Path(location) |
0 commit comments