From 0792374ea856a3b6f24b2aba597122f3928a76e6 Mon Sep 17 00:00:00 2001 From: Benjamin Parzella Date: Mon, 6 Mar 2023 11:19:49 +0100 Subject: [PATCH 1/3] fix: generate xml report packages correctly on windows --- coverage/xmlreport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 65da11d23..fd2e9f81b 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -182,7 +182,7 @@ def xml_file(self, fr: FileReporter, analysis: Analysis, has_arcs: bool) -> None rel_name = filename[len(source_path)+1:] break else: - rel_name = fr.relative_filename() + rel_name = fr.relative_filename().replace("\\", "/") self.source_paths.add(fr.filename[:-len(rel_name)].rstrip(r"\/")) dirname = os.path.dirname(rel_name) or "." From 388285a60f5ad5eda7c227b5c15a3fe8f65df14e Mon Sep 17 00:00:00 2001 From: Benjamin Parzella Date: Mon, 13 Mar 2023 08:24:33 +0100 Subject: [PATCH 2/3] test: check duplicate package names in xml report --- tests/test_xml.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_xml.py b/tests/test_xml.py index c21a9dd4a..ec9a7141f 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -318,6 +318,36 @@ def test_accented_directory(self) -> None: "name": "รข", } + def test_no_duplicate_packages(self) -> None: + self.make_file("namespace/package/__init__.py", "from . import sample; from . import test; from .subpackage import test") + self.make_file("namespace/package/sample.py", "print('package.sample')") + self.make_file("namespace/package/test.py", "print('package.test')") + self.make_file("namespace/package/subpackage/test.py", "print('package.subpackage.test')") + + # no source path passed to coverage! + # problem occurs when they are dynamically generated during xml report + cov = coverage.Coverage() + + cov.start() + import_local_file("foo", "namespace/package/__init__.py") # pragma: nested + cov.stop() # pragma: nested + + cov.xml_report() + + dom = ElementTree.parse("coverage.xml") + + # only two packages should be present + packages = dom.findall(".//package") + assert len(packages) == 2 + + # one of them is namespace.package + named_package = dom.findall(".//package[@name='namespace.package']") + assert len(named_package) == 1 + + # the other one namespace.package.subpackage + named_sub_package = dom.findall(".//package[@name='namespace.package.subpackage']") + assert len(named_sub_package) == 1 + def unbackslash(v: Any) -> Any: """Find strings in `v`, and replace backslashes with slashes throughout.""" From afb6c7d4dd00bd9f76fc65b5692c56ad1023fdd3 Mon Sep 17 00:00:00 2001 From: Benjamin Parzella Date: Mon, 13 Mar 2023 08:30:50 +0100 Subject: [PATCH 3/3] fix: shorten long line in test_xml --- tests/test_xml.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_xml.py b/tests/test_xml.py index ec9a7141f..94b310e3e 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -319,7 +319,10 @@ def test_accented_directory(self) -> None: } def test_no_duplicate_packages(self) -> None: - self.make_file("namespace/package/__init__.py", "from . import sample; from . import test; from .subpackage import test") + self.make_file( + "namespace/package/__init__.py", + "from . import sample; from . import test; from .subpackage import test" + ) self.make_file("namespace/package/sample.py", "print('package.sample')") self.make_file("namespace/package/test.py", "print('package.test')") self.make_file("namespace/package/subpackage/test.py", "print('package.subpackage.test')")