[GRASS-SVN] r60697 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 3 20:27:35 PDT 2014


Author: wenzeslaus
Date: 2014-06-03 20:27:34 -0700 (Tue, 03 Jun 2014)
New Revision: 60697

Modified:
   grass/trunk/lib/python/script/core.py
Log:
pythonlib/script: more doctests for core

Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2014-06-04 02:40:24 UTC (rev 60696)
+++ grass/trunk/lib/python/script/core.py	2014-06-04 03:27:34 UTC (rev 60697)
@@ -659,6 +659,17 @@
     """!Returns separator from G_OPT_F_SEP appropriately converted
     to character.
 
+    >>> separator('pipe')
+    '|'
+    >>> separator('comma')
+    ','
+
+    If the string does not match any of the spearator keywords,
+    it is returned as is:
+
+    >>> separator(', ')
+    ', '
+
     @param separator character or separator keyword
 
     @return separator character
@@ -674,7 +685,6 @@
     elif sep == "newline" or sep == "\\n":
         return "\n"
     return sep
-    
 
 # interface to g.tempfile
 
@@ -733,11 +743,17 @@
     """!Parse a string into a dictionary, where entries are separated
     by newlines and the key and value are separated by `sep' (default: `=')
 
+    >>> parse_key_val('min=20\\nmax=50') == {'min': '20', 'max': '50'}
+    True
+    >>> parse_key_val('min=20\\nmax=50',
+    ...     val_type=float) == {'min': 20, 'max': 50}
+    True
+
     @param s string to be parsed
     @param sep key/value separator
     @param dflt default value to be used
     @param val_type value type (None for no cast)
-    @param vsep vertical separator (default os.linesep)
+    @param vsep vertical separator (default is Python 'universal newlines' approach)
 
     @return parsed input (dictionary of keys/values)
     """
@@ -1436,20 +1452,23 @@
         name = fs[0]
     return name
 
+
 def find_program(pgm, *args):
     """!Attempt to run a program, with optional arguments.
+
     You must call the program in a way that will return a successful
     exit code. For GRASS modules this means you need to pass it some
     valid CLI option, like "--help". For other programs a common
-    valid do-little option is "--version".
-    
+    valid do-little option is usually "--version".
+
     Example:
 
     @code
-    >>> grass.find_program('r.sun', 'help')
+    >>> find_program('r.sun', '--help')
     True
-    >>> grass.find_program('gdalwarp', '--version')
+    >>> find_program('ls', '--version')
     True
+
     @endcode
 
     @param pgm program name
@@ -1461,6 +1480,7 @@
     """
     nuldev = file(os.devnull, 'w+')
     try:
+        # TODO: the doc or impl is not correct, any return code is accepted
         call([pgm] + list(args), stdin = nuldev, stdout = nuldev, stderr = nuldev)
         found = True
     except:
@@ -1501,6 +1521,11 @@
 def float_or_dms(s):
     """!Convert DMS to float.
 
+    >>> round(float_or_dms('26:45:30'), 5)
+    26.75833
+    >>> round(float_or_dms('26:0:0.1'), 5)
+    26.00003
+
     @param s DMS value
 
     @return float value



More information about the grass-commit mailing list