Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYinCarl committed Sep 1, 2024
2 parents 54835a5 + b5408df commit c466f4b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 35 deletions.
24 changes: 12 additions & 12 deletions requirements/dev.pip
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ backports-tarfile==1.2.0
# via jaraco-context
build==1.2.1
# via check-manifest
cachetools==5.4.0
cachetools==5.5.0
# via tox
certifi==2024.7.4
certifi==2024.8.30
# via requests
chardet==5.2.0
# via tox
Expand Down Expand Up @@ -49,24 +49,24 @@ flaky==3.8.1
# via -r requirements/pytest.in
greenlet==3.0.3
# via -r requirements/dev.in
hypothesis==6.110.0
hypothesis==6.111.2
# via -r requirements/pytest.in
idna==3.7
idna==3.8
# via requests
importlib-metadata==8.2.0
importlib-metadata==8.4.0
# via
# build
# keyring
# twine
importlib-resources==6.4.0
importlib-resources==6.4.4
# via keyring
iniconfig==2.0.0
# via pytest
isort==5.13.2
# via pylint
jaraco-classes==3.4.0
# via keyring
jaraco-context==5.3.0
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.0.2
# via keyring
Expand Down Expand Up @@ -141,7 +141,7 @@ requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.7.1
rich==13.8.0
# via twine
sortedcontainers==2.4.0
# via hypothesis
Expand All @@ -155,9 +155,9 @@ tomli==2.0.1
# pyproject-api
# pytest
# tox
tomlkit==0.13.0
tomlkit==0.13.2
# via pylint
tox==4.17.1
tox==4.18.0
# via
# -r requirements/tox.in
# tox-gh
Expand Down Expand Up @@ -187,15 +187,15 @@ virtualenv==20.26.3
# tox
wcwidth==0.2.13
# via urwid
zipp==3.19.2
zipp==3.20.1
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
pip==24.2
# via -r requirements/pip.in
setuptools==72.1.0
setuptools==74.0.0
# via
# -r requirements/pip.in
# check-manifest
18 changes: 9 additions & 9 deletions requirements/kit.pip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
auditwheel==6.0.0
auditwheel==6.1.0
# via -r requirements/kit.in
backports-tarfile==1.2.0
# via jaraco-context
Expand All @@ -14,7 +14,7 @@ bracex==2.5
# via cibuildwheel
build==1.2.1
# via -r requirements/kit.in
certifi==2024.7.4
certifi==2024.8.30
# via
# cibuildwheel
# requests
Expand All @@ -28,18 +28,18 @@ docutils==0.20.1
# via readme-renderer
filelock==3.15.4
# via cibuildwheel
idna==3.7
idna==3.8
# via requests
importlib-metadata==8.2.0
importlib-metadata==8.4.0
# via
# build
# keyring
# twine
importlib-resources==6.4.0
importlib-resources==6.4.4
# via keyring
jaraco-classes==3.4.0
# via keyring
jaraco-context==5.3.0
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.0.2
# via keyring
Expand Down Expand Up @@ -82,7 +82,7 @@ requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.7.1
rich==13.8.0
# via twine
tomli==2.0.1
# via
Expand All @@ -100,11 +100,11 @@ urllib3==2.2.2
# twine
wheel==0.44.0
# via -r requirements/kit.in
zipp==3.19.2
zipp==3.20.1
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
setuptools==72.1.0
setuptools==74.0.0
# via -r requirements/kit.in
4 changes: 2 additions & 2 deletions requirements/light-threads.pip
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pycparser==2.22
# via cffi
zope-event==5.0
# via gevent
zope-interface==7.0.1
zope-interface==7.0.3
# via gevent

# The following packages are considered to be unsafe in a requirements file:
setuptools==72.1.0
setuptools==74.0.0
# via
# zope-event
# zope-interface
4 changes: 2 additions & 2 deletions requirements/mypy.pip
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ execnet==2.1.1
# via pytest-xdist
flaky==3.8.1
# via -r requirements/pytest.in
hypothesis==6.110.0
hypothesis==6.111.2
# via -r requirements/pytest.in
iniconfig==2.0.0
# via pytest
mypy==1.11.1
mypy==1.11.2
# via -r requirements/mypy.in
mypy-extensions==1.0.0
# via mypy
Expand Down
6 changes: 3 additions & 3 deletions requirements/pip-tools.pip
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build==1.2.1
# via pip-tools
click==8.1.7
# via pip-tools
importlib-metadata==8.2.0
importlib-metadata==8.4.0
# via build
packaging==24.1
# via build
Expand All @@ -24,11 +24,11 @@ tomli==2.0.1
# pip-tools
wheel==0.44.0
# via pip-tools
zipp==3.19.2
zipp==3.20.1
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
pip==24.2
# via pip-tools
setuptools==72.1.0
setuptools==74.0.0
# via pip-tools
2 changes: 1 addition & 1 deletion requirements/pip.pip
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ virtualenv==20.26.3
# The following packages are considered to be unsafe in a requirements file:
pip==24.2
# via -r requirements/pip.in
setuptools==72.1.0
setuptools==74.0.0
# via -r requirements/pip.in
2 changes: 1 addition & 1 deletion requirements/pytest.pip
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ execnet==2.1.1
# via pytest-xdist
flaky==3.8.1
# via -r requirements/pytest.in
hypothesis==6.110.0
hypothesis==6.111.2
# via -r requirements/pytest.in
iniconfig==2.0.0
# via pytest
Expand Down
4 changes: 2 additions & 2 deletions requirements/tox.pip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
cachetools==5.4.0
cachetools==5.5.0
# via tox
chardet==5.2.0
# via tox
Expand Down Expand Up @@ -34,7 +34,7 @@ tomli==2.0.1
# via
# pyproject-api
# tox
tox==4.17.1
tox==4.18.0
# via
# -r requirements/tox.in
# tox-gh
Expand Down
56 changes: 53 additions & 3 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import re
import sys

from unittest import mock
from html.parser import HTMLParser
from typing import Any, IO
from unittest import mock

import pytest

Expand Down Expand Up @@ -94,6 +95,12 @@ def get_html_index_content(self) -> str:
)
return index

def get_html_report_text_lines(self, module: str) -> list[str]:
"""Parse the HTML report, and return a list of strings, the text rendered."""
parser = HtmlReportParser()
parser.feed(self.get_html_report_content(module))
return parser.text()

def assert_correct_timestamp(self, html: str) -> None:
"""Extract the time stamp from `html`, and assert it is recent."""
timestamp_pat = r"created at (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})"
Expand Down Expand Up @@ -133,6 +140,43 @@ def assert_valid_hrefs(self, directory: str = "htmlcov") -> None:
)


class HtmlReportParser(HTMLParser): # pylint: disable=abstract-method
"""An HTML parser for our HTML reports.
Assertions are made about the structure we expect.
"""
def __init__(self) -> None:
super().__init__()
self.lines: list[list[str]] = []
self.in_source = False

def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
if tag == "main":
assert attrs == [("id", "source")]
self.in_source = True
elif self.in_source and tag == "a":
dattrs = dict(attrs)
assert "id" in dattrs
ida = dattrs["id"]
assert ida is not None
assert ida[0] == "t"
line_no = int(ida[1:])
self.lines.append([])
assert line_no == len(self.lines)

def handle_endtag(self, tag: str) -> None:
if tag == "main":
self.in_source = False

def handle_data(self, data: str) -> None:
if self.in_source and self.lines:
self.lines[-1].append(data)

def text(self) -> list[str]:
"""Get the rendered text as a list of strings, one per line."""
return ["".join(l).rstrip() for l in self.lines]


class FileWriteTracker:
"""A fake object to track how `open` is used to write files."""
def __init__(self, written: set[str]) -> None:
Expand Down Expand Up @@ -1141,10 +1185,10 @@ def test_bug_1828(self) -> None:

cov = coverage.Coverage()
backslashes = self.start_import_stop(cov, "backslashes")
cov.html_report(backslashes, directory="out")
cov.html_report(backslashes)

contains(
"out/backslashes_py.html",
"htmlcov/backslashes_py.html",
# line 2 is `"bbb \`
r'<a id="t2" href="#t2">2</a></span>'
+ r'<span class="t"> <span class="str">"bbb \</span>',
Expand All @@ -1153,6 +1197,12 @@ def test_bug_1828(self) -> None:
+ r'<span class="t"><span class="str"> ccc"</span><span class="op">]</span>',
)

assert self.get_html_report_text_lines("backslashes.py") == [
'1a = ["aaa",\\',
'2 "bbb \\',
'3 ccc"]',
]

def test_unicode(self) -> None:
surrogate = "\U000e0100"

Expand Down

0 comments on commit c466f4b

Please sign in to comment.