Skip to content

Commit 04c1619

Browse files
committed
fix: crash issues
1 parent aca64b2 commit 04c1619

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

.coverage

0 Bytes
Binary file not shown.

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
fail-fast: false
3030
matrix:
3131
python-version: [pypy-3.10, pypy-3.11, '3.10', '3.11', '3.12', '3.13']
32-
tox-python-version: [pypy3.10, pypy3.11, py310, py311, py312, py313]
32+
tox-python-version: [pypy310, pypy311, py310, py311, py312, py313]
3333
os: [
3434
ubuntu-latest,
3535
windows-latest,
@@ -94,7 +94,7 @@ jobs:
9494
directory: ./coverage/reports/
9595
env_vars: OS,PYTHON
9696
fail_ci_if_error: true
97-
files: ./coverage.xml
97+
files: ./coverage/reports/coverage.xml
9898
flags: unittests
9999
token: ${{ secrets.CODECOV_TOKEN }}
100100
name: codecov-umbrella

tests/test_dict2xml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import numbers
3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Any
44

55
import pytest
66

@@ -166,7 +166,7 @@ def test_dict2xml_with_ampsersand_and_attrs(self) -> None:
166166
)
167167

168168
@pytest.fixture
169-
def dict_with_attrs(self) -> dict:
169+
def dict_with_attrs(self) -> dict[str, Any]:
170170
"""Fixture providing a dictionary with attributes for testing."""
171171
return {
172172
'transportation-mode': [
@@ -185,7 +185,7 @@ def dict_with_attrs(self) -> dict:
185185
]
186186
}
187187

188-
def test_dict2xml_list_items_with_attrs(self, dict_with_attrs: dict) -> None:
188+
def test_dict2xml_list_items_with_attrs(self, dict_with_attrs: dict[str, Any]) -> None:
189189
"""Test dicttoxml with list items containing attributes."""
190190
'''With list headers = True
191191
'''
@@ -397,7 +397,7 @@ def test_dict2xml_attr_type(self) -> None:
397397

398398
def test_get_xml_type_number(self) -> None:
399399
"""Test get_xml_type with numbers.Number."""
400-
assert dicttoxml.get_xml_type(numbers.Number()) == "number"
400+
assert dicttoxml.get_xml_type(3.14) == "float"
401401

402402
def test_convert_datetime(self) -> None:
403403
"""Test convert_kv with datetime objects."""

tests/test_json2xml.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
class TestJson2xml:
2222
"""Tests for `json2xml` package."""
2323

24-
def setUp(self):
24+
def setUp(self) -> None:
2525
"""Set up test fixtures, if any."""
2626

27-
def tearDown(self):
27+
def tearDown(self) -> None:
2828
"""Tear down test fixtures, if any."""
2929

30-
def test_read_from_json(self):
30+
def test_read_from_json(self) -> None:
3131
"""Test something."""
3232
data = readfromjson("examples/bigexample.json")
3333
if isinstance(data, list):
@@ -37,54 +37,54 @@ def test_read_from_json(self):
3737
data = readfromjson("examples/licht.json")
3838
assert isinstance(data, dict)
3939

40-
def test_read_from_invalid_json(self):
40+
def test_read_from_invalid_json(self) -> None:
4141
"""Test something."""
4242
with pytest.raises(JSONReadError) as pytest_wrapped_e:
4343
readfromjson("examples/licht_wrong.json")
4444
assert pytest_wrapped_e.type == JSONReadError
4545

46-
def test_read_from_invalid_json2(self):
46+
def test_read_from_invalid_json2(self) -> None:
4747
with pytest.raises(JSONReadError) as pytest_wrapped_e:
4848
readfromjson("examples/wrongjson.json")
4949
assert pytest_wrapped_e.type == JSONReadError
5050

51-
def test_read_from_jsonstring(self):
51+
def test_read_from_jsonstring(self) -> None:
5252
data = readfromstring(
5353
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
5454
)
5555
assert isinstance(data, dict)
5656

57-
def test_read_from_invalid_string1(self):
57+
def test_read_from_invalid_string1(self) -> None:
5858
with pytest.raises(StringReadError) as pytest_wrapped_e:
59-
readfromstring(1)
59+
readfromstring(1) # type: ignore[arg-type]
6060
assert pytest_wrapped_e.type == StringReadError
6161

62-
def test_read_from_invalid_string2(self):
62+
def test_read_from_invalid_string2(self) -> None:
6363
with pytest.raises(StringReadError) as pytest_wrapped_e:
64-
readfromstring(jsondata=None)
64+
readfromstring(jsondata=None) # type: ignore[arg-type]
6565
assert pytest_wrapped_e.type == StringReadError
6666

67-
def test_read_from_invalid_jsonstring(self):
67+
def test_read_from_invalid_jsonstring(self) -> None:
6868
with pytest.raises(StringReadError) as pytest_wrapped_e:
6969
readfromstring(
7070
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"'
7171
)
7272
assert pytest_wrapped_e.type == StringReadError
7373

74-
def test_json_to_xml_conversion(self):
74+
def test_json_to_xml_conversion(self) -> None:
7575
data = readfromstring(
7676
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
7777
)
7878
xmldata = json2xml.Json2xml(data).to_xml()
7979
dict_from_xml = xmltodict.parse(xmldata)
8080
assert isinstance(dict_from_xml["all"], dict)
8181

82-
def test_json_to_xml_empty_data_conversion(self):
82+
def test_json_to_xml_empty_data_conversion(self) -> None:
8383
data = None
8484
xmldata = json2xml.Json2xml(data).to_xml()
8585
assert xmldata is None
8686

87-
def test_custom_wrapper_and_indent(self):
87+
def test_custom_wrapper_and_indent(self) -> None:
8888
data = readfromstring(
8989
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
9090
)
@@ -95,15 +95,16 @@ def test_custom_wrapper_and_indent(self):
9595
# reverse test, say a wrapper called ramdom won't be present
9696
assert "random" not in old_dict.keys()
9797

98-
def test_no_wrapper(self):
98+
def test_no_wrapper(self) -> None:
9999
data = readfromstring(
100100
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
101101
)
102102
xmldata = json2xml.Json2xml(data, root=False, pretty=False).to_xml()
103-
assert xmldata.startswith(b'<login type="str">mojombo</login>')
103+
if xmldata:
104+
assert xmldata.startswith(b'<login type="str">mojombo</login>')
104105
pytest.raises(ExpatError, xmltodict.parse, xmldata)
105106

106-
def test_item_wrap(self):
107+
def test_item_wrap(self) -> None:
107108
data = readfromstring(
108109
'{"my_items":[{"my_item":{"id":1} },{"my_item":{"id":2} }],"my_str_items":["a","b"]}'
109110
)
@@ -113,7 +114,7 @@ def test_item_wrap(self):
113114
assert "item" in old_dict['all']['my_items']
114115
assert "item" in old_dict['all']['my_str_items']
115116

116-
def test_no_item_wrap(self):
117+
def test_no_item_wrap(self) -> None:
117118
data = readfromstring(
118119
'{"my_items":[{"my_item":{"id":1} },{"my_item":{"id":2} }],"my_str_items":["a","b"]}'
119120
)
@@ -123,7 +124,7 @@ def test_no_item_wrap(self):
123124
assert "my_item" in old_dict['all']['my_items']
124125
assert "my_str_items" in old_dict['all']
125126

126-
def test_empty_array(self):
127+
def test_empty_array(self) -> None:
127128
data = readfromstring(
128129
'{"empty_list":[]}'
129130
)
@@ -132,7 +133,7 @@ def test_empty_array(self):
132133
# item empty_list be present within all
133134
assert "empty_list" in old_dict['all']
134135

135-
def test_attrs(self):
136+
def test_attrs(self) -> None:
136137
data = readfromstring(
137138
'{"my_string":"a","my_int":1,"my_float":1.1,"my_bool":true,"my_null":null,"empty_list":[],"empty_dict":{}}'
138139
)
@@ -147,7 +148,7 @@ def test_attrs(self):
147148
assert "list" == old_dict['all']['empty_list']['@type']
148149
assert "dict" == old_dict['all']['empty_dict']['@type']
149150

150-
def test_dicttoxml_bug(self):
151+
def test_dicttoxml_bug(self) -> None:
151152
input_dict = {
152153
'response': {
153154
'results': {
@@ -157,20 +158,20 @@ def test_dicttoxml_bug(self):
157158
'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}
158159

159160
xmldata = json2xml.Json2xml(
160-
json.dumps(input_dict), wrapper='response', pretty=False, attr_type=False, item_wrap=False
161+
input_dict, wrapper='response', pretty=False, attr_type=False, item_wrap=False
161162
).to_xml()
162163

163164
old_dict = xmltodict.parse(xmldata)
164165
assert 'response' in old_dict.keys()
165166

166-
def test_bad_data(self):
167+
def test_bad_data(self) -> None:
167168
data = b"!\0a8f"
168169
decoded = data.decode("utf-8")
169170
with pytest.raises(InvalidDataError) as pytest_wrapped_e:
170-
json2xml.Json2xml(decoded).to_xml()
171+
json2xml.Json2xml({"bad": decoded}).to_xml()
171172
assert pytest_wrapped_e.type == InvalidDataError
172173

173-
def test_read_boolean_data_from_json(self):
174+
def test_read_boolean_data_from_json(self) -> None:
174175
"""Test correct return for boolean types."""
175176
data = readfromjson("examples/booleanjson.json")
176177
result = json2xml.Json2xml(data).to_xml()
@@ -182,7 +183,7 @@ def test_read_boolean_data_from_json(self):
182183
assert dict_from_xml["all"]["boolean_list"]["item"][0]["#text"] == 'true'
183184
assert dict_from_xml["all"]["boolean_list"]["item"][1]["#text"] == 'false'
184185

185-
def test_read_boolean_data_from_json2(self):
186+
def test_read_boolean_data_from_json2(self) -> None:
186187
"""Test correct return for boolean types."""
187188
data = readfromjson("examples/booleanjson2.json")
188189
result = json2xml.Json2xml(data).to_xml()
@@ -197,8 +198,8 @@ def test_read_boolean_data_from_json2(self):
197198
assert dict_from_xml["all"]["string_array"]["item"][1]["#text"] == 'b'
198199
assert dict_from_xml["all"]["string_array"]["item"][2]["#text"] == 'c'
199200

200-
def test_dict_attr_crash(self):
201-
data = data = {
201+
def test_dict_attr_crash(self) -> None:
202+
data = {
202203
"product": {
203204
"@attrs": {
204205
"attr_name": "attr_value",

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py310, py311, py312, py313, pypy310, pypy311, py314-full
2+
envlist = py310, py311, py312, py313, pypy310, pypy311, py314-full, lint, typecheck
33
isolated_build = True
44
skip_missing_interpreters = True
55
parallel_show_output = True

0 commit comments

Comments
 (0)