Skip to content

Commit efe7c54

Browse files
committed
test: make mock git list untracked files
1 parent 6fc7aa4 commit efe7c54

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

tests/test_build.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,36 @@
1212

1313
LIST_FILES_TEMPLATE = """\
1414
#!{python}
15-
import sys
15+
import sys, posixpath
1616
tracked = {tracked}
17-
if '--deleted' not in sys.argv:
18-
for filename in tracked:
19-
print(filename, end="\\0")
17+
untracked_deleted = {untracked_deleted}
18+
19+
if '--deleted' in sys.argv:
20+
files = untracked_deleted
21+
else:
22+
files = tracked
23+
24+
for filename in map(posixpath.normpath, files):
25+
print(filename, end="\\0")
2026
"""
2127

2228
MODULE1_TOML_FILES = ["EG_README.rst", "module1.py", "pyproject.toml"]
2329

30+
def make_git_script(
31+
tracked = MODULE1_TOML_FILES,
32+
untracked_deleted = ["dist/module1-0.1.tar.gz"]
33+
):
34+
return LIST_FILES_TEMPLATE.format(
35+
python=sys.executable,
36+
tracked=tracked,
37+
untracked_deleted=untracked_deleted,
38+
)
39+
2440
def test_build_main(copy_sample):
2541
td = copy_sample('module1_toml')
2642
(td / '.git').mkdir() # Fake a git repo
2743

28-
with MockCommand('git', LIST_FILES_TEMPLATE.format(
29-
python=sys.executable, tracked=MODULE1_TOML_FILES)):
44+
with MockCommand('git', make_git_script()):
3045
res = build.main(td / 'pyproject.toml')
3146
assert res.wheel.file.suffix == '.whl'
3247
assert res.sdist.file.name.endswith('.tar.gz')
@@ -37,8 +52,7 @@ def test_build_sdist_only(copy_sample):
3752
td = copy_sample('module1_toml')
3853
(td / '.git').mkdir() # Fake a git repo
3954

40-
with MockCommand('git', LIST_FILES_TEMPLATE.format(
41-
python=sys.executable, tracked=MODULE1_TOML_FILES)):
55+
with MockCommand('git', make_git_script()):
4256
res = build.main(td / 'pyproject.toml', formats={'sdist'})
4357
assert res.wheel is None
4458

@@ -49,8 +63,7 @@ def test_build_wheel_only(copy_sample):
4963
td = copy_sample('module1_toml')
5064
(td / '.git').mkdir() # Fake a git repo
5165

52-
with MockCommand('git', LIST_FILES_TEMPLATE.format(
53-
python=sys.executable, tracked=MODULE1_TOML_FILES)):
66+
with MockCommand('git', make_git_script()):
5467
res = build.main(td / 'pyproject.toml', formats={'wheel'})
5568
assert res.sdist is None
5669

@@ -70,9 +83,19 @@ def test_build_module_no_docstring():
7083
"EG_README.rst",
7184
]
7285

73-
74-
with MockCommand('git', LIST_FILES_TEMPLATE.format(
75-
python=sys.executable, tracked=tracked)):
86+
with MockCommand('git', make_git_script(tracked=tracked)):
7687
with pytest.raises(common.NoDocstringError) as exc_info:
7788
build.main(pyproject)
7889
assert 'no_docstring.py' in str(exc_info.value)
90+
91+
def test_rebuild(copy_sample):
92+
"""
93+
build artifacts should not cause subsequent builds to fail if no other
94+
files were changed
95+
"""
96+
td = copy_sample('module1_toml')
97+
(td / '.git').mkdir() # Fake a git repo
98+
99+
with MockCommand('git', make_git_script()):
100+
res = build.main(td / 'pyproject.toml')
101+
res = build.main(td / 'pyproject.toml')

0 commit comments

Comments
 (0)