Skip to content

Commit

Permalink
Fix warning test (#113)
Browse files Browse the repository at this point in the history
* dev requirements

* multiline import

* fix warnings when running tests
  • Loading branch information
Jeroendevr authored Feb 24, 2022
1 parent 1d833b1 commit fd9df50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# When installing dev dependencies also install the user dependencies
-r requirements.txt

flake8
pytest
31 changes: 19 additions & 12 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from json2xml import json2xml
from json2xml.dicttoxml import dicttoxml
from json2xml.utils import InvalidDataError, readfromjson, readfromstring, readfromurl, JSONReadError, StringReadError, URLReadError
from json2xml.utils import InvalidDataError, readfromjson, readfromstring, readfromurl, \
JSONReadError, StringReadError, URLReadError


class TestJson2xml(unittest.TestCase):
Expand All @@ -38,7 +39,7 @@ def test_read_from_json(self):
def test_read_from_invalid_json(self):
"""Test something."""
with pytest.raises(JSONReadError) as pytest_wrapped_e:
data = readfromjson("examples/licht_wrong.json")
readfromjson("examples/licht_wrong.json")
assert pytest_wrapped_e.type == JSONReadError

def test_read_from_url(self):
Expand All @@ -47,7 +48,7 @@ def test_read_from_url(self):

def test_read_from_wrong_url(self):
with pytest.raises(URLReadError) as pytest_wrapped_e:
data = readfromurl("https://coderwall.com/vinitcool76.jsoni")
readfromurl("https://coderwall.com/vinitcool76.jsoni")
assert pytest_wrapped_e.type == URLReadError

def test_read_from_jsonstring(self):
Expand All @@ -58,7 +59,7 @@ def test_read_from_jsonstring(self):

def test_read_from_invalid_jsonstring(self):
with pytest.raises(StringReadError) as pytest_wrapped_e:
data = readfromstring(
readfromstring(
'{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"'
)
assert pytest_wrapped_e.type == StringReadError
Expand Down Expand Up @@ -139,13 +140,18 @@ def test_attrs(self):
assert "dict" == old_dict['all']['empty_dict']['@type']

def test_dicttoxml_bug(self):
input_dict = {'response': {'results': {'user': [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}
input_dict = {
'response': {
'results': {
'user': [{
'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'
}, {
'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}

xmldata = json2xml.Json2xml(
json.dumps(input_dict), wrapper='response', pretty=False, attr_type=False, item_wrap=False
).to_xml()

# with pytest.raises(AttributeError) as pytest_wrapped_e:
# json2xml.Json2xml(json.dumps(input_dict), wrapper='response', pretty=False, attr_type=False, item_wrap=False).to_xml()
# assert pytest_wrapped_e.type == AttributeError

xmldata = json2xml.Json2xml(json.dumps(input_dict), wrapper='response', pretty=False, attr_type=False, item_wrap=False).to_xml()
old_dict = xmltodict.parse(xmldata)
assert 'response' in old_dict.keys()

Expand All @@ -165,7 +171,8 @@ def test_dict2xml_with_custom_root(self):
assert b'<?xml version="1.0" encoding="UTF-8" ?><element><mock>payload</mock></element>' == result

def test_bad_data(self):
data = b"!\0a\8f".decode("utf-8")
data = b"!\0a8f"
decoded = data.decode("utf-8")
with pytest.raises(InvalidDataError) as pytest_wrapped_e:
result = json2xml.Json2xml(data).to_xml()
json2xml.Json2xml(decoded).to_xml()
assert pytest_wrapped_e.type == InvalidDataError

0 comments on commit fd9df50

Please sign in to comment.