From 07820d362843fab759756f95af878af39efe8864 Mon Sep 17 00:00:00 2001 From: Matthew Schinckel Date: Thu, 28 Jan 2016 14:33:29 +1030 Subject: [PATCH 1/2] Ensure recursive_dict works on legacy python. --- rinse/tests/test_util.py | 35 +++++++++++++++++++++++++++++++++++ rinse/util.py | 14 +++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 rinse/tests/test_util.py diff --git a/rinse/tests/test_util.py b/rinse/tests/test_util.py new file mode 100755 index 0000000..859b01d --- /dev/null +++ b/rinse/tests/test_util.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Unit tests for rinse.util module.""" + +import unittest +from lxml import etree + +from ..util import recursive_dict + + +class TestRecursiveDict(unittest.TestCase): + def test_recursive_dict_function(self): + doc = etree.fromstring(''' + + + + + 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 ) From 765fc923dc24fb78736cf1ebfcfeef0c80661675 Mon Sep 17 00:00:00 2001 From: Matthew Schinckel Date: Thu, 28 Jan 2016 14:40:35 +1030 Subject: [PATCH 2/2] Remembers to test in all pythons. --- rinse/tests/test_util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rinse/tests/test_util.py b/rinse/tests/test_util.py index 859b01d..589cbeb 100755 --- a/rinse/tests/test_util.py +++ b/rinse/tests/test_util.py @@ -3,6 +3,7 @@ """Unit tests for rinse.util module.""" import unittest +import six from lxml import etree from ..util import recursive_dict @@ -10,7 +11,7 @@ class TestRecursiveDict(unittest.TestCase): def test_recursive_dict_function(self): - doc = etree.fromstring(''' + doc = etree.fromstring(six.b(''' - ''') + ''')) recursive_dict(doc)