diff --git a/tests/test_build.py b/tests/test_build.py index eeadaf64..a3eb7508 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -12,21 +12,36 @@ LIST_FILES_TEMPLATE = """\ #!{python} -import sys +import sys, posixpath tracked = {tracked} -if '--deleted' not in sys.argv: - for filename in tracked: - print(filename, end="\\0") +untracked_deleted = {untracked_deleted} + +if '--deleted' in sys.argv: + files = untracked_deleted +else: + files = tracked + +for filename in map(posixpath.normpath, files): + print(filename, end="\\0") """ MODULE1_TOML_FILES = ["EG_README.rst", "module1.py", "pyproject.toml"] +def make_git_script( + tracked = MODULE1_TOML_FILES, + untracked_deleted = ["dist/module1-0.1.tar.gz"] +): + return LIST_FILES_TEMPLATE.format( + python=sys.executable, + tracked=tracked, + untracked_deleted=untracked_deleted, + ) + 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, tracked=MODULE1_TOML_FILES)): + with MockCommand('git', make_git_script()): res = build.main(td / 'pyproject.toml') assert res.wheel.file.suffix == '.whl' assert res.sdist.file.name.endswith('.tar.gz') @@ -37,8 +52,7 @@ 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, tracked=MODULE1_TOML_FILES)): + with MockCommand('git', make_git_script()): res = build.main(td / 'pyproject.toml', formats={'sdist'}) assert res.wheel is None @@ -49,8 +63,7 @@ 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, tracked=MODULE1_TOML_FILES)): + with MockCommand('git', make_git_script()): res = build.main(td / 'pyproject.toml', formats={'wheel'}) assert res.sdist is None @@ -70,9 +83,19 @@ def test_build_module_no_docstring(): "EG_README.rst", ] - - with MockCommand('git', LIST_FILES_TEMPLATE.format( - python=sys.executable, tracked=tracked)): + with MockCommand('git', make_git_script(tracked=tracked)): with pytest.raises(common.NoDocstringError) as exc_info: build.main(pyproject) assert 'no_docstring.py' in str(exc_info.value) + +def test_rebuild(copy_sample): + """ + build artifacts should not cause subsequent builds to fail if no other + files were changed + """ + td = copy_sample('module1_toml') + (td / '.git').mkdir() # Fake a git repo + + with MockCommand('git', make_git_script()): + res = build.main(td / 'pyproject.toml') + res = build.main(td / 'pyproject.toml')