Skip to content

Commit

Permalink
tests: add SDist test
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jan 27, 2023
1 parent 8617e02 commit 7edc0c3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install the project
run: pip install --no-binary=wheel .
- name: Install test dependencies
run: pip install .[test] coverage[toml]
run: pip install .[test] coverage[toml] build flit
- name: Test with pytest
run: |
coverage run -m pytest -W always
Expand Down
48 changes: 48 additions & 0 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import subprocess
import sys
import tarfile
from pathlib import Path

import pytest

pytest.importorskip("flit")
pytest.importorskip("build")

# This test must be run from the source directory - okay to skip if not
DIR = os.path.abspath(os.path.dirname(__file__))
MAIN_DIR = os.path.dirname(DIR)


def test_compare_sdists(monkeypatch, tmpdir):
monkeypatch.chdir(MAIN_DIR)

sdist_build_dir = os.path.join(str(tmpdir), "bdir")

subprocess.run(
[
sys.executable,
"-m",
"build",
"--sdist",
"--no-isolation",
f"--outdir={sdist_build_dir}",
],
check=True,
)

(sdist_build,) = Path(sdist_build_dir).glob("*.tar.gz")

# Flit doesn't allow targeting directories, as far as I can tell
subprocess.run(
[sys.executable, "-m", "flit", "build", "--format=sdist"], check=True
)

(sdist_flit,) = Path("dist").glob("*.tar.gz")

out = [set(), set()]
for i, sdist in enumerate([sdist_build, sdist_flit]):
with tarfile.open(str(sdist), "r:gz") as tar:
out[i] = set(tar.getnames())

assert out[0] == (out[1] - {"setup.py"})
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py37, py38, py39, py310, py311, pypy3, lint
envlist = py37, py38, py39, py310, py311, pypy3, lint, pkg
minversion = 3.3.0
skip_missing_interpreters = true
isolated_build = true
Expand All @@ -20,3 +20,10 @@ basepython = python3
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure
skip_install = true

[testenv:pkg]
basepython = python3
deps =
build
flit
commands = {envpython} -b -m pytest tests/test_sdist.py {posargs}

0 comments on commit 7edc0c3

Please sign in to comment.