Skip to content

Commit

Permalink
BUG: Yahoo should convert <x>0</x> into {x: 0}
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed Feb 11, 2019
1 parent 7cdba11 commit 2ecc206
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions tests/test_xmljson.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,14 @@ def test_xml_fromstring(self):


class TestYahoo(TestXmlJson):
@unittest.skip('To be written')
def test_etree(self):
'Yahoo conversion from data to etree'
pass
eq = self.check_etree(xmljson.yahoo)
eq({'x': ''}, '<x/>')
eq({'x': 0}, '<x>0</x>')
eq({'x': 'text'}, '<x>text</x>')
eq({'x': {'key': 'val'}}, '<x key="val"></x>')
eq({'x': {'key': 'val', 'content': 'text'}}, '<x key="val">text</x>')

def test_data(self):
'Yahoo conversion from etree to data'
Expand Down Expand Up @@ -577,9 +581,14 @@ def test_data(self):

eq(json.dumps(data), result)
eq('{"x": ""}', '<x/>')
eq('{"x": "0"}', '<x>0</x>')
eq('{"x": "False"}', '<x>False</x>')
eq('{"x": "text"}', '<x>text</x>')
eq('{"x": {"key": "val"}}', '<x key="val"></x>')
eq('{"x": {"key": "val", "content": "text"}}', '<x key="val">text</x>')
eq2 = self.check_data(xmljson.Yahoo(xml_fromstring=True))
eq2('{"x": 0}', '<x>0</x>')
eq2('{"x": false}', '<x>False</x>')

def test_xml_fromstring(self):
'xml_fromstring=False does not convert types'
Expand Down
4 changes: 2 additions & 2 deletions xmljson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def data(self, root):
else:
result = value.setdefault(child.tag, self.list())
result += self.data(child).values()
# if simple_text, elements with no children or attrs become '', not {}
if not value and self.simple_text:
# if simple_text, elements with no children nor attrs become '', not {}
if isinstance(value, dict) and not value and self.simple_text:
value = ''
return self.dict([(root.tag, value)])

Expand Down

0 comments on commit 2ecc206

Please sign in to comment.