Skip to content

Commit 66dd2c1

Browse files
authored
Adjust HTML reports in tests to support newer libxml (#20199)
Fixes #20070. I tested this manually in debian:sid container with `libxml2-16` installed via `apt` and `lxml==6.0.2` built against it (`--no-binary`). HTML reports testcases fail on master as reported and pass on my branch.
1 parent f10b462 commit 66dd2c1

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

mypy/test/helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ def check_test_output_files(
444444
if testcase.suite.native_sep and os.path.sep == "\\":
445445
normalized_output = [fix_cobertura_filename(line) for line in normalized_output]
446446
normalized_output = normalize_error_messages(normalized_output)
447+
if os.path.basename(testcase.file) == "reports.test":
448+
normalized_output = normalize_report_meta(normalized_output)
447449
assert_string_arrays_equal(
448450
expected_content.splitlines(),
449451
normalized_output,
@@ -467,6 +469,13 @@ def normalize_file_output(content: list[str], current_abs_path: str) -> list[str
467469
return result
468470

469471

472+
def normalize_report_meta(content: list[str]) -> list[str]:
473+
# libxml 2.15 and newer emits the "modern" version of this <meta> element.
474+
# Normalize the old style to look the same.
475+
html_meta = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
476+
return ['<meta charset="UTF-8">' if x == html_meta else x for x in content]
477+
478+
470479
def find_test_files(pattern: str, exclude: list[str] | None = None) -> list[str]:
471480
return [
472481
path.name

test-data/unit/reports.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class A(object):
118118
[outfile report/html/n.py.html]
119119
<html>
120120
<head>
121-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
121+
<meta charset="UTF-8">
122122
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
123123
</head>
124124
<body>
@@ -172,7 +172,7 @@ T = TypeVar('T')
172172
[outfile report/html/n.py.html]
173173
<html>
174174
<head>
175-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
175+
<meta charset="UTF-8">
176176
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
177177
</head>
178178
<body>
@@ -214,7 +214,7 @@ def bar(x):
214214
[outfile report/html/n.py.html]
215215
<html>
216216
<head>
217-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
217+
<meta charset="UTF-8">
218218
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
219219
</head>
220220
<body>
@@ -255,7 +255,7 @@ old_stdout = sys.stdout
255255
[outfile report/html/n.py.html]
256256
<html>
257257
<head>
258-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
258+
<meta charset="UTF-8">
259259
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
260260
</head>
261261
<body>
@@ -487,7 +487,7 @@ DisplayToSource = Callable[[int], int]
487487
[outfile report/html/n.py.html]
488488
<html>
489489
<head>
490-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
490+
<meta charset="UTF-8">
491491
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
492492
</head>
493493
<body>
@@ -529,7 +529,7 @@ namespace_packages = True
529529
[outfile report/html/folder/subfolder/something.py.html]
530530
<html>
531531
<head>
532-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
532+
<meta charset="UTF-8">
533533
<link rel="stylesheet" type="text/css" href="../../../mypy-html.css">
534534
</head>
535535
<body>

0 commit comments

Comments
 (0)