Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonFileReporter: do not expect files without a filename extension to contain Python code #1489

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions coverage/python.py
Expand Up @@ -244,9 +244,6 @@ def should_be_python(self) -> bool:
# Anything named *.py* should be Python.
if ext.startswith(".py"):
return True
# A file with no extension should be Python.
if not ext:
return True
# Everything else is probably not Python.
return False

Expand Down
7 changes: 7 additions & 0 deletions tests/test_filereporter.py
Expand Up @@ -102,3 +102,10 @@ def test_zipfile(self) -> None:
z1z1 = PythonFileReporter(zip1.zip1)
assert z1.source() == ""
assert "# My zip file!" in z1z1.source().splitlines()

def test_python_extensions(self) -> None:
f1 = PythonFileReporter("afile.py")
f2 = PythonFileReporter("Makefile")

assert f1.should_be_python()
assert not f2.should_be_python()