From 2cc629c601481231f1849c115d360e66d24934af Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Thu, 29 Dec 2016 22:42:08 +0200
Subject: [PATCH] - More doctests. - Updated TODO list.

---
 README.rst          |  2 +-
 template/filters.py | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index 31bb096..19293ab 100644
--- a/README.rst
+++ b/README.rst
@@ -78,7 +78,7 @@ at: https://www.shore.co.il/git/.
 TODO
 ----
 
-- Add unit tests of filters using doctest.
+- 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
diff --git a/template/filters.py b/template/filters.py
index 993435a..7266921 100644
--- a/template/filters.py
+++ b/template/filters.py
@@ -1,4 +1,6 @@
 #!/usr/bin/env python
+from __future__ import (absolute_import, division,
+                        print_function, unicode_literals)
 
 
 def to_yaml(value):
@@ -20,16 +22,51 @@ def to_yaml(value):
 
 
 def to_json(value):
+    '''
+    Converts given data structure to JSON form.
+    Examples:
+
+    >>> to_json([1,2,3])
+    '[1, 2, 3]'
+    >>> to_json({'b':2})
+    '{"b": 2}'
+    >>> to_json(2)
+    '2'
+    >>> to_json({1: {'a': [1,2,3]}})
+    '{"1": {"a": [1, 2, 3]}}'
+    '''
     from json import dumps
     return dumps(value)
 
 
 def from_json(value):
+    '''
+    Returns native data structure from the given JSON string.
+    Examples:
+
+    >>> 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 import loads
     return loads(value)
 
 
 def from_yaml(value):
+    '''
+    Returns native data structure from the given YAML string.
+    Examples:
+
+    >>> from_yaml('a')
+    'a'
+    >>> from_yaml('[1, 2, 3]')
+    [1, 2, 3]
+    >>> from_yaml('{"1": {"a": [1, 2, 3]}}')
+    {'1': {'a': [1, 2, 3]}}
+    '''
     from yaml import safe_load
     return safe_load(value)
 
-- 
GitLab