| 1 |
from pathlib import Path |
| 2 |
import pytest |
| 3 |
import shutil |
| 4 |
import sys |
| 5 |
from tempfile import TemporaryDirectory |
| 6 |
from testpath import assert_isdir, MockCommand |
| 7 |
|
| 8 |
from flit_core import common |
| 9 |
from flit import build |
| 10 |
|
| 11 |
samples_dir = Path(__file__).parent / 'samples' |
| 12 |
|
| 13 |
LIST_FILES_TEMPLATE = """\ |
| 14 |
#!{python} |
| 15 |
import sys |
| 16 |
from os.path import join |
| 17 |
if '--deleted' not in sys.argv: |
| 18 |
files = ['pyproject.toml', '{module}', 'EG_README.rst'] |
| 19 |
print('\\0'.join(files), end='\\0') |
| 20 |
""" |
| 21 |
|
| 22 |
def test_build_main(copy_sample): |
| 23 |
td = copy_sample('module1_toml') |
| 24 |
(td / '.git').mkdir() # Fake a git repo |
| 25 |
|
| 26 |
with MockCommand('git', LIST_FILES_TEMPLATE.format( |
| 27 |
python=sys.executable, module='module1.py')): |
| 28 |
res = build.main(td / 'pyproject.toml') |
| 29 |
assert res.wheel.file.suffix == '.whl' |
| 30 |
assert res.sdist.file.name.endswith('.tar.gz') |
| 31 |
|
| 32 |
assert_isdir(td / 'dist') |
| 33 |
|
| 34 |
def test_build_sdist_only(copy_sample): |
| 35 |
td = copy_sample('module1_toml') |
| 36 |
(td / '.git').mkdir() # Fake a git repo |
| 37 |
|
| 38 |
with MockCommand('git', LIST_FILES_TEMPLATE.format( |
| 39 |
python=sys.executable, module='module1.py')): |
| 40 |
res = build.main(td / 'pyproject.toml', formats={'sdist'}) |
| 41 |
assert res.wheel is None |
| 42 |
|
| 43 |
# Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5 |
| 44 |
assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.sdist.file)] |
| 45 |
|
| 46 |
def test_build_wheel_only(copy_sample): |
| 47 |
td = copy_sample('module1_toml') |
| 48 |
(td / '.git').mkdir() # Fake a git repo |
| 49 |
|
| 50 |
with MockCommand('git', LIST_FILES_TEMPLATE.format( |
| 51 |
python=sys.executable, module='module1.py')): |
| 52 |
res = build.main(td / 'pyproject.toml', formats={'wheel'}) |
| 53 |
assert res.sdist is None |
| 54 |
|
| 55 |
# Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5 |
| 56 |
assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.wheel.file)] |
| 57 |
|
| 58 |
def test_build_ns_main(copy_sample): |
| 59 |
td = copy_sample('ns1-pkg') |
| 60 |
(td / '.git').mkdir() # Fake a git repo |
| 61 |
|
| 62 |
with MockCommand('git', LIST_FILES_TEMPLATE.format( |
| 63 |
python=sys.executable, module='ns1/pkg/__init__.py')): |
| 64 |
res = build.main(td / 'pyproject.toml') |
| 65 |
assert res.wheel.file.suffix == '.whl' |
| 66 |
assert res.sdist.file.name.endswith('.tar.gz') |
| 67 |
|
| 68 |
assert_isdir(td / 'dist') |
| 69 |
|
| 70 |
|
| 71 |
def test_build_module_no_docstring(): |
| 72 |
with TemporaryDirectory() as td: |
| 73 |
pyproject = Path(td, 'pyproject.toml') |
| 74 |
shutil.copy(str(samples_dir / 'no_docstring-pkg.toml'), str(pyproject)) |
| 75 |
shutil.copy(str(samples_dir / 'no_docstring.py'), td) |
| 76 |
shutil.copy(str(samples_dir / 'EG_README.rst'), td) |
| 77 |
Path(td, '.git').mkdir() # Fake a git repo |
| 78 |
|
| 79 |
|
| 80 |
with MockCommand('git', LIST_FILES_TEMPLATE.format( |
| 81 |
python=sys.executable, module='no_docstring.py')): |
| 82 |
with pytest.raises(common.NoDocstringError) as exc_info: |
| 83 |
build.main(pyproject) |
| 84 |
assert 'no_docstring.py' in str(exc_info.value) |