Skip to content

Commit 76ddaeb

Browse files
committed
ignore empty string warnings
1 parent 57d2d83 commit 76ddaeb

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

tests/utils/check_warnings.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def check_warnings(file: Path) -> bool:
2323
0 if the warnings are all there
2424
1 if some warning are not registered or unexpected
2525
"""
26+
windows = platform.system().lower() == "windows"
2627
# print some log
2728
print("\n=== Sphinx Warnings test ===\n")
2829

@@ -32,26 +33,31 @@ def check_warnings(file: Path) -> bool:
3233

3334
test_warnings = file.read_text().strip().split("\n")
3435
ref_warnings = warning_file.read_text().strip().split("\n")
35-
if platform.system().lower() == "windows":
36+
if windows:
3637
ref_warnings += extra_warning_file.read_text().strip().split("\n")
3738

39+
extra = f' and "{extra_warning_file}"' if windows else ""
3840
print(
3941
f'Checking build warnings in file: "{file}" and comparing to expected '
40-
f'warnings defined in "{warning_file}"\n\n'
42+
f'warnings defined in "{warning_file}"{extra}\n\n'
4143
)
4244

43-
for refw in ref_warnings[::-1]:
45+
for _rw in ref_warnings[::-1]:
4446
found = False
45-
for testw in test_warnings:
46-
if refw in testw:
47-
ref_warnings.remove(refw)
48-
test_warnings.remove(testw)
47+
for _tw in test_warnings:
48+
if _rw in _tw:
49+
ref_warnings.remove(_rw)
50+
test_warnings.remove(_tw)
4951
found = True
5052
break
5153
if not found:
52-
print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{refw}\n")
53-
for testw in test_warnings:
54-
print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{testw}\n")
54+
print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{_rw}\n")
55+
# warn about unexpected warnings (unless they're the empty string)
56+
for _tw in test_warnings[::-1]:
57+
if len(_tw):
58+
print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n")
59+
else:
60+
test_warnings.remove(_tw)
5561
return len(test_warnings) != 0 or len(ref_warnings) != 0
5662

5763

0 commit comments

Comments
 (0)