|
1 | 1 | """Make sure that applying the configuration from pyproject.toml is equivalent to
|
2 | 2 | applying a similar configuration from setup.cfg
|
| 3 | +
|
| 4 | +To run these tests offline, please have a look on ``./downloads/preload.py`` |
3 | 5 | """
|
4 | 6 | import io
|
5 | 7 | import re
|
| 8 | +import tarfile |
6 | 9 | from pathlib import Path
|
7 |
| -from urllib.request import urlopen |
8 | 10 | from unittest.mock import Mock
|
| 11 | +from zipfile import ZipFile |
9 | 12 |
|
10 | 13 | import pytest
|
11 | 14 | from ini2toml.api import Translator
|
|
17 | 20 | from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField, _some_attrgetter
|
18 | 21 | from setuptools.command.egg_info import write_requirements
|
19 | 22 |
|
| 23 | +from .downloads import retrieve_file, urls_from_file |
| 24 | + |
20 | 25 |
|
21 |
| -EXAMPLES = (Path(__file__).parent / "setupcfg_examples.txt").read_text() |
22 |
| -EXAMPLE_URLS = [x for x in EXAMPLES.splitlines() if not x.startswith("#")] |
23 |
| -DOWNLOAD_DIR = Path(__file__).parent / "downloads" |
| 26 | +HERE = Path(__file__).parent |
| 27 | +EXAMPLES_FILE = "setupcfg_examples.txt" |
24 | 28 |
|
25 | 29 |
|
26 | 30 | def makedist(path, **attrs):
|
27 | 31 | return Distribution({"src_root": path, **attrs})
|
28 | 32 |
|
29 | 33 |
|
30 |
| -@pytest.mark.parametrize("url", EXAMPLE_URLS) |
| 34 | +@pytest.mark.parametrize("url", urls_from_file(HERE / EXAMPLES_FILE)) |
31 | 35 | @pytest.mark.filterwarnings("ignore")
|
32 | 36 | @pytest.mark.uses_network
|
33 | 37 | def test_apply_pyproject_equivalent_to_setupcfg(url, monkeypatch, tmp_path):
|
34 | 38 | monkeypatch.setattr(expand, "read_attr", Mock(return_value="0.0.1"))
|
35 |
| - setupcfg_example = retrieve_file(url, DOWNLOAD_DIR) |
| 39 | + setupcfg_example = retrieve_file(url) |
36 | 40 | pyproject_example = Path(tmp_path, "pyproject.toml")
|
37 | 41 | toml_config = Translator().translate(setupcfg_example.read_text(), "setup.cfg")
|
38 | 42 | pyproject_example.write_text(toml_config)
|
@@ -276,32 +280,19 @@ def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):
|
276 | 280 | assert "bar" in reqs
|
277 | 281 |
|
278 | 282 |
|
279 |
| -# --- Auxiliary Functions --- |
280 |
| - |
281 |
| - |
282 |
| -NAME_REMOVE = ("http://", "https://", "github.com/", "/raw/") |
| 283 | +class TestMeta: |
| 284 | + def test_example_file_in_sdist(self, setuptools_sdist): |
| 285 | + """Meta test to ensure tests can run from sdist""" |
| 286 | + with tarfile.open(setuptools_sdist) as tar: |
| 287 | + assert any(name.endswith(EXAMPLES_FILE) for name in tar.getnames()) |
283 | 288 |
|
| 289 | + def test_example_file_not_in_wheel(self, setuptools_wheel): |
| 290 | + """Meta test to ensure auxiliary test files are not in wheel""" |
| 291 | + with ZipFile(setuptools_wheel) as zipfile: |
| 292 | + assert not any(name.endswith(EXAMPLES_FILE) for name in zipfile.namelist()) |
284 | 293 |
|
285 |
| -def retrieve_file(url, download_dir): |
286 |
| - file_name = url.strip() |
287 |
| - for part in NAME_REMOVE: |
288 |
| - file_name = file_name.replace(part, '').strip().strip('/:').strip() |
289 |
| - file_name = re.sub(r"[^\-_\.\w\d]+", "_", file_name) |
290 |
| - path = Path(download_dir, file_name) |
291 |
| - if not path.exists(): |
292 |
| - download_dir.mkdir(exist_ok=True, parents=True) |
293 |
| - download(url, path) |
294 |
| - return path |
295 | 294 |
|
296 |
| - |
297 |
| -def download(url, dest): |
298 |
| - with urlopen(url) as f: |
299 |
| - data = f.read() |
300 |
| - |
301 |
| - with open(dest, "wb") as f: |
302 |
| - f.write(data) |
303 |
| - |
304 |
| - assert Path(dest).exists() |
| 295 | +# --- Auxiliary Functions --- |
305 | 296 |
|
306 | 297 |
|
307 | 298 | def core_metadata(dist) -> str:
|
|
0 commit comments