From c94a0d5b4907a4da2006f533730d3e5c2467c631 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 16 Nov 2022 13:49:34 +0000 Subject: [PATCH 1/4] PythonFileReporter: do not expect files without a filename extension to contain Python code --- coverage/python.py | 3 --- tests/test_filereporter.py | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/coverage/python.py b/coverage/python.py index 089c27ea6..057cd6061 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -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 diff --git a/tests/test_filereporter.py b/tests/test_filereporter.py index c36fa013b..a0bcac13f 100644 --- a/tests/test_filereporter.py +++ b/tests/test_filereporter.py @@ -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): + f1 = PythonFileReporter("afile.py") + f2 = PythonFileReporter("Makefile") + + assert f1.should_be_python() + assert not f2.should_be_python() From 69e6ef0de4530c5c1b6ff687fcbfe1a2749c2019 Mon Sep 17 00:00:00 2001 From: James Addison Date: Fri, 10 May 2024 00:09:58 +0100 Subject: [PATCH 2/4] PythonFileReporter: add ``.jinja*`` to filename extensions expected to be evaluated using Python code. --- coverage/python.py | 3 +++ tests/test_filereporter.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/coverage/python.py b/coverage/python.py index 057cd6061..e0bd08395 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -244,6 +244,9 @@ def should_be_python(self) -> bool: # Anything named *.py* should be Python. if ext.startswith(".py"): return True + # Jinja templates are evaluated using Python. + if ext.startswith('.jinja'): + return True # Everything else is probably not Python. return False diff --git a/tests/test_filereporter.py b/tests/test_filereporter.py index a0bcac13f..5064081dc 100644 --- a/tests/test_filereporter.py +++ b/tests/test_filereporter.py @@ -106,6 +106,8 @@ def test_zipfile(self) -> None: def test_python_extensions(self): f1 = PythonFileReporter("afile.py") f2 = PythonFileReporter("Makefile") + f3 = PythonFileReporter("template.jinja") assert f1.should_be_python() assert not f2.should_be_python() + assert f3.should_be_python() From 5c3e4201d9174e0d22bc74f3c47a6ea24cbb0563 Mon Sep 17 00:00:00 2001 From: James Addison Date: Fri, 10 May 2024 00:14:10 +0100 Subject: [PATCH 3/4] Linting: add empty-return-type annotation to test case. --- tests/test_filereporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_filereporter.py b/tests/test_filereporter.py index 5064081dc..1d072daea 100644 --- a/tests/test_filereporter.py +++ b/tests/test_filereporter.py @@ -103,7 +103,7 @@ def test_zipfile(self) -> None: assert z1.source() == "" assert "# My zip file!" in z1z1.source().splitlines() - def test_python_extensions(self): + def test_python_extensions(self) -> None: f1 = PythonFileReporter("afile.py") f2 = PythonFileReporter("Makefile") f3 = PythonFileReporter("template.jinja") From 5e7134c5e48653402eee8b2e48aff23d3baacf05 Mon Sep 17 00:00:00 2001 From: James Addison Date: Fri, 10 May 2024 11:12:06 +0100 Subject: [PATCH 4/4] Revert "PythonFileReporter: add ``.jinja*`` to filename extensions expected to be evaluated using Python code." This reverts commit 69e6ef0de4530c5c1b6ff687fcbfe1a2749c2019. --- coverage/python.py | 3 --- tests/test_filereporter.py | 2 -- 2 files changed, 5 deletions(-) diff --git a/coverage/python.py b/coverage/python.py index e0bd08395..057cd6061 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -244,9 +244,6 @@ def should_be_python(self) -> bool: # Anything named *.py* should be Python. if ext.startswith(".py"): return True - # Jinja templates are evaluated using Python. - if ext.startswith('.jinja'): - return True # Everything else is probably not Python. return False diff --git a/tests/test_filereporter.py b/tests/test_filereporter.py index 1d072daea..b273d6193 100644 --- a/tests/test_filereporter.py +++ b/tests/test_filereporter.py @@ -106,8 +106,6 @@ def test_zipfile(self) -> None: def test_python_extensions(self) -> None: f1 = PythonFileReporter("afile.py") f2 = PythonFileReporter("Makefile") - f3 = PythonFileReporter("template.jinja") assert f1.should_be_python() assert not f2.should_be_python() - assert f3.should_be_python()