Updated docstrings and doctests
authorThierry Florac <thierry.florac@onf.fr>
Mon, 19 Jun 2017 16:05:08 +0200
changeset 94 39095d40c406
parent 93 bf448402f41d
child 95 f6cc362670a6
Updated docstrings and doctests
src/pyams_utils/dict.py
--- a/src/pyams_utils/dict.py	Mon Jun 19 15:54:58 2017 +0200
+++ b/src/pyams_utils/dict.py	Mon Jun 19 16:05:08 2017 +0200
@@ -21,6 +21,34 @@
 
 
 def update_dict(input, key, value):
-    """Update given mapping if input value is not null"""
+    """Update given mapping if input value is a boolean 'true' value
+
+    :param dict input: input dictionary
+    :param key: mapping key
+    :param value: new value
+
+    'False' values leave mapping unchanged::
+
+    >>> from pyams_utils.dict import update_dict
+    >>> mydict = {}
+    >>> update_dict(mydict, 'key1', None)
+    >>> mydict
+    {}
+    >>> update_dict(mydict, 'key1', '')
+    >>> mydict
+    {}
+    >>> update_dict(mydict, 'key1', 0)
+    >>> mydict
+    {}
+
+    'True' values modify the mapping::
+
+    >>> update_dict(mydict, 'key1', 'value')
+    >>> mydict
+    {'key1': 'value'}
+    >>> update_dict(mydict, 'key1', 'value2')
+    >>> mydict
+    {'key1': 'value2'}
+    """
     if value:
         input[key] = value