From 8f641eb807311ac7823a7172dcf4d4948fb995b9 Mon Sep 17 00:00:00 2001 From: Patrick Dahlke Date: Wed, 1 Apr 2026 19:45:51 +0200 Subject: [PATCH] Fix commented-out assertion and replace skipped test with real fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove commented-out `assert not result.has_warnings()` in test_basic_build.py — the existing ERROR-level check is the correct assertion since basic builds may produce non-error warnings - Replace unconditionally skipped test_missing_image_warning with a real test using a new with_missing_image test fixture that references a nonexistent image file Fixes #141 --- tests/doc_test/with_missing_image/conf.py | 8 ++++++++ tests/doc_test/with_missing_image/index.rst | 9 +++++++++ tests/test_basic_build.py | 1 - tests/test_warnings.py | 9 ++++++--- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/doc_test/with_missing_image/conf.py create mode 100644 tests/doc_test/with_missing_image/index.rst diff --git a/tests/doc_test/with_missing_image/conf.py b/tests/doc_test/with_missing_image/conf.py new file mode 100644 index 0000000..3114dcd --- /dev/null +++ b/tests/doc_test/with_missing_image/conf.py @@ -0,0 +1,8 @@ +"""Configuration for testing missing image warnings.""" + +project = "MissingImageTest" +extensions = ["sphinx_simplepdf"] +master_doc = "index" +exclude_patterns = ["_build"] + +simplepdf_theme = "simplepdf_theme" diff --git a/tests/doc_test/with_missing_image/index.rst b/tests/doc_test/with_missing_image/index.rst new file mode 100644 index 0000000..d8879a3 --- /dev/null +++ b/tests/doc_test/with_missing_image/index.rst @@ -0,0 +1,9 @@ +Document with Missing Image +=========================== + +This document references an image that does not exist. + +.. image:: _static/nonexistent_image.png + :alt: This image does not exist + +Content after the missing image. diff --git a/tests/test_basic_build.py b/tests/test_basic_build.py index e5853a0..01601e4 100644 --- a/tests/test_basic_build.py +++ b/tests/test_basic_build.py @@ -10,7 +10,6 @@ def test_basic_build_succeeds(sphinx_build, capsys): result = build_and_capture_stdout(sphinx_build, capsys, srcdir="basic_doc") assert result.pdf_exists() - # assert not result.has_warnings() assert not result.has_warnings("ERROR:") diff --git a/tests/test_warnings.py b/tests/test_warnings.py index 0e1ab0c..f7d3091 100644 --- a/tests/test_warnings.py +++ b/tests/test_warnings.py @@ -17,10 +17,13 @@ def test_broken_anchors_warning(sphinx_build, capsys): assert len(anchor_warnings) > 0 -def test_missing_image_warning(sphinx_build, tmp_path): +def test_missing_image_warning(sphinx_build, capsys): """Test that missing images produce warnings.""" - # This would require a test doc with broken image reference - pytest.skip("Requires test doc with broken image") + result = build_and_capture_stdout(sphinx_build, capsys, srcdir="with_missing_image") + + assert result.has_warnings() + image_warnings = result.get_warnings_matching(r"(image|nonexistent|not found|not readable)") + assert len(image_warnings) > 0 def test_build_warnings_are_captured(sphinx_build, capsys):