2121class 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"!\0 a8f"
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" ,
0 commit comments