| 1 |
from io import BytesIO |
| 2 |
import os.path as osp |
| 3 |
from pathlib import Path |
| 4 |
import tarfile |
| 5 |
from testpath import assert_isfile |
| 6 |
|
| 7 |
from flit_core import sdist |
| 8 |
|
| 9 |
samples_dir = Path(__file__).parent / 'samples' |
| 10 |
|
| 11 |
def test_make_sdist(tmp_path): |
| 12 |
# Smoke test of making a complete sdist |
| 13 |
builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'package1.toml') |
| 14 |
builder.build(tmp_path) |
| 15 |
assert_isfile(tmp_path / 'package1-0.1.tar.gz') |
| 16 |
|
| 17 |
|
| 18 |
def test_make_sdist_pep621(tmp_path): |
| 19 |
builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'pep621' / 'pyproject.toml') |
| 20 |
path = builder.build(tmp_path) |
| 21 |
assert path == tmp_path / 'module1-0.1.tar.gz' |
| 22 |
assert_isfile(path) |
| 23 |
|
| 24 |
|
| 25 |
def test_make_sdist_pep621_nodynamic(tmp_path): |
| 26 |
builder = sdist.SdistBuilder.from_ini_path( |
| 27 |
samples_dir / 'pep621_nodynamic' / 'pyproject.toml' |
| 28 |
) |
| 29 |
path = builder.build(tmp_path) |
| 30 |
assert path == tmp_path / 'module1-0.3.tar.gz' |
| 31 |
assert_isfile(path) |
| 32 |
|
| 33 |
|
| 34 |
def test_clean_tarinfo(): |
| 35 |
with tarfile.open(mode='w', fileobj=BytesIO()) as tf: |
| 36 |
ti = tf.gettarinfo(str(samples_dir / 'module1.py')) |
| 37 |
cleaned = sdist.clean_tarinfo(ti, mtime=42) |
| 38 |
assert cleaned.uid == 0 |
| 39 |
assert cleaned.uname == '' |
| 40 |
assert cleaned.mtime == 42 |
| 41 |
|
| 42 |
|
| 43 |
def test_include_exclude(): |
| 44 |
builder = sdist.SdistBuilder.from_ini_path( |
| 45 |
samples_dir / 'inclusion' / 'pyproject.toml' |
| 46 |
) |
| 47 |
files = builder.apply_includes_excludes(builder.select_files()) |
| 48 |
|
| 49 |
assert osp.join('doc', 'test.rst') in files |
| 50 |
assert osp.join('doc', 'test.txt') not in files |
| 51 |
assert osp.join('doc', 'subdir', 'test.txt') in files |
| 52 |
assert osp.join('doc', 'subdir', 'subsubdir', 'test.md') not in files |
| 53 |
|
| 54 |
|
| 55 |
def test_data_dir(): |
| 56 |
builder = sdist.SdistBuilder.from_ini_path( |
| 57 |
samples_dir / 'with_data_dir' / 'pyproject.toml' |
| 58 |
) |
| 59 |
files = builder.apply_includes_excludes(builder.select_files()) |
| 60 |
|
| 61 |
assert osp.join('data', 'share', 'man', 'man1', 'foo.1') in files |
| 62 |
|
| 63 |
|
| 64 |
def test_pep625(tmp_path): |
| 65 |
builder = sdist.SdistBuilder.from_ini_path( |
| 66 |
samples_dir / 'normalization' / 'pyproject.toml' |
| 67 |
) |
| 68 |
path = builder.build(tmp_path) |
| 69 |
assert path == tmp_path / 'my_python_module-0.0.1.tar.gz' |
| 70 |
assert_isfile(path) |
| 71 |
|
| 72 |
def test_license_inside_src(tmp_path): |
| 73 |
builder = sdist.SdistBuilder.from_ini_path( |
| 74 |
samples_dir / 'license_in_src' / 'pyproject.toml' |
| 75 |
) |
| 76 |
path = builder.build(tmp_path) |
| 77 |
|
| 78 |
with tarfile.open(path, 'r|*') as tar: |
| 79 |
lic_count = sum( |
| 80 |
1 for member in iter(tar.next, None) |
| 81 |
if member.name == 'license_in_src-0/license_in_src/lic.txt' |
| 82 |
) |
| 83 |
|
| 84 |
assert lic_count == 1 |