From 13668c6bf8f613c4e560f11e1a72e7e17551b108 Mon Sep 17 00:00:00 2001 From: Jeroen de Vries Date: Thu, 24 Feb 2022 13:59:32 +0100 Subject: [PATCH 1/3] dev requirements --- dev-requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 dev-requirements.txt diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..eaaac07 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,5 @@ +# When installing dev dependencies also install the user dependencies +-r requirements.txt + +flake8 +pytest \ No newline at end of file From 8623739ed44f5454653867e2e38c7c3c66d3b5d5 Mon Sep 17 00:00:00 2001 From: Jeroen de Vries Date: Thu, 24 Feb 2022 14:02:53 +0100 Subject: [PATCH 2/3] multiline import --- tests/test_json2xml.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_json2xml.py b/tests/test_json2xml.py index 75b5f4f..9ef0e38 100644 --- a/tests/test_json2xml.py +++ b/tests/test_json2xml.py @@ -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): From 39bba1af7f0709b2b110d8f4c8092e4396815906 Mon Sep 17 00:00:00 2001 From: Jeroen de Vries Date: Thu, 24 Feb 2022 14:37:01 +0100 Subject: [PATCH 3/3] fix warnings when running tests --- tests/test_json2xml.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/test_json2xml.py b/tests/test_json2xml.py index 9ef0e38..bbf7ae4 100644 --- a/tests/test_json2xml.py +++ b/tests/test_json2xml.py @@ -39,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): @@ -48,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): @@ -59,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 @@ -140,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() @@ -166,7 +171,8 @@ def test_dict2xml_with_custom_root(self): assert b'payload' == 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