diff --git a/rinse/tests/test_util.py b/rinse/tests/test_util.py new file mode 100755 index 0000000..589cbeb --- /dev/null +++ b/rinse/tests/test_util.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Unit tests for rinse.util module.""" + +import unittest +import six +from lxml import etree + +from ..util import recursive_dict + + +class TestRecursiveDict(unittest.TestCase): + def test_recursive_dict_function(self): + doc = etree.fromstring(six.b(''' + + + + + 1234567890 + + 0 + No Error + + + + + + ''')) + + recursive_dict(doc) diff --git a/rinse/util.py b/rinse/util.py index 120c736..fae3de4 100644 --- a/rinse/util.py +++ b/rinse/util.py @@ -8,6 +8,7 @@ import defusedxml.lxml import lxml.builder from lxml import etree +import six RINSE_DIR = os.path.dirname(__file__) ENVELOPE_XSD = 'soap-1.1_envelope.xsd' @@ -160,14 +161,13 @@ def recursive_dict(element): for child in element ) + if six.PY2: + kwargs = {'width': 10000} + else: + kwargs = {'compact': True, 'width': 10000} return ( - '{}{}'.format( - element.tag, - pprint.pformat(element.attrib, compact=True, width=10000), - ), - dict( - map(recursive_dict, element) - ) or element.text + '{}{}'.format(element.tag, pprint.pformat(element.attrib, **kwargs)), + dict(map(recursive_dict, element)) or element.text )