-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathtest_dists.py
More file actions
47 lines (34 loc) · 1.48 KB
/
test_dists.py
File metadata and controls
47 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
import sys
import tarfile
import zipfile
from pathlib import Path
import pytest
from gitlab._version import __title__, __version__
DOCS_DIR = "docs"
TEST_DIR = "tests"
DIST_NORMALIZED_TITLE = f"{__title__.replace('-', '_')}-{__version__}"
SDIST_FILE = f"{DIST_NORMALIZED_TITLE}.tar.gz"
WHEEL_FILE = f"{DIST_NORMALIZED_TITLE}-py{sys.version_info.major}-none-any.whl"
PY_TYPED = "gitlab/py.typed"
@pytest.fixture(scope="session")
def build(tmp_path_factory: pytest.TempPathFactory):
temp_dir = tmp_path_factory.mktemp("build")
subprocess.run([sys.executable, "-m", "build", "--outdir", temp_dir], check=True)
return temp_dir
def test_sdist_includes_correct_files(build: Path) -> None:
sdist = tarfile.open(build / SDIST_FILE, "r:gz")
docs_dir = sdist.getmember(f"{DIST_NORMALIZED_TITLE}/{DOCS_DIR}")
test_dir = sdist.getmember(f"{DIST_NORMALIZED_TITLE}/{TEST_DIR}")
readme = sdist.getmember(f"{DIST_NORMALIZED_TITLE}/README.rst")
py_typed = sdist.getmember(f"{DIST_NORMALIZED_TITLE}/{PY_TYPED}")
assert docs_dir.isdir()
assert test_dir.isdir()
assert py_typed.isfile()
assert readme.isfile()
def test_wheel_includes_correct_files(build: Path) -> None:
wheel = zipfile.ZipFile(build / WHEEL_FILE)
assert PY_TYPED in wheel.namelist()
def test_wheel_excludes_docs_and_tests(build: Path) -> None:
wheel = zipfile.ZipFile(build / WHEEL_FILE)
assert not any(file.startswith((DOCS_DIR, TEST_DIR)) for file in wheel.namelist())