diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-07-15 09:36:35 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-07-15 09:36:35 -0400 |
commit | 4d05ddeeded7f3f594c0614630f467e1bf3fa629 (patch) | |
tree | 593c06219447a5643a2326f698b55a242ba5bc78 /tests | |
parent | 0ff5a1c8a31f701321c838eea3beea553882b269 (diff) | |
download | python-coveragepy-git-4d05ddeeded7f3f594c0614630f467e1bf3fa629.tar.gz |
fix: generate flat file names differently
Fixes a few unusual issues with reports:
- #580: HTML report generation fails on too long path
- #584: File collisions in coverage report html
- #1167: Remove leading underscore in coverage html
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gold/annotate/anno_dir/d_80084bf2fba02475___init__.py,cover (renamed from tests/gold/annotate/anno_dir/a___init__.py,cover) | 0 | ||||
-rw-r--r-- | tests/gold/annotate/anno_dir/d_80084bf2fba02475_a.py,cover (renamed from tests/gold/annotate/anno_dir/a_a.py,cover) | 0 | ||||
-rw-r--r-- | tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2___init__.py,cover (renamed from tests/gold/annotate/anno_dir/b___init__.py,cover) | 0 | ||||
-rw-r--r-- | tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover (renamed from tests/gold/annotate/anno_dir/b_b.py,cover) | 0 | ||||
-rw-r--r-- | tests/test_files.py | 25 | ||||
-rw-r--r-- | tests/test_html.py | 13 | ||||
-rw-r--r-- | tests/test_process.py | 5 |
7 files changed, 28 insertions, 15 deletions
diff --git a/tests/gold/annotate/anno_dir/a___init__.py,cover b/tests/gold/annotate/anno_dir/d_80084bf2fba02475___init__.py,cover index e69de29b..e69de29b 100644 --- a/tests/gold/annotate/anno_dir/a___init__.py,cover +++ b/tests/gold/annotate/anno_dir/d_80084bf2fba02475___init__.py,cover diff --git a/tests/gold/annotate/anno_dir/a_a.py,cover b/tests/gold/annotate/anno_dir/d_80084bf2fba02475_a.py,cover index d0ff3c0c..d0ff3c0c 100644 --- a/tests/gold/annotate/anno_dir/a_a.py,cover +++ b/tests/gold/annotate/anno_dir/d_80084bf2fba02475_a.py,cover diff --git a/tests/gold/annotate/anno_dir/b___init__.py,cover b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2___init__.py,cover index e69de29b..e69de29b 100644 --- a/tests/gold/annotate/anno_dir/b___init__.py,cover +++ b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2___init__.py,cover diff --git a/tests/gold/annotate/anno_dir/b_b.py,cover b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover index 90d076f1..90d076f1 100644 --- a/tests/gold/annotate/anno_dir/b_b.py,cover +++ b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover diff --git a/tests/test_files.py b/tests/test_files.py index 98ece632..39a51d8c 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -69,18 +69,23 @@ class FilesTest(CoverageTest): @pytest.mark.parametrize("original, flat", [ - ("a/b/c.py", "a_b_c_py"), - (r"c:\foo\bar.html", "_foo_bar_html"), - ("Montréal/☺/conf.py", "Montréal_☺_conf_py"), + ("abc.py", "abc_py"), + ("hellothere", "hellothere"), + ("a/b/c.py", "d_86bbcbe134d28fd2_c_py"), + ("a/b/defghi.py", "d_86bbcbe134d28fd2_defghi_py"), + ("/a/b/c.py", "d_bb25e0ada04227c6_c_py"), + ("/a/b/defghi.py", "d_bb25e0ada04227c6_defghi_py"), + (r"c:\foo\bar.html", "d_e7c107482373f299_bar_html"), + (r"d:\foo\bar.html", "d_584a05dcebc67b46_bar_html"), + ("Montréal/☺/conf.py", "d_c840497a2c647ce0_conf_py"), ( # original: - r"c:\lorem\ipsum\quia\dolor\sit\amet\consectetur\adipisci\velit\sed\quia\non" - r"\numquam\eius\modi\tempora\incidunt\ut\labore\et\dolore\magnam\aliquam" - r"\quaerat\voluptatem\ut\enim\ad\minima\veniam\quis\nostrum\exercitationem" - r"\ullam\corporis\suscipit\laboriosam\Montréal\☺\my_program.py", + r"c:\lorem\ipsum\quia\dolor\sit\amet\consectetur\adipisci\velit\sed" + + r"\quia\non\numquam\eius\modi\tempora\incidunt\ut\labore\et\dolore" + + r"\magnam\aliquam\quaerat\voluptatem\ut\enim\ad\minima\veniam\quis" + + r"\nostrum\exercitationem\ullam\corporis\suscipit\laboriosam" + + r"\Montréal\☺\my_program.py", # flat: - "re_et_dolore_magnam_aliquam_quaerat_voluptatem_ut_enim_ad_minima_veniam_quis_" - "nostrum_exercitationem_ullam_corporis_suscipit_laboriosam_Montréal_☺_my_program_py_" - "97eaca41b860faaa1a21349b1f3009bb061cf0a8" + "d_e597dfacb73a23d5_my_program_py" ), ]) def test_flat_rootname(original, flat): diff --git a/tests/test_html.py b/tests/test_html.py index 56519a64..a0ab2d4a 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -56,7 +56,7 @@ class HtmlTestHelpers(CoverageTest): def get_html_report_content(self, module): """Return the content of the HTML report for `module`.""" - filename = module.replace(".", "_").replace("/", "_") + ".html" + filename = flat_rootname(module) + ".html" filename = os.path.join("htmlcov", filename) with open(filename) as f: return f.read() @@ -617,7 +617,7 @@ def filepath_to_regex(path): return regex -def compare_html(expected, actual): +def compare_html(expected, actual, extra_scrubs=None): """Specialized compare function for our HTML files.""" scrubs = [ (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'), @@ -640,6 +640,8 @@ def compare_html(expected, actual): if env.WINDOWS: # For file paths... scrubs += [(r"\\", "/")] + if extra_scrubs: + scrubs += extra_scrubs compare(expected, actual, file_pattern="*.html", scrubs=scrubs) @@ -897,7 +899,12 @@ assert len(math) == 18 for p in glob.glob("out/other/*_other_py.html"): os.rename(p, "out/other/blah_blah_other_py.html") - compare_html(gold_path("html/other"), "out/other") + compare_html( + gold_path("html/other"), "out/other", + extra_scrubs=[ + (r'href="d_[0-9a-z]{16}_', 'href="_TEST_TMPDIR_othersrc_'), + ], + ) contains( "out/other/index.html", '<a href="here_py.html">here.py</a>', diff --git a/tests/test_process.py b/tests/test_process.py index 04a8a2d5..58915b87 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1332,10 +1332,11 @@ class UnicodeFilePathsTest(CoverageTest): # The HTML report uses ascii-encoded HTML entities. out = self.run_command("coverage html") assert out == "" - self.assert_exists("htmlcov/\xe2_accented_py.html") + self.assert_exists("htmlcov/d_5786906b6f0ffeb4_accented_py.html") with open("htmlcov/index.html") as indexf: index = indexf.read() - assert '<a href="â_accented_py.html">â%saccented.py</a>' % os.sep in index + expected = '<a href="d_5786906b6f0ffeb4_accented_py.html">â%saccented.py</a>' + assert expected % os.sep in index # The XML report is always UTF8-encoded. out = self.run_command("coverage xml") |