Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pygments==2.19.1
# accessible-pygments
# furo
# sphinx
requests==2.32.4
requests==2.33.0
# via sphinx
roman-numerals==4.1.0
# via sphinx
Expand Down
12 changes: 9 additions & 3 deletions json2xml/dicttoxml_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
_rust_dicttoxml = None

try:
from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] # pragma: no cover
from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] # pragma: no cover
from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] # pragma: no cover
from json2xml_rs import (
dicttoxml as _rust_dicttoxml, # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
)
from json2xml_rs import (
escape_xml_py as rust_escape_xml, # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
)
from json2xml_rs import (
wrap_cdata_py as rust_wrap_cdata, # type: ignore[import-not-found] # ty: ignore[unresolved-import] # pragma: no cover
)
_USE_RUST = True # pragma: no cover
LOG.debug("Using Rust backend for dicttoxml") # pragma: no cover
except ImportError: # pragma: no cover
Expand Down
10 changes: 5 additions & 5 deletions tests/test_dict2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class CustomClass:

# Should return the class name for unsupported types
# Using type: ignore for intentional test of unsupported type
result = dicttoxml.get_xml_type(CustomClass()) # type: ignore[arg-type]
result = dicttoxml.get_xml_type(CustomClass()) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
assert result == "CustomClass"

def test_make_valid_xml_name_invalid_chars(self) -> None:
Expand Down Expand Up @@ -807,8 +807,8 @@ def patched_get_unique_id(element: str) -> str:
this_id = module.make_id(element) # This exercises line 52
return ids[-1]

module.make_id = mock_make_id # type: ignore[assignment]
module.get_unique_id = patched_get_unique_id # type: ignore[assignment]
module.make_id = mock_make_id # type: ignore[assignment] # ty: ignore[invalid-assignment]
module.get_unique_id = patched_get_unique_id # type: ignore[assignment] # ty: ignore[invalid-assignment]

try:
result = dicttoxml.get_unique_id("test")
Expand Down Expand Up @@ -874,7 +874,7 @@ class CustomClass:

with pytest.raises(TypeError, match="Unsupported data type:"):
dicttoxml.convert(
obj=CustomClass(), # type: ignore[arg-type]
obj=CustomClass(), # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
ids=None,
attr_type=False,
item_func=lambda x: "item",
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def mock_is_primitive(val: Any) -> bool:
return True
return original_is_primitive(val)

module.is_primitive_type = mock_is_primitive # type: ignore[assignment]
module.is_primitive_type = mock_is_primitive # type: ignore[assignment] # ty: ignore[invalid-assignment]
try:
item = {"@val": {"test": "data"}}
result = dicttoxml.dict2xml_str(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def test_read_from_jsonstring(self) -> None:

def test_read_from_invalid_string1(self) -> None:
with pytest.raises(StringReadError) as pytest_wrapped_e:
readfromstring(1) # type: ignore[arg-type]
readfromstring(1) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
assert pytest_wrapped_e.type == StringReadError

def test_read_from_invalid_string2(self) -> None:
with pytest.raises(StringReadError) as pytest_wrapped_e:
readfromstring(jsondata=None) # type: ignore[arg-type]
readfromstring(jsondata=None) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
assert pytest_wrapped_e.type == StringReadError

def test_read_from_invalid_jsonstring(self) -> None:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_rust_dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

# Check if Rust extension is available
try:
from json2xml_rs import dicttoxml as rust_dicttoxml # type: ignore[import-not-found]
from json2xml_rs import escape_xml_py, wrap_cdata_py # type: ignore[import-not-found]
from json2xml_rs import (
dicttoxml as rust_dicttoxml, # type: ignore[import-not-found] # ty: ignore[unresolved-import]
)
from json2xml_rs import ( # type: ignore[import-not-found]
escape_xml_py, # ty: ignore[unresolved-import]
wrap_cdata_py, # ty: ignore[unresolved-import]
)
RUST_AVAILABLE = True
except ImportError:
RUST_AVAILABLE = False
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,22 @@ def test_readfromstring_complex_object(self) -> None:
def test_readfromstring_invalid_type_int(self) -> None:
"""Test reading with integer input."""
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
readfromstring(123) # type: ignore[arg-type]
readfromstring(123) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]

def test_readfromstring_invalid_type_list(self) -> None:
"""Test reading with list input."""
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
readfromstring(["not", "a", "string"]) # type: ignore[arg-type]
readfromstring(["not", "a", "string"]) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]

def test_readfromstring_invalid_type_dict(self) -> None:
"""Test reading with dict input."""
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
readfromstring({"not": "a string"}) # type: ignore[arg-type]
readfromstring({"not": "a string"}) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]

def test_readfromstring_invalid_type_none(self) -> None:
"""Test reading with None input."""
with pytest.raises(StringReadError, match="Input is not a proper JSON string"):
readfromstring(None) # type: ignore[arg-type]
readfromstring(None) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]

def test_readfromstring_invalid_json_syntax(self) -> None:
"""Test reading string with invalid JSON syntax."""
Expand Down
Loading