Skip to content

Commit

Permalink
test: make mock git list untracked files
Browse files Browse the repository at this point in the history
  • Loading branch information
mawillcockson committed Dec 4, 2021
1 parent aadee0d commit 0b44c88
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -83,9 +96,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')

0 comments on commit 0b44c88

Please sign in to comment.