summaryrefslogtreecommitdiffstats
path: root/tests/test_build.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:26:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:26:28 +0000
commitbbbeb2d07d4f7fd0191032c219b40565fd83454f (patch)
tree3c08f1e09ed89a004867762ab40f3b610f6c0fa1 /tests/test_build.py
parentInitial commit. (diff)
downloadflit-bbbeb2d07d4f7fd0191032c219b40565fd83454f.tar.xz
flit-bbbeb2d07d4f7fd0191032c219b40565fd83454f.zip
Adding upstream version 3.8.0.upstream/3.8.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_build.py')
-rw-r--r--tests/test_build.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
new file mode 100644
index 0000000..59dd90e
--- /dev/null
+++ b/tests/test_build.py
@@ -0,0 +1,84 @@
+from pathlib import Path
+import pytest
+import shutil
+import sys
+from tempfile import TemporaryDirectory
+from testpath import assert_isdir, MockCommand
+
+from flit_core import common
+from flit import build
+
+samples_dir = Path(__file__).parent / 'samples'
+
+LIST_FILES_TEMPLATE = """\
+#!{python}
+import sys
+from os.path import join
+if '--deleted' not in sys.argv:
+ files = ['pyproject.toml', '{module}', 'EG_README.rst']
+ print('\\0'.join(files), end='\\0')
+"""
+
+def test_build_main(copy_sample):
+ td = copy_sample('module1_toml')
+ (td / '.git').mkdir() # Fake a git repo
+
+ with MockCommand('git', LIST_FILES_TEMPLATE.format(
+ python=sys.executable, module='module1.py')):
+ res = build.main(td / 'pyproject.toml')
+ assert res.wheel.file.suffix == '.whl'
+ assert res.sdist.file.name.endswith('.tar.gz')
+
+ assert_isdir(td / 'dist')
+
+def test_build_sdist_only(copy_sample):
+ td = copy_sample('module1_toml')
+ (td / '.git').mkdir() # Fake a git repo
+
+ with MockCommand('git', LIST_FILES_TEMPLATE.format(
+ python=sys.executable, module='module1.py')):
+ res = build.main(td / 'pyproject.toml', formats={'sdist'})
+ assert res.wheel is None
+
+ # Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5
+ assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.sdist.file)]
+
+def test_build_wheel_only(copy_sample):
+ td = copy_sample('module1_toml')
+ (td / '.git').mkdir() # Fake a git repo
+
+ with MockCommand('git', LIST_FILES_TEMPLATE.format(
+ python=sys.executable, module='module1.py')):
+ res = build.main(td / 'pyproject.toml', formats={'wheel'})
+ assert res.sdist is None
+
+ # Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5
+ assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.wheel.file)]
+
+def test_build_ns_main(copy_sample):
+ td = copy_sample('ns1-pkg')
+ (td / '.git').mkdir() # Fake a git repo
+
+ with MockCommand('git', LIST_FILES_TEMPLATE.format(
+ python=sys.executable, module='ns1/pkg/__init__.py')):
+ res = build.main(td / 'pyproject.toml')
+ assert res.wheel.file.suffix == '.whl'
+ assert res.sdist.file.name.endswith('.tar.gz')
+
+ assert_isdir(td / 'dist')
+
+
+def test_build_module_no_docstring():
+ with TemporaryDirectory() as td:
+ pyproject = Path(td, 'pyproject.toml')
+ shutil.copy(str(samples_dir / 'no_docstring-pkg.toml'), str(pyproject))
+ shutil.copy(str(samples_dir / 'no_docstring.py'), td)
+ shutil.copy(str(samples_dir / 'EG_README.rst'), td)
+ Path(td, '.git').mkdir() # Fake a git repo
+
+
+ with MockCommand('git', LIST_FILES_TEMPLATE.format(
+ python=sys.executable, module='no_docstring.py')):
+ with pytest.raises(common.NoDocstringError) as exc_info:
+ build.main(pyproject)
+ assert 'no_docstring.py' in str(exc_info.value)