[GRASS-SVN] r60998 - in sandbox/wenzeslaus/gunittest: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 26 14:19:13 PDT 2014


Author: wenzeslaus
Date: 2014-06-26 14:19:13 -0700 (Thu, 26 Jun 2014)
New Revision: 60998

Modified:
   sandbox/wenzeslaus/gunittest/gmodules.py
   sandbox/wenzeslaus/gunittest/testsuite/test_gmodules.py
Log:
gunittest: switch to TypeError from ValueError (more appropiate for bad keyword argument), add tests from #2326

Modified: sandbox/wenzeslaus/gunittest/gmodules.py
===================================================================
--- sandbox/wenzeslaus/gunittest/gmodules.py	2014-06-26 21:12:16 UTC (rev 60997)
+++ sandbox/wenzeslaus/gunittest/gmodules.py	2014-06-26 21:19:13 UTC (rev 60998)
@@ -52,7 +52,7 @@
     :raises CalledModuleError: if module return code is non-zero
     """
     if 'stdout' in kwargs:
-        raise ValueError('stdout argument not allowed, it would be overridden.')
+        raise TypeError('stdout argument not allowed, it would be overridden.')
     kwargs['stdout'] = subprocess.PIPE
     process = start_command(module, **kwargs)
     output = process.communicate()[0]
@@ -130,9 +130,9 @@
     if merge_stderr and not (capture_stdout and capture_stderr):
         raise ValueError(_("You cannot merge stdout and stderr and not capture them"))
     if 'stdout' in kwargs:
-        raise ValueError(_("stdout argument not allowed, it could be overridden"))
+        raise TypeError(_("stdout argument not allowed, it could be overridden"))
     if 'stderr' in kwargs:
-        raise ValueError(_("stderr argument not allowed, it could be overridden"))
+        raise TypeError(_("stderr argument not allowed, it could be overridden"))
 
     if capture_stdout:
         kwargs['stdout'] = subprocess.PIPE

Modified: sandbox/wenzeslaus/gunittest/testsuite/test_gmodules.py
===================================================================
--- sandbox/wenzeslaus/gunittest/testsuite/test_gmodules.py	2014-06-26 21:12:16 UTC (rev 60997)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_gmodules.py	2014-06-26 21:19:13 UTC (rev 60998)
@@ -8,7 +8,8 @@
 sys.path.insert(0, os.path.split(os.path.split((os.path.dirname(__file__)))[0])[0])
 
 from gunittest.case import GrassTestCase
-from gunittest.gmodules import call_module, CalledModuleError
+from gunittest.gmodules import (call_module, CalledModuleError,
+                                run_module, read_module, write_module)
 
 G_REGION_OUTPUT = """n=...
 s=...
@@ -83,11 +84,41 @@
                           call_module,
                           'm.proj', flags='i', input='-',
                           stdin=subprocess.PIPE)
-        self.assertRaises(ValueError,
+        self.assertRaises(TypeError,
                           call_module,
-                          'm.proj', flags='i', input='-',
+                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                           stdout='any_value_or_type_here')
-        self.assertRaises(ValueError,
+        self.assertRaises(TypeError,
                           call_module,
-                          'm.proj', flags='i', input='-',
+                          'm.proj', flags='i', input='-', stdin="50.0 41.5",
                           stderr='any_value_or_type_here')
+
+
+class ModuleFunctionsTest(GrassTestCase):
+
+    def test_run_module_raise(self):
+        self.assertRaises(CalledModuleError,
+                          run_module,
+                          'r.univar', aaabbbcc='notexist')
+
+    def test_read_module_return(self):
+        self.assertTrue(read_module('r.info', map='elevation'))
+
+    def test_read_module_raise(self):
+        self.assertRaises(CalledModuleError,
+                          read_module,
+                          'r.univar', aaabbbcc='notexist')
+
+    def test_write_module_missing_stdin(self):
+        self.assertRaises(TypeError,
+                          write_module,
+                          'm.proj', aaabbbcc='notexist')
+
+    def test_write_module_return(self):
+        self.assertIsNone(write_module('m.proj', input='-', stdin='50,50',
+                                       flags='o'))
+
+    def test_write_module_raise(self):
+        self.assertRaises(CalledModuleError,
+                          write_module,
+                          'm.proj', stdin='50,50', aaabbbcc='notexist')



More information about the grass-commit mailing list