summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-03-22 13:12:16 -0400
committerNed Batchelder <ned@nedbatchelder.com>2023-03-22 13:58:58 -0400
commit63f3e495b184ebd9aa4c9d757fb78ed148580d29 (patch)
treeaf4c68f94d50fafe94d56fce46cf92739cd8bd3f /coverage
parenta5dc01131b1a38bb7c7908ad968488d87e3664ed (diff)
downloadpython-coveragepy-git-63f3e495b184ebd9aa4c9d757fb78ed148580d29.tar.gz
style: clean up #1587
Diffstat (limited to 'coverage')
-rw-r--r--coverage/html.py22
-rw-r--r--coverage/htmlfiles/coverage_html.js3
-rw-r--r--coverage/htmlfiles/pyfile.html6
-rw-r--r--coverage/htmlfiles/style.css2
-rw-r--r--coverage/htmlfiles/style.scss4
5 files changed, 13 insertions, 24 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 23fba3f0..d172e896 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -5,12 +5,12 @@
from __future__ import annotations
+import collections
import datetime
import json
import os
import re
import shutil
-from collections import Counter
from dataclasses import dataclass
from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING, cast
@@ -370,9 +370,12 @@ class HtmlReporter:
# Write the HTML page for this file.
file_data = self.datagen.data_for_file(ftr.fr, ftr.analysis)
- contexts = Counter(c for cline in file_data.lines for c in cline.contexts)
+ contexts = collections.Counter(c for cline in file_data.lines for c in cline.contexts)
context_codes = {y: i for (i, y) in enumerate(x[0] for x in contexts.most_common())}
- contexts_json = json.dumps({v: k for (k, v) in context_codes.items()}, indent=2)
+ if context_codes:
+ contexts_json = json.dumps({v: k for (k, v) in context_codes.items()}, indent=2)
+ else:
+ contexts_json = None
for ldata in file_data.lines:
# Build the HTML for the line.
@@ -382,13 +385,11 @@ class HtmlReporter:
html_parts.append(escape(tok_text))
else:
tok_html = escape(tok_text) or '&nbsp;'
- html_parts.append(
- f'<span class="{tok_type}">{tok_html}</span>'
- )
+ html_parts.append(f'<span class="{tok_type}">{tok_html}</span>')
ldata.html = ''.join(html_parts)
-
ldata.context_str = ",".join(
- str(context_codes[c_context]) for c_context in ldata.context_list)
+ str(context_codes[c_context]) for c_context in ldata.context_list
+ )
if ldata.short_annotations:
# 202F is NARROW NO-BREAK SPACE.
@@ -422,13 +423,10 @@ class HtmlReporter:
)
ldata.css_class = ' '.join(css_classes) or "pln"
- if context_codes:
- file_data.__dict__["contexts_json"] = contexts_json
- else:
- file_data.__dict__["contexts_json"] = None
html_path = os.path.join(self.directory, ftr.html_filename)
html = self.source_tmpl.render({
**file_data.__dict__,
+ "contexts_json": contexts_json,
'prev_html': prev_html,
'next_html': next_html,
})
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 8b7fb96f..1cd2b5d4 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -604,8 +604,7 @@ coverage.showContexts = function (e) {
span = e.target.nextElementSibling.nextElementSibling;
span_text = span.textContent;
- if (/^[0-9,]+$/.test(span_text))
- {
+ if (/^[0-9,]+$/.test(span_text)) {
span.textContent = "";
span_text.split(",").forEach(function(s) {
ctx = contexts[s];
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 1921e1c2..bc8fa697 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -14,7 +14,7 @@
{% if contexts_json %}
<script type="text/javascript">
- contexts = {{ contexts_json }}
+ contexts = {{ contexts_json }}
</script>
{% endif %}
@@ -125,9 +125,7 @@
</span>
{# Things that should appear below the line. #}
{% if line.context_str %}
- <span class="ctxs">
- {{ line.context_str }}
- </span>
+ <span class="ctxs">{{ line.context_str }}</span>
{% endif %}
</p>
{% endjoined %}
diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css
index ace48c2c..11b24c4e 100644
--- a/coverage/htmlfiles/style.css
+++ b/coverage/htmlfiles/style.css
@@ -262,8 +262,6 @@ kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em
@media (prefers-color-scheme: dark) { #source p .ctxs { background: #056; } }
-#source p .ctxs span { display: block; text-align: right; }
-
#index { font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.875em; }
#index table.index { margin-left: -.5em; }
diff --git a/coverage/htmlfiles/style.scss b/coverage/htmlfiles/style.scss
index fe388487..b1465154 100644
--- a/coverage/htmlfiles/style.scss
+++ b/coverage/htmlfiles/style.scss
@@ -623,10 +623,6 @@ $border-indicator-width: .2em;
border-radius: .25em;
margin-right: 1.75em;
text-align: right;
- span {
- display: block;
- text-align: right;
- }
}
}
}