Skip to content

Commit 5c71d1e

Browse files
committed
test_makefile_warts
1 parent 16b1bd6 commit 5c71d1e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

testing/test_pytester.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,35 @@ def test_makefile_joins_absolute_path(testdir: Testdir) -> None:
894894
else:
895895
p1 = testdir.makepyfile(**{str(absfile): ""})
896896
assert str(p1) == (testdir.tmpdir / absfile) + ".py"
897+
898+
899+
def test_makefile_warts(testdir: Testdir) -> None:
900+
"""Test behavior with makefile.
901+
902+
Additional issues:
903+
- always strips and dedents.
904+
"""
905+
# Requires "ext".
906+
with pytest.raises(TypeError, match="required positional argument"):
907+
testdir.makefile(foo="") # type: ignore[call-arg] # noqa: F821
908+
909+
# Cannot create a file named "ext".
910+
p1 = testdir.makefile(ext="")
911+
assert p1 is None
912+
assert testdir.tmpdir.listdir() == []
913+
914+
with pytest.raises(TypeError, match="got multiple values for argument 'ext'"):
915+
testdir.makefile("", ext="") # type: ignore[misc] # noqa: F821
916+
917+
# However, "ext.py" can be created via `makepyfile` at least.
918+
p1 = testdir.makepyfile(ext="")
919+
assert p1.basename == "ext.py"
920+
921+
# Replaces any "ext".
922+
p1 = testdir.makefile(ext="txt", **{"foo.txt": ""})
923+
assert p1.basename == "foo.txt"
924+
# Even if empty. Could allow for None to skip it.
925+
p1 = testdir.makefile(ext="", **{"foo.txt.txt": ""})
926+
assert p1.basename == "foo.txt"
927+
p1 = testdir.makefile(ext="", **{"foo.txt.txt.meh": ""})
928+
assert p1.basename == "foo.txt.txt"

0 commit comments

Comments
 (0)