Skip to content

Commit

Permalink
Updated release notes for 0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed Aug 1, 2017
1 parent 96b4785 commit 93011b1
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 19 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,13 @@
History
-------

0.1.9 (1 Aug 2017)
~~~~~~~~~~~~~~~~~~

- Bugfix and test cases for multiple nested children in Abdera_ convention

Thanks to @mukultaneja

0.1.8 (9 May 2017)
~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -3,3 +3,6 @@ universal = 1

[metadata]
license_file = LICENSE

[flake8]
ignore = E911
1 change: 1 addition & 0 deletions tests/abdera-1.json
@@ -0,0 +1 @@
{"Data":{"attributes":{"version":9.0,"{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation":"comp.xsd"},"children":[{"Airport":{"attributes":{"country":"Samoa","city":"Apia","name":"Faleolo Intl","lat":-13.8296668231487,"lon":-171.997166723013,"alt":"17.678M","ident":"NSFA"},"children":[{"Services":{"Fuel":{"attributes":{"type":"JETA","availability":"YES"}}}},{"Tower":{"attributes":{"lat":-13.8320958986878,"lon":-171.998676359653,"alt":"0.0M"}}},{"Runway":{"attributes":{"lat":-13.8300792127848,"lon":-172.008545994759,"alt":"17.678M","surface":"ASPHALT","heading":89.3199996948242,"length":"2999.23M","width":"45.11M","number":8,"designator":"NONE"}}}]}}]}}
1 change: 1 addition & 0 deletions tests/abdera-1.xml
@@ -0,0 +1 @@
<Data version="9.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="comp.xsd"><Airport country="Samoa" city="Apia" name="Faleolo Intl" lat="-13.8296668231487" lon="-171.997166723013" alt="17.678M" ident="NSFA"><Services><Fuel type="JETA" availability="YES"/></Services><Tower lat="-13.8320958986878" lon="-171.998676359653" alt="0.0M"></Tower><Runway lat="-13.8300792127848" lon="-172.008545994759" alt="17.678M" surface="ASPHALT" heading="89.3199996948242" length="2999.23M" width="45.11M" number="08" designator="NONE"></Runway></Airport></Data>
1 change: 1 addition & 0 deletions tests/abdera-2.json
@@ -0,0 +1 @@
{"root":{"children":[{"a":{"attributes":{"x": 1},"children":[{"b":{"c":{}}}]}},{"d":{"attributes":{"x": 1},"children":[{"e":{"f":{}}}]}},{"g":{"attributes":{"x": 1},"children":[{"h":{"i":{}}}]}}]}}
1 change: 1 addition & 0 deletions tests/abdera-2.xml
@@ -0,0 +1 @@
<root><a x="1"><b><c/></b></a><d x="1"><e><f/></e></d><g x="1"><h><i/></h></g></root>
1 change: 1 addition & 0 deletions tests/abdera-3.json
@@ -0,0 +1 @@
{"root": {"children": [{"a": {"attributes": {"x": 1}, "children": [{"b": {"c": {"d": {"attributes": {"x": 1}}}}}]}}, {"e": {"attributes": {"x": 1}, "children": [{"f": {"g": {"h": {"attributes": {"x": 1}}}}}]}}, {"i": {"attributes": {"x": 1}, "children": [{"j": {"k": {"l": {"attributes": {"x": 1}}}}}]}}]}}
1 change: 1 addition & 0 deletions tests/abdera-3.xml
@@ -0,0 +1 @@
<root><a x="1"><b><c><d x="1"/></c></b></a><e x="1"><f><g><h x="1"/></g></f></e><i x="1"><j><k><l x="1"/></k></j></i></root>
1 change: 1 addition & 0 deletions tests/abdera-4.json
@@ -0,0 +1 @@
{"root": {"a": {"attributes": {"x": 1}, "children": [{"b": {"attributes": {"x": 1}, "children": [{"c": {"attributes": {"x": 1}, "children": [{"d": {}}]}}]}}]}}}
1 change: 1 addition & 0 deletions tests/abdera-4.xml
@@ -0,0 +1 @@
<root><a x="1"><b x="1"><c x="1"><d/></c></b></a></root>
31 changes: 16 additions & 15 deletions tests/test_xmljson.py
Expand Up @@ -8,6 +8,8 @@
Tests for `xmljson` module.
'''

import io
import os
import sys
import json
import unittest
Expand All @@ -20,6 +22,8 @@
import xml.etree.cElementTree
import xmljson

_folder = os.path.dirname(os.path.abspath(__file__))

# For Python 3, decode byte strings as UTF-8
if sys.version_info[0] == 3:
def decode(s):
Expand All @@ -29,6 +33,11 @@ def decode(s):
return s


def read(path):
with io.open(os.path.join(_folder, path), 'r', encoding='utf-8') as handle:
return handle.read()


class TestXmlJson(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -126,8 +135,7 @@ def test_html(self):
('p', {'$': 'paragraph'}),
('hr', {}),
('ul', {'li': [{'$': '1'}, {'$': '2'}]}),
])},
'<div><p>paragraph</p><hr><ul><li>1</li><li>2</li></ul></div>')
])}, '<div><p>paragraph</p><hr><ul><li>1</li><li>2</li></ul></div>')

def test_data(self):
'BadgerFish conversion from etree to data'
Expand Down Expand Up @@ -587,17 +595,10 @@ def test_data(self):
'<alice charlie="david">bob</alice>')

# Nested elements with more than one children
eq('{"Data":{"attributes":{"version":9.0,"{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation":"comp.xsd"},"children":[{"Airport":{"attributes":{"country":"Samoa","city":"Apia","name":"Faleolo Intl","lat":-13.8296668231487,"lon":-171.997166723013,"alt":"17.678M","ident":"NSFA"},"children":[{"Services":{"Fuel":{"attributes":{"type":"JETA","availability":"YES"}}}},{"Tower":{"attributes":{"lat":-13.8320958986878,"lon":-171.998676359653,"alt":"0.0M"}}},{"Runway":{"attributes":{"lat":-13.8300792127848,"lon":-172.008545994759,"alt":"17.678M","surface":"ASPHALT","heading":89.3199996948242,"length":"2999.23M","width":"45.11M","number":8,"designator":"NONE"}}}]}}]}}',
'<Data version="9.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="comp.xsd"><Airport country="Samoa" city="Apia" name="Faleolo Intl" lat="-13.8296668231487" lon="-171.997166723013" alt="17.678M" ident="NSFA"><Services><Fuel type="JETA" availability="YES"/></Services><Tower lat="-13.8320958986878" lon="-171.998676359653" alt="0.0M"></Tower><Runway lat="-13.8300792127848" lon="-172.008545994759" alt="17.678M" surface="ASPHALT" heading="89.3199996948242" length="2999.23M" width="45.11M" number="08" designator="NONE"></Runway></Airport></Data>')

eq('{"root":{"children":[{"a":{"attributes":{"x": 1},"children":[{"b":{"c":{}}}]}},{"d":{"attributes":{"x": 1},"children":[{"e":{"f":{}}}]}},{"g":{"attributes":{"x": 1},"children":[{"h":{"i":{}}}]}}]}}',
'<root><a x="1"><b><c/></b></a><d x="1"><e><f/></e></d><g x="1"><h><i/></h></g></root>')

eq('{"root": {"children": [{"a": {"attributes": {"x": 1}, "children": [{"b": {"c": {"d": {"attributes": {"x": 1}}}}}]}}, {"e": {"attributes": {"x": 1}, "children": [{"f": {"g": {"h": {"attributes": {"x": 1}}}}}]}}, {"i": {"attributes": {"x": 1}, "children": [{"j": {"k": {"l": {"attributes": {"x": 1}}}}}]}}]}}',
'<root><a x="1"><b><c><d x="1"/></c></b></a><e x="1"><f><g><h x="1"/></g></f></e><i x="1"><j><k><l x="1"/></k></j></i></root>')

eq('{"root": {"a": {"attributes": {"x": 1}, "children": [{"b": {"attributes": {"x": 1}, "children": [{"c": {"attributes": {"x": 1}, "children": [{"d": {}}]}}]}}]}}}',
'<root><a x="1"><b x="1"><c x="1"><d/></c></b></a></root>')
eq(read('abdera-1.json'), read('abdera-1.xml'))
eq(read('abdera-2.json'), read('abdera-2.xml'))
eq(read('abdera-3.json'), read('abdera-3.xml'))
eq(read('abdera-4.json'), read('abdera-4.xml'))


class TestCobra(TestXmlJson):
Expand All @@ -620,8 +621,8 @@ def test_data(self):
'<x><a/></x>')
eq('{"x": {"attributes": {"x": "1"}}}',
'<x x="1"/>')
eq('{"root": {"attributes": {}, "children": [{"x": {"attributes": {"x": "1"}}},'
+ ' {"y": {"attributes": {}, "children": [{"z": {"attributes": {}}}]}}]}}',
eq('{"root": {"attributes": {}, "children": [{"x": {"attributes": {"x": "1"}}},' +
' {"y": {"attributes": {}, "children": [{"z": {"attributes": {}}}]}}]}}',
'<root><x x="1"/><y><z/></y></root>')

# Attributes
Expand Down
8 changes: 4 additions & 4 deletions xmljson/__init__.py
Expand Up @@ -9,7 +9,7 @@

__author__ = 'S Anand'
__email__ = 'root.node@gmail.com'
__version__ = '0.1.8'
__version__ = '0.1.9'

# Python 3: define unicode() as str()
if sys.version_info[0] == 3:
Expand Down Expand Up @@ -272,9 +272,9 @@ def data(self, root):
count = Counter(child.tag for child in children)
for child in children:
child_data = self.data(child)
if (count[child.tag] == 1
and len(children_list) > 1
and isinstance(children_list[-1], dict)):
if (count[child.tag] == 1 and
len(children_list) > 1 and
isinstance(children_list[-1], dict)):
# Merge keys to existing dictionary
children_list[-1].update(child_data)
else:
Expand Down

0 comments on commit 93011b1

Please sign in to comment.