From d241bc6482c6f7cdc1f63fab50e726c1f73534ab Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 2 Aug 2026 21:54:05 +0200 Subject: [PATCH] test: capture CivArchive failure contract --- tests/test_civarchive_failure_contract.py | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_civarchive_failure_contract.py diff --git a/tests/test_civarchive_failure_contract.py b/tests/test_civarchive_failure_contract.py new file mode 100644 index 0000000..d01813b --- /dev/null +++ b/tests/test_civarchive_failure_contract.py @@ -0,0 +1,25 @@ +from types import SimpleNamespace +from unittest.mock import patch + +import pytest + +from core.sources import civarchive + + +@pytest.mark.parametrize("status_code", [502, 522]) +def test_civarchive_search_preserves_http_failure_message(status_code): + response = SimpleNamespace(status_code=status_code, text="") + + with ( + patch.object(civarchive, "request_source_response", return_value=response), + pytest.raises(civarchive.CivArchiveSearchError, match=f"HTTP {status_code}"), + ): + civarchive._search_page("model.safetensors") + + +def test_civarchive_search_preserves_network_failure_message(): + with ( + patch.object(civarchive, "request_source_response", return_value=None), + pytest.raises(civarchive.CivArchiveSearchError, match="network error or timeout"), + ): + civarchive._search_page("model.safetensors")