summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/gold/html/styled/style.css8
-rw-r--r--tests/goldtest.py17
-rw-r--r--tests/test_html.py22
3 files changed, 32 insertions, 15 deletions
diff --git a/tests/gold/html/styled/style.css b/tests/gold/html/styled/style.css
index 9cbe5fad..910a779e 100644
--- a/tests/gold/html/styled/style.css
+++ b/tests/gold/html/styled/style.css
@@ -140,7 +140,7 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em
#source { padding: 1em 0 1em 3.5rem; font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
-#source p { margin-top: -4em; padding-top: 4em; position: relative; white-space: pre; }
+#source p { position: relative; white-space: pre; }
#source p * { box-sizing: border-box; }
@@ -148,7 +148,9 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em
@media (prefers-color-scheme: dark) { #source p .n { color: #777; } }
-#source p .n a { text-decoration: none; color: #999; }
+#source p .n.highlight { background: #ffdd00; }
+
+#source p .n a { margin-top: -4em; padding-top: 4em; text-decoration: none; color: #999; }
@media (prefers-color-scheme: dark) { #source p .n a { color: #777; } }
@@ -156,8 +158,6 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em
@media (prefers-color-scheme: dark) { #source p .n a:hover { color: #777; } }
-#source p.highlight .n { background: #ffdd00; }
-
#source p .t { display: inline-block; width: 100%; box-sizing: border-box; margin-left: -.5em; padding-left: 0.3em; border-left: 0.2em solid #fff; }
@media (prefers-color-scheme: dark) { #source p .t { border-color: #1e1e1e; } }
diff --git a/tests/goldtest.py b/tests/goldtest.py
index 6d9ae4b0..57fa5c06 100644
--- a/tests/goldtest.py
+++ b/tests/goldtest.py
@@ -134,12 +134,27 @@ def contains(filename, *strlist):
missing in `filename`.
"""
+ __tracebackhide__ = True # pytest, please don't show me this function.
with open(filename) as fobj:
text = fobj.read()
for s in strlist:
assert s in text, f"Missing content in {filename}: {s!r}"
+def contains_rx(filename, *rxlist):
+ """Check that the file has lines that re.search all of the regexes.
+
+ An assert will be raised if one of the regexes in `rxlist` doesn't match
+ any lines in `filename`.
+
+ """
+ __tracebackhide__ = True # pytest, please don't show me this function.
+ with open(filename) as fobj:
+ lines = fobj.readlines()
+ for rx in rxlist:
+ assert any(re.search(rx, line) for line in lines), f"Missing rx in {filename}: {rx!r}"
+
+
def contains_any(filename, *strlist):
"""Check that the file contains at least one of a list of strings.
@@ -147,6 +162,7 @@ def contains_any(filename, *strlist):
`filename`.
"""
+ __tracebackhide__ = True # pytest, please don't show me this function.
with open(filename) as fobj:
text = fobj.read()
for s in strlist:
@@ -165,6 +181,7 @@ def doesnt_contain(filename, *strlist):
`filename`.
"""
+ __tracebackhide__ = True # pytest, please don't show me this function.
with open(filename) as fobj:
text = fobj.read()
for s in strlist:
diff --git a/tests/test_html.py b/tests/test_html.py
index 84cc2d4c..849be567 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -23,7 +23,7 @@ from coverage.report import get_analysis_to_report
from tests.coveragetest import CoverageTest, TESTS_DIR
from tests.goldtest import gold_path
-from tests.goldtest import compare, contains, doesnt_contain, contains_any
+from tests.goldtest import compare, contains, contains_rx, doesnt_contain, contains_any
from tests.helpers import assert_coverage_warnings, change_dir
@@ -893,14 +893,14 @@ assert len(math) == 18
if env.PYBEHAVIOR.pep626:
cov.html_report(partial, directory="out/partial_626")
compare_html(gold_path("html/partial_626"), "out/partial_626")
- contains(
+ contains_rx(
"out/partial_626/partial_py.html",
- '<p id="t4" class="par run show_par">',
- '<p id="t7" class="run">',
+ r'<p class="par run show_par">.* id="t4"',
+ r'<p class="run">.* id="t7"',
# The "if 0" and "if 1" statements are marked as run.
- '<p id="t10" class="run">',
+ r'<p class="run">.* id="t10"',
# The "raise ZeroDivisionError" is excluded by regex in the .ini.
- '<p id="t17" class="exc show_exc">',
+ r'<p class="exc show_exc">.* id="t17"',
)
contains(
"out/partial_626/index.html",
@@ -910,14 +910,14 @@ assert len(math) == 18
else:
cov.html_report(partial, directory="out/partial")
compare_html(gold_path("html/partial"), "out/partial")
- contains(
+ contains_rx(
"out/partial/partial_py.html",
- '<p id="t4" class="par run show_par">',
- '<p id="t7" class="run">',
+ r'<p class="par run show_par">.* id="t4"',
+ r'<p class="run">.* id="t7"',
# The "if 0" and "if 1" statements are optimized away.
- '<p id="t10" class="pln">',
+ r'<p class="pln">.* id="t10"',
# The "raise ZeroDivisionError" is excluded by regex in the .ini.
- '<p id="t17" class="exc show_exc">',
+ r'<p class="exc show_exc">.* id="t17"',
)
contains(
"out/partial/index.html",