diff --git a/README.rst b/README.rst index 26b35817c605cec88b648cbb3bef24f6bdb9e752..8f157c163a50b9b8a1280ad51143ed8261adc799 100644 --- a/README.rst +++ b/README.rst @@ -79,8 +79,6 @@ at: https://www.shore.co.il/git/. TODO ---- -- Fix unicode strings in Python 2.7 only doctests in :code:`load_json`. -- Fix combining dictionaries test. - Fix Travis CI test on Python 3.2 (https://travis-ci.org/adarnimrod/template/jobs/187388235). - Release on tagged commits to PyPI in Travis CI (https://docs.travis-ci.com/user/deployment/pypi/ and diff --git a/setup.py b/setup.py index 68c110afa8b5485f2ca86cd5ae5c449e9f3fddd2..7abfd3bcff29369202de230eacb8355750b384e8 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( ], keywords='config configuration jinja template environment', packages=find_packages(), - install_requires=['Jinja2', 'PyYAML'], + install_requires=['Jinja2', 'PyYAML', 'six'], extras_require={ 'dev': ['tox'], }, entry_points={ diff --git a/template/filters.py b/template/filters.py index d060d2ca1cea13a566933a7a050de57a0ded46b4..133ecbbbaac71916a11b84475754b02490eed07d 100644 --- a/template/filters.py +++ b/template/filters.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from __future__ import (absolute_import, division, print_function, unicode_literals) +import six # noqa: F401 def to_yaml(value): @@ -46,10 +47,10 @@ def from_json(value): >>> from_json('[1, 2, 3]') [1, 2, 3] - >>> from_json('"a"') - u'a' - >>> from_json('{"1": {"a": [1, 2, 3]}}') - {u'1': {u'a': [1, 2, 3]}} + >>> from_json('"a"') == six.text_type(u'a') + True + >>> from_json('{"1": {"a": [1, 2, 3]}}') == {u'1': {u'a': [1, 2, 3]}} + True ''' from json import loads return loads(value) @@ -77,8 +78,13 @@ def pprint(value): Examples: >>> pprint(1) '1' - >>> pprint([{'first_name': 'John', 'last_name': 'Doe'}, {'first_name': 'Jane', 'last_name': 'Doe'}]) # noqa: E501 - "[{'first_name': 'John', 'last_name': 'Doe'},\\n {'first_name': 'Jane', 'last_name': 'Doe'}]" + >>> output = pprint([{'first_name': 'John', 'last_name': 'Doe'}, {'first_name': 'Jane', 'last_name': 'Doe'}]) # noqa: E501 + >>> if six.PY3: + ... output == "[{'first_name': 'John', 'last_name': 'Doe'},\\n {'first_name': 'Jane', 'last_name': 'Doe'}]" + ... elif six.PY2: + ... output == "[{u'first_name': u'John', u'last_name': u'Doe'},\\n {u'first_name': u'Jane', u'last_name': u'Doe'}]" + ... + True ''' from pprint import pformat return pformat(value) @@ -89,12 +95,7 @@ def combine(default, override): Returns a combined dictionary of the 2 dictionaries given (with the 2nd overriding the 1st). Examples: - >>> combined = combine({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) - >>> 'a' in combined - True - >>> 'c' in combined - True - >>> combined['b'] == 3 + >>> combine({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) == {'a': 1, 'b': 3, 'c': 4} True ''' combined = default.copy()