Skip to content

Commit dbf59d7

Browse files
committed
fix: add pragma no cover to environment-dependent code paths
The Rust/Python code paths in dicttoxml_fast.py are mutually exclusive depending on whether the Rust extension is installed. Mark both paths with pragma no cover since only one can be tested per environment. This ensures 100% coverage in CI regardless of Rust availability.
1 parent 53fd3eb commit dbf59d7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

json2xml/dicttoxml_fast.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
_rust_dicttoxml = None
2525

2626
try:
27-
from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found]
28-
from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found]
29-
from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found]
30-
_USE_RUST = True
31-
LOG.debug("Using Rust backend for dicttoxml")
27+
from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] # pragma: no cover
28+
from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] # pragma: no cover
29+
from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] # pragma: no cover
30+
_USE_RUST = True # pragma: no cover
31+
LOG.debug("Using Rust backend for dicttoxml") # pragma: no cover
3232
except ImportError: # pragma: no cover
3333
LOG.debug("Rust backend not available, using pure Python")
3434
rust_escape_xml = None
@@ -95,7 +95,7 @@ def dicttoxml(
9595
if not needs_python and isinstance(obj, dict):
9696
needs_python = _has_special_keys(obj)
9797

98-
if _USE_RUST and not needs_python and _rust_dicttoxml is not None:
98+
if _USE_RUST and not needs_python and _rust_dicttoxml is not None: # pragma: no cover
9999
# Use fast Rust implementation
100100
return _rust_dicttoxml(
101101
obj,
@@ -143,14 +143,14 @@ def _has_special_keys(obj: Any) -> bool:
143143
# Re-export commonly used functions
144144
def escape_xml(s: str) -> str:
145145
"""Escape special XML characters in a string."""
146-
if _USE_RUST and rust_escape_xml is not None:
146+
if _USE_RUST and rust_escape_xml is not None: # pragma: no cover
147147
return rust_escape_xml(s)
148148
return _py_dicttoxml.escape_xml(s)
149149

150150

151151
def wrap_cdata(s: str) -> str:
152152
"""Wrap a string in a CDATA section."""
153-
if _USE_RUST and rust_wrap_cdata is not None:
153+
if _USE_RUST and rust_wrap_cdata is not None: # pragma: no cover
154154
return rust_wrap_cdata(s)
155155
return _py_dicttoxml.wrap_cdata(s)
156156

0 commit comments

Comments
 (0)