From 8f1a6b85259ecdf68705be1ae6939c3b9d679884 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 17 Oct 2023 16:52:51 -0500 Subject: [PATCH 01/19] use warning list --- tests/warning_list.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/warning_list.txt b/tests/warning_list.txt index b1d89e3f8..7b6668df5 100644 --- a/tests/warning_list.txt +++ b/tests/warning_list.txt @@ -22,3 +22,5 @@ WARNING: autosummary: stub file not found 'urllib.parse.SplitResult.index'. Chec WARNING: autosummary: stub file not found 'urllib.parse.SplitResultBytes.count'. Check your autosummary_generate setting. WARNING: autosummary: stub file not found 'urllib.parse.SplitResultBytes.index'. Check your autosummary_generate setting. ERROR: Unexpected indentation. +WARNING: Cell printed to stderr: +WARNING: Matplotlib is building the font cache; this may take a moment. From 6c29fe5eb1692dcc1f36b39ffb231befc185e946 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 17 Oct 2023 16:59:49 -0500 Subject: [PATCH 02/19] clean up notebook --- docs/examples/pydata.ipynb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/docs/examples/pydata.ipynb b/docs/examples/pydata.ipynb index 34a8da267..742a0b7c3 100644 --- a/docs/examples/pydata.ipynb +++ b/docs/examples/pydata.ipynb @@ -37,20 +37,6 @@ "## Matplotlib" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "import matplotlib\n", - "\n", - "# avoid warnings upon doc build\n", - "matplotlib.set_loglevel(\"critical\")" - ] - }, { "cell_type": "code", "execution_count": null, @@ -69,11 +55,6 @@ "metadata": {}, "outputs": [], "source": [ - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "\n", - "matplotlib.set_loglevel(\"critical\")\n", - "\n", "rng = np.random.default_rng()\n", "data = rng.standard_normal((3, 100))\n", "fig, ax = plt.subplots()\n", From befd018f3386274f4fe03fe793794816b866d912 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 17 Oct 2023 17:23:36 -0500 Subject: [PATCH 03/19] refactor to pass on all platforms? --- tests/utils/check_warnings.py | 35 ++++++++++++++++++++-------------- tests/warning_list.txt | 2 -- tests/warning_list_windows.txt | 3 +++ 3 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 tests/warning_list_windows.txt diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 9e790b835..a63521290 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -1,5 +1,6 @@ """Check the list of warnings produced by a doc build.""" +import platform import sys from pathlib import Path @@ -27,30 +28,36 @@ def check_warnings(file: Path) -> bool: # find the file where all the known warnings are stored warning_file = Path(__file__).parent.parent / "warning_list.txt" + extra_warning_file = Path(__file__).parent.parent / "warning_list_windows.txt" test_warnings = file.read_text().strip().split("\n") ref_warnings = warning_file.read_text().strip().split("\n") + if platform.system() == "windows": + extra_warnings = extra_warning_file.read_text().strip().split("\n") + else: + extra_warnings = list() print( f'Checking build warnings in file: "{file}" and comparing to expected ' f'warnings defined in "{warning_file}"\n\n' ) - # find all the missing warnings - missing_warnings = [] - for wa in ref_warnings: - index = [i for i, twa in enumerate(test_warnings) if wa in twa] - if len(index) == 0: - missing_warnings += [wa] - print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{wa}\n") + # find all the unexpected warnings + unexpected_warnings = list() + for ww in test_warnings: + if ww in ref_warnings: + ref_warnings.remove(ww) + elif ww in extra_warnings: + extra_warnings.remove(ww) else: - test_warnings.pop(index[0]) - - # the remaining one are unexpected - for twa in test_warnings: - print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{twa}\n") - - return len(missing_warnings) != 0 or len(test_warnings) != 0 + unexpected_warnings.append(ww) + print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{ww}\n") + # alert about expected warnings not being raised + leftover_expected = ref_warnings + extra_warnings + for wa in leftover_expected: + print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{wa}\n") + + return len(unexpected_warnings) != 0 or len(leftover_expected) != 0 if __name__ == "__main__": diff --git a/tests/warning_list.txt b/tests/warning_list.txt index 7b6668df5..b1d89e3f8 100644 --- a/tests/warning_list.txt +++ b/tests/warning_list.txt @@ -22,5 +22,3 @@ WARNING: autosummary: stub file not found 'urllib.parse.SplitResult.index'. Chec WARNING: autosummary: stub file not found 'urllib.parse.SplitResultBytes.count'. Check your autosummary_generate setting. WARNING: autosummary: stub file not found 'urllib.parse.SplitResultBytes.index'. Check your autosummary_generate setting. ERROR: Unexpected indentation. -WARNING: Cell printed to stderr: -WARNING: Matplotlib is building the font cache; this may take a moment. diff --git a/tests/warning_list_windows.txt b/tests/warning_list_windows.txt new file mode 100644 index 000000000..04c00db9e --- /dev/null +++ b/tests/warning_list_windows.txt @@ -0,0 +1,3 @@ +WARNING: Cell printed to stderr: + +Matplotlib is building the font cache; this may take a moment. From d55bc01932df62cd92819e48937637a636ee0392 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 17 Oct 2023 17:33:52 -0500 Subject: [PATCH 04/19] simplify --- tests/utils/check_warnings.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index a63521290..a5225e184 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -33,9 +33,7 @@ def check_warnings(file: Path) -> bool: test_warnings = file.read_text().strip().split("\n") ref_warnings = warning_file.read_text().strip().split("\n") if platform.system() == "windows": - extra_warnings = extra_warning_file.read_text().strip().split("\n") - else: - extra_warnings = list() + ref_warnings += extra_warning_file.read_text().strip().split("\n") print( f'Checking build warnings in file: "{file}" and comparing to expected ' @@ -47,17 +45,14 @@ def check_warnings(file: Path) -> bool: for ww in test_warnings: if ww in ref_warnings: ref_warnings.remove(ww) - elif ww in extra_warnings: - extra_warnings.remove(ww) else: unexpected_warnings.append(ww) print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{ww}\n") # alert about expected warnings not being raised - leftover_expected = ref_warnings + extra_warnings - for wa in leftover_expected: + for wa in ref_warnings: print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{wa}\n") - return len(unexpected_warnings) != 0 or len(leftover_expected) != 0 + return len(unexpected_warnings) != 0 or len(ref_warnings) != 0 if __name__ == "__main__": From a70dda4bc1db830fc88a38095f9d927cc91289d7 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 17 Oct 2023 21:52:40 -0500 Subject: [PATCH 05/19] fix logic --- tests/utils/check_warnings.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index a5225e184..dbee43490 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -40,19 +40,16 @@ def check_warnings(file: Path) -> bool: f'warnings defined in "{warning_file}"\n\n' ) - # find all the unexpected warnings - unexpected_warnings = list() - for ww in test_warnings: - if ww in ref_warnings: - ref_warnings.remove(ww) - else: - unexpected_warnings.append(ww) - print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{ww}\n") - # alert about expected warnings not being raised - for wa in ref_warnings: - print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{wa}\n") - - return len(unexpected_warnings) != 0 or len(ref_warnings) != 0 + for refw in ref_warnings: + for testw in test_warnings: + if refw in testw: + ref_warnings.remove(refw) + test_warnings.remove(testw) + break + print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{refw}\n") + for testw in test_warnings: + print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{testw}\n") + return len(test_warnings) != 0 or len(ref_warnings) != 0 if __name__ == "__main__": From 073b70bd02033655d68fd3af48504af4e8f25770 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 10:45:12 -0500 Subject: [PATCH 06/19] iterate backwards --- tests/utils/check_warnings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index dbee43490..92d01f647 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -40,7 +40,7 @@ def check_warnings(file: Path) -> bool: f'warnings defined in "{warning_file}"\n\n' ) - for refw in ref_warnings: + for refw in ref_warnings[::-1]: for testw in test_warnings: if refw in testw: ref_warnings.remove(refw) From 57d2d836c2c78fb3ea2c99099ed426936f8acf61 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:03:34 -0500 Subject: [PATCH 07/19] =?UTF-8?q?fix=20plaform=20detection=3F=20also=20don?= =?UTF-8?q?'t=20log=20unnecessarily=1B[H?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/utils/check_warnings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 92d01f647..f2f70e062 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -32,7 +32,7 @@ def check_warnings(file: Path) -> bool: test_warnings = file.read_text().strip().split("\n") ref_warnings = warning_file.read_text().strip().split("\n") - if platform.system() == "windows": + if platform.system().lower() == "windows": ref_warnings += extra_warning_file.read_text().strip().split("\n") print( @@ -41,12 +41,15 @@ def check_warnings(file: Path) -> bool: ) for refw in ref_warnings[::-1]: + found = False for testw in test_warnings: if refw in testw: ref_warnings.remove(refw) test_warnings.remove(testw) + found = True break - print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{refw}\n") + if not found: + print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{refw}\n") for testw in test_warnings: print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{testw}\n") return len(test_warnings) != 0 or len(ref_warnings) != 0 From 76ddaebed5c9a43d34ee22b7bd57b30b4dd590ed Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:21:05 -0500 Subject: [PATCH 08/19] ignore empty string warnings --- tests/utils/check_warnings.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index f2f70e062..443c95e02 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -23,6 +23,7 @@ def check_warnings(file: Path) -> bool: 0 if the warnings are all there 1 if some warning are not registered or unexpected """ + windows = platform.system().lower() == "windows" # print some log print("\n=== Sphinx Warnings test ===\n") @@ -32,26 +33,31 @@ def check_warnings(file: Path) -> bool: test_warnings = file.read_text().strip().split("\n") ref_warnings = warning_file.read_text().strip().split("\n") - if platform.system().lower() == "windows": + if windows: ref_warnings += extra_warning_file.read_text().strip().split("\n") + extra = f' and "{extra_warning_file}"' if windows else "" print( f'Checking build warnings in file: "{file}" and comparing to expected ' - f'warnings defined in "{warning_file}"\n\n' + f'warnings defined in "{warning_file}"{extra}\n\n' ) - for refw in ref_warnings[::-1]: + for _rw in ref_warnings[::-1]: found = False - for testw in test_warnings: - if refw in testw: - ref_warnings.remove(refw) - test_warnings.remove(testw) + for _tw in test_warnings: + if _rw in _tw: + ref_warnings.remove(_rw) + test_warnings.remove(_tw) found = True break if not found: - print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{refw}\n") - for testw in test_warnings: - print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{testw}\n") + print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{_rw}\n") + # warn about unexpected warnings (unless they're the empty string) + for _tw in test_warnings[::-1]: + if len(_tw): + print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n") + else: + test_warnings.remove(_tw) return len(test_warnings) != 0 or len(ref_warnings) != 0 From 42f46723eb9eeea7603efb91fbfb6bdfa1de28b3 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:21:36 -0500 Subject: [PATCH 09/19] remove notebook metawarning --- tests/warning_list_windows.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/warning_list_windows.txt b/tests/warning_list_windows.txt index 04c00db9e..85ff1be04 100644 --- a/tests/warning_list_windows.txt +++ b/tests/warning_list_windows.txt @@ -1,3 +1 @@ -WARNING: Cell printed to stderr: - Matplotlib is building the font cache; this may take a moment. From 4e8e30363dfa77e8d867c3d6912a2a299000bc03 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:31:56 -0500 Subject: [PATCH 10/19] Revert "remove notebook metawarning" This reverts commit 42f46723eb9eeea7603efb91fbfb6bdfa1de28b3. --- tests/warning_list_windows.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/warning_list_windows.txt b/tests/warning_list_windows.txt index 85ff1be04..04c00db9e 100644 --- a/tests/warning_list_windows.txt +++ b/tests/warning_list_windows.txt @@ -1 +1,3 @@ +WARNING: Cell printed to stderr: + Matplotlib is building the font cache; this may take a moment. From 6fc35bb103e2edd5391ec4f9e6b5608f55aab71e Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:34:53 -0500 Subject: [PATCH 11/19] try again --- tests/utils/check_warnings.py | 2 +- tests/warning_list_windows.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 443c95e02..576c70a55 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -54,7 +54,7 @@ def check_warnings(file: Path) -> bool: print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{_rw}\n") # warn about unexpected warnings (unless they're the empty string) for _tw in test_warnings[::-1]: - if len(_tw): + if len(_tw.strip()): print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n") else: test_warnings.remove(_tw) diff --git a/tests/warning_list_windows.txt b/tests/warning_list_windows.txt index 04c00db9e..0f3d90d76 100644 --- a/tests/warning_list_windows.txt +++ b/tests/warning_list_windows.txt @@ -1,3 +1,2 @@ WARNING: Cell printed to stderr: - Matplotlib is building the font cache; this may take a moment. From 28406548d915cf31f6337cd62358051308a95980 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 11:46:15 -0500 Subject: [PATCH 12/19] debug the mysterious empty warning --- tests/utils/check_warnings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 576c70a55..98244bdf4 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -55,6 +55,7 @@ def check_warnings(file: Path) -> bool: # warn about unexpected warnings (unless they're the empty string) for _tw in test_warnings[::-1]: if len(_tw.strip()): + print(f'UNEXPECTED WARNING: "{_tw}", {tuple(map(ord, _tw))}') print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n") else: test_warnings.remove(_tw) From c8b187f1eb113d213d251f7815e78bd13c2cca66 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 12:43:22 -0500 Subject: [PATCH 13/19] escape color codes --- tests/utils/check_warnings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 98244bdf4..a242931d3 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -6,6 +6,8 @@ from colorama import Fore, init +from ..test_build import escape_ansi + # init colors for all plateforms init() @@ -31,7 +33,7 @@ def check_warnings(file: Path) -> bool: warning_file = Path(__file__).parent.parent / "warning_list.txt" extra_warning_file = Path(__file__).parent.parent / "warning_list_windows.txt" - test_warnings = file.read_text().strip().split("\n") + test_warnings = escape_ansi(file.read_text()).strip().split("\n") ref_warnings = warning_file.read_text().strip().split("\n") if windows: ref_warnings += extra_warning_file.read_text().strip().split("\n") @@ -55,7 +57,6 @@ def check_warnings(file: Path) -> bool: # warn about unexpected warnings (unless they're the empty string) for _tw in test_warnings[::-1]: if len(_tw.strip()): - print(f'UNEXPECTED WARNING: "{_tw}", {tuple(map(ord, _tw))}') print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n") else: test_warnings.remove(_tw) From bc76f51c4cbc192870be94850186d3dfc3a1567b Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 12:57:52 -0500 Subject: [PATCH 14/19] import --- src/pydata_sphinx_theme/utils.py | 7 +++++++ tests/test_build.py | 7 +------ tests/utils/check_warnings.py | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pydata_sphinx_theme/utils.py b/src/pydata_sphinx_theme/utils.py index 9fccaea6f..db56af9f4 100644 --- a/src/pydata_sphinx_theme/utils.py +++ b/src/pydata_sphinx_theme/utils.py @@ -1,5 +1,6 @@ """General helpers for the management of config parameters.""" +import re from typing import Any, Dict, Iterator from docutils.nodes import Node @@ -39,3 +40,9 @@ def traverse_or_findall(node: Node, condition: str, **kwargs) -> Iterator[Node]: if hasattr(node, "findall") else node.traverse(condition, **kwargs) ) + + +def escape_ansi(string: str) -> str: + """Helper function to remove ansi coloring from sphinx warnings.""" + ansi_escape = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]") + return ansi_escape.sub("", string) diff --git a/tests/test_build.py b/tests/test_build.py index 32d949d01..f22ec1f8c 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -5,12 +5,7 @@ import pytest import sphinx.errors - - -def escape_ansi(string: str) -> str: - """Helper function to remove ansi coloring from sphinx warnings.""" - ansi_escape = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]") - return ansi_escape.sub("", string) +from pydata_sphinx_theme.utils import escape_ansi def test_build_html(sphinx_build_factory, file_regression) -> None: diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index a242931d3..4c935f104 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -5,8 +5,7 @@ from pathlib import Path from colorama import Fore, init - -from ..test_build import escape_ansi +from pydata_sphinx_theme.utils import escape_ansi # init colors for all plateforms init() From e8298af6545914ae49d404d3b2bc3f3ecbed9a17 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 15:25:36 -0500 Subject: [PATCH 15/19] triage by intermittency, not by platform; better var names --- ...dows.txt => intermittent_warning_list.txt} | 0 tests/utils/check_warnings.py | 39 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) rename tests/{warning_list_windows.txt => intermittent_warning_list.txt} (100%) diff --git a/tests/warning_list_windows.txt b/tests/intermittent_warning_list.txt similarity index 100% rename from tests/warning_list_windows.txt rename to tests/intermittent_warning_list.txt diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 4c935f104..49f62c6f4 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -1,6 +1,5 @@ """Check the list of warnings produced by a doc build.""" -import platform import sys from pathlib import Path @@ -24,42 +23,40 @@ def check_warnings(file: Path) -> bool: 0 if the warnings are all there 1 if some warning are not registered or unexpected """ - windows = platform.system().lower() == "windows" # print some log print("\n=== Sphinx Warnings test ===\n") # find the file where all the known warnings are stored warning_file = Path(__file__).parent.parent / "warning_list.txt" - extra_warning_file = Path(__file__).parent.parent / "warning_list_windows.txt" + extra_warning_file = Path(__file__).parent.parent / "intermittent_warning_list.txt" - test_warnings = escape_ansi(file.read_text()).strip().split("\n") - ref_warnings = warning_file.read_text().strip().split("\n") - if windows: - ref_warnings += extra_warning_file.read_text().strip().split("\n") + received_warnings = escape_ansi(file.read_text()).strip().split("\n") + expected_warnings = warning_file.read_text().strip().split("\n") + intermittent_warnings = extra_warning_file.read_text().strip().split("\n") - extra = f' and "{extra_warning_file}"' if windows else "" print( f'Checking build warnings in file: "{file}" and comparing to expected ' - f'warnings defined in "{warning_file}"{extra}\n\n' + f'warnings defined in "{warning_file}" and "{extra_warning_file}"\n\n' ) - for _rw in ref_warnings[::-1]: + for exp_w in expected_warnings[::-1] + intermittent_warnings[::-1]: found = False - for _tw in test_warnings: - if _rw in _tw: - ref_warnings.remove(_rw) - test_warnings.remove(_tw) + for rec_w in received_warnings: + if exp_w in rec_w: + expected_warnings.remove(exp_w) + received_warnings.remove(rec_w) found = True break - if not found: - print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{_rw}\n") + # alert only if an *always expected* warning wasn't raised (not intermittent) + if not found and exp_w not in intermittent_warnings: + print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{exp_w}\n") # warn about unexpected warnings (unless they're the empty string) - for _tw in test_warnings[::-1]: - if len(_tw.strip()): - print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{_tw}\n") + for rec_w in received_warnings[::-1]: + if len(rec_w.strip()): + print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{rec_w}\n") else: - test_warnings.remove(_tw) - return len(test_warnings) != 0 or len(ref_warnings) != 0 + received_warnings.remove(rec_w) + return len(received_warnings) or len(expected_warnings) if __name__ == "__main__": From 1241793eb0e6b09750a1b3d4cd09c27b7028a9a8 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 15:25:59 -0500 Subject: [PATCH 16/19] simplify --- tests/utils/check_warnings.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 49f62c6f4..7aecbff8c 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -50,12 +50,9 @@ def check_warnings(file: Path) -> bool: # alert only if an *always expected* warning wasn't raised (not intermittent) if not found and exp_w not in intermittent_warnings: print(f"{Fore.YELLOW}Warning was not raised: {Fore.RESET}{exp_w}\n") - # warn about unexpected warnings (unless they're the empty string) + # warn about unexpected warnings for rec_w in received_warnings[::-1]: - if len(rec_w.strip()): - print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{rec_w}\n") - else: - received_warnings.remove(rec_w) + print(f"{Fore.YELLOW}Unexpected warning: {Fore.RESET}{rec_w}\n") return len(received_warnings) or len(expected_warnings) From 447f39e72ab07dc86becd9fd2eb69cd0d4ca0fa3 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 15:32:55 -0500 Subject: [PATCH 17/19] fix list.remove --- tests/utils/check_warnings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 7aecbff8c..3f53397ca 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -43,8 +43,11 @@ def check_warnings(file: Path) -> bool: found = False for rec_w in received_warnings: if exp_w in rec_w: - expected_warnings.remove(exp_w) received_warnings.remove(rec_w) + if exp_w in expected_warnings: + expected_warnings.remove(exp_w) + elif exp_w in intermittent_warnings: + intermittent_warnings.remove(exp_w) found = True break # alert only if an *always expected* warning wasn't raised (not intermittent) From 426747401196d41dd32285c94a62c112fb2a07ea Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 16:03:20 -0500 Subject: [PATCH 18/19] undo what I broke --- tests/utils/check_warnings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index 3f53397ca..be0e756cf 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -33,6 +33,8 @@ def check_warnings(file: Path) -> bool: received_warnings = escape_ansi(file.read_text()).strip().split("\n") expected_warnings = warning_file.read_text().strip().split("\n") intermittent_warnings = extra_warning_file.read_text().strip().split("\n") + # filter out empty warnings (happens on notebooks for some reason) + received_warnings = filter(len, received_warnings) print( f'Checking build warnings in file: "{file}" and comparing to expected ' From 6c9cc89c8b2455d975e024043d4bb219e44751ab Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 18 Oct 2023 16:39:31 -0500 Subject: [PATCH 19/19] Update tests/utils/check_warnings.py --- tests/utils/check_warnings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/check_warnings.py b/tests/utils/check_warnings.py index be0e756cf..726a81c7b 100644 --- a/tests/utils/check_warnings.py +++ b/tests/utils/check_warnings.py @@ -34,7 +34,7 @@ def check_warnings(file: Path) -> bool: expected_warnings = warning_file.read_text().strip().split("\n") intermittent_warnings = extra_warning_file.read_text().strip().split("\n") # filter out empty warnings (happens on notebooks for some reason) - received_warnings = filter(len, received_warnings) + received_warnings = list(filter(len, received_warnings)) print( f'Checking build warnings in file: "{file}" and comparing to expected '