From 36d7fdea01f35f4d1dfbb3e9fbcb830175857b0e Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Mon, 23 Jan 2017 07:25:29 +0200 Subject: [PATCH] - Added doctests to pprint and combine filters. --- template/filters.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/template/filters.py b/template/filters.py index 7266921..d060d2c 100644 --- a/template/filters.py +++ b/template/filters.py @@ -72,11 +72,31 @@ def from_yaml(value): def pprint(value): + ''' + Returns a pretty string representation of the data structure given. + 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'}]" + ''' from pprint import pformat return pformat(value) 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 + True + ''' combined = default.copy() combined.update(override) return combined -- GitLab