mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-04-19 21:39:17 -04:00
28 lines
869 B
Python
28 lines
869 B
Python
"""Tests for shared utility helpers."""
|
|
|
|
import sys
|
|
import types
|
|
import xmlrpc.client as stdlib_xmlrpc_client
|
|
|
|
from shelfmark.core import utils
|
|
|
|
|
|
def test_get_hardened_xmlrpc_client_tolerates_patch_runtime_error(monkeypatch) -> None:
|
|
fake_package = types.ModuleType("defusedxml")
|
|
fake_module = types.ModuleType("defusedxml.xmlrpc")
|
|
|
|
def failing_monkey_patch() -> None:
|
|
raise RuntimeError("patch failed")
|
|
|
|
fake_module.monkey_patch = failing_monkey_patch
|
|
fake_package.xmlrpc = fake_module
|
|
|
|
monkeypatch.setitem(sys.modules, "defusedxml", fake_package)
|
|
monkeypatch.setitem(sys.modules, "defusedxml.xmlrpc", fake_module)
|
|
monkeypatch.setattr(utils, "_xmlrpc_patch_applied", False)
|
|
|
|
client_module = utils.get_hardened_xmlrpc_client()
|
|
|
|
assert client_module is stdlib_xmlrpc_client
|
|
assert utils._xmlrpc_patch_applied is False
|