[GRASS-SVN] r61512 - in grass/trunk/lib/python/pygrass/modules/interface: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 4 05:46:46 PDT 2014
Author: zarch
Date: 2014-08-04 05:46:46 -0700 (Mon, 04 Aug 2014)
New Revision: 61512
Modified:
grass/trunk/lib/python/pygrass/modules/interface/read.py
grass/trunk/lib/python/pygrass/modules/interface/testsuite/test_modules.py
Log:
pygrass: Substitute lambda with function to make Module instances pickable
Modified: grass/trunk/lib/python/pygrass/modules/interface/read.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/read.py 2014-08-04 12:44:03 UTC (rev 61511)
+++ grass/trunk/lib/python/pygrass/modules/interface/read.py 2014-08-04 12:46:46 UTC (rev 61512)
@@ -8,34 +8,44 @@
with_statement, print_function, unicode_literals)
+def do_nothing(p):
+ return p
+
+
+def get_None(p):
+ return None
+
+
+def get_dict(p):
+ return dict(p.items())
+
+
+def get_values(p):
+ return [e.text.strip() for e in p.findall('value/name')]
+
+
+def read_text(p):
+ return p.text.strip()
+
+
def read_keydesc(par):
name = par.text.strip()
items = [e.text.strip() for e in par.findall('item')]
return name, tuple(items) if len(items) > 1 else None
-#
-# this dictionary is used to extract the value of interest from the xml
-# the lambda experssion is used to define small simple functions,
-# is equivalent to: ::
-#
-# def f(p):
-# return p.text.strip()
-#
-# and then we call f(p)
-#
GETFROMTAG = {
- 'description': lambda p: p.text.strip(),
+ 'description': read_text,
'keydesc': read_keydesc,
- 'gisprompt': lambda p: dict(p.items()),
- 'default': lambda p: p.text.strip(),
- 'values': lambda p: [e.text.strip() for e in p.findall('value/name')],
- 'value': lambda p: None,
- 'guisection': lambda p: p.text.strip(),
- 'label': lambda p: p.text.strip(),
- 'suppress_required': lambda p: None,
- 'keywords': lambda p: p.text.strip(),
- 'guidependency': lambda p: p.text.strip(),
+ 'gisprompt': get_dict,
+ 'default': read_text,
+ 'values': get_values,
+ 'value': get_None,
+ 'guisection': read_text,
+ 'label': read_text,
+ 'suppress_required': get_None,
+ 'keywords': read_text,
+ 'guidependency': read_text,
}
GETTYPE = {
@@ -44,7 +54,7 @@
'float': float,
'double': float,
'file': str,
- 'all': lambda x: x,
+ 'all': do_nothing,
}
Modified: grass/trunk/lib/python/pygrass/modules/interface/testsuite/test_modules.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/testsuite/test_modules.py 2014-08-04 12:44:03 UTC (rev 61511)
+++ grass/trunk/lib/python/pygrass/modules/interface/testsuite/test_modules.py 2014-08-04 12:46:46 UTC (rev 61512)
@@ -34,5 +34,15 @@
__metaclass__ = TestModulesMeta
+class TestModulesPickability(TestCase):
+ def test_rsun(self):
+ """Test if a Module instance is pickable"""
+ import pickle
+ from StringIO import StringIO
+ out = StringIO()
+ pickle.dump(Module('r.sun'), out)
+ out.close()
+
+
if __name__ == '__main__':
test()
More information about the grass-commit
mailing list