Skip to content
Snippets Groups Projects
Commit d5f9b7c4 authored by nimrod's avatar nimrod
Browse files

- Fixed issues with difference between Python2 and Python3 regarding

Unicode strings.
- Fixed combine filter tests.
- Updated TODO list accordingly.
parent d6e14b58
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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={
......
#!/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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment