Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning test #113

Merged
merged 3 commits into from
Feb 24, 2022
Merged
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
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