[GRASS-SVN] r63924 - in grass/branches/releasebranch_7_0/general: g.list g.list/testsuite g.parser g.remove g.remove/testsuite g.setproj g.tempfile

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 1 14:49:11 PST 2015


Author: neteler
Date: 2015-01-01 14:49:11 -0800 (Thu, 01 Jan 2015)
New Revision: 63924

Added:
   grass/branches/releasebranch_7_0/general/g.list/testsuite/
   grass/branches/releasebranch_7_0/general/g.list/testsuite/test_g_list.py
   grass/branches/releasebranch_7_0/general/g.remove/testsuite/
   grass/branches/releasebranch_7_0/general/g.remove/testsuite/test_g_remove.py
Modified:
   grass/branches/releasebranch_7_0/general/g.parser/main.c
   grass/branches/releasebranch_7_0/general/g.setproj/get_stp.c
   grass/branches/releasebranch_7_0/general/g.tempfile/main.c
Log:
g.*: minor backports; testsuites backported

Added: grass/branches/releasebranch_7_0/general/g.list/testsuite/test_g_list.py
===================================================================
--- grass/branches/releasebranch_7_0/general/g.list/testsuite/test_g_list.py	                        (rev 0)
+++ grass/branches/releasebranch_7_0/general/g.list/testsuite/test_g_list.py	2015-01-01 22:49:11 UTC (rev 63924)
@@ -0,0 +1,55 @@
+"""g.list tests"""
+
+import grass.gunittest
+from grass.gunittest.gmodules import SimpleModule
+
+
+class GMlistWrongParamertersTest(grass.gunittest.TestCase):
+    """Test wrong input of parameters for g.list module"""
+
+    @classmethod
+    def setUpClass(cls):
+        """Create maps in a small region."""
+        cls.use_temp_region()
+        cls.runModule("g.region", s=0, n=5, w=0, e=5, res=1)
+
+    @classmethod
+    def tearDownClass(cls):
+        """Remove temporary region"""
+        cls.del_temp_region()
+
+    def test_pt_flags(self):
+        """Test that -p and -t flags are exclusive"""
+        module = SimpleModule('g.list', flags='pt', type='raster')
+        self.assertModuleFail(module)
+        stderr = module.outputs.stderr
+        self.assertIn('-p', stderr)
+        self.assertIn('-t', stderr)
+
+    def test_ft_flags(self):
+        """Test that -f and -t flags are exclusive"""
+        module = SimpleModule('g.list', flags='ft', type='raster')
+        self.assertModuleFail(module)
+        stderr = module.outputs.stderr
+        self.assertIn('-f', stderr)
+        self.assertIn('-t', stderr)
+
+    def test_pf_flags(self):
+        """Test that -p and -f flags are exclusive"""
+        module = SimpleModule('g.list', flags='pf', type='raster')
+        self.assertModuleFail(module)
+        stderr = module.outputs.stderr
+        self.assertIn('-p', stderr)
+        self.assertIn('-f', stderr)
+
+    def test_re_flags(self):
+        """Test that -r and -e flags are exclusive"""
+        module = SimpleModule('g.list', flags='re', type='raster')
+        self.assertModuleFail(module)
+        stderr = module.outputs.stderr
+        self.assertIn('-r', stderr)
+        self.assertIn('-e', stderr)
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()


Property changes on: grass/branches/releasebranch_7_0/general/g.list/testsuite/test_g_list.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Modified: grass/branches/releasebranch_7_0/general/g.parser/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.parser/main.c	2015-01-01 22:36:28 UTC (rev 63923)
+++ grass/branches/releasebranch_7_0/general/g.parser/main.c	2015-01-01 22:49:11 UTC (rev 63924)
@@ -29,11 +29,14 @@
 
 int main(int argc, char *argv[])
 {
+    char *progname;
     struct context ctx;
     const char *filename;
     int standard_output;
     int separator_nul;
     
+    progname = argv[0];
+
     ctx.module = NULL;
     ctx.option = NULL;
     ctx.flag = NULL;
@@ -67,8 +70,8 @@
     if ((argc < 2) || ((strcmp(argv[1], "help") == 0) ||
 		       (strcmp(argv[1], "-help") == 0) ||
 		       (strcmp(argv[1], "--help") == 0))) {
-	fprintf(stderr, "%s: %s [-t] [-s] <filename> [<argument> ...]\n",
-		_("Usage"), argv[0]);
+	fprintf(stderr, "%s: %s [-t] [-s] [-n] <filename> [<argument> ...]\n",
+		_("Usage"), progname);
 	exit(EXIT_FAILURE);
     }
 

Added: grass/branches/releasebranch_7_0/general/g.remove/testsuite/test_g_remove.py
===================================================================
--- grass/branches/releasebranch_7_0/general/g.remove/testsuite/test_g_remove.py	                        (rev 0)
+++ grass/branches/releasebranch_7_0/general/g.remove/testsuite/test_g_remove.py	2015-01-01 22:49:11 UTC (rev 63924)
@@ -0,0 +1,109 @@
+"""Test of g.remove module"""
+
+# TODO: rmapcalc probably fatals, replace or add raise on error?
+from grass.script.raster import mapcalc as rmapcalc
+
+import grass.gunittest
+from grass.gunittest.gutils import get_current_mapset
+from grass.gunittest.gmodules import SimpleModule
+
+# when used user1 must be replaced by current mapset
+REMOVE_RASTERS = """raster/test_map_0 at user1
+raster/test_map_1 at user1
+raster/test_map_2 at user1
+raster/test_map_3 at user1
+raster/test_map_4 at user1
+raster/test_map_5 at user1
+raster/test_map_6 at user1
+raster/test_map_7 at user1
+raster/test_map_8 at user1
+raster/test_map_9 at user1
+raster/test_two at user1
+"""
+
+REMOVING_RASTERS_LOG = """Removing raster <test_map_0>
+Removing raster <test_map_1>
+Removing raster <test_map_2>
+Removing raster <test_map_3>
+Removing raster <test_map_4>
+Removing raster <test_map_5>
+Removing raster <test_map_6>
+Removing raster <test_map_7>
+Removing raster <test_map_8>
+Removing raster <test_map_9>
+Removing raster <test_two>
+"""
+
+
+class GMRemoveTest(grass.gunittest.TestCase):
+    """Test removing with g.remove"""
+
+    @classmethod
+    def setUpClass(cls):
+        """Set up small region for fast map creation."""
+        cls.use_temp_region()
+        cls.runModule("g.region", s=0, n=5, w=0, e=5, res=1)
+
+    @classmethod
+    def tearDownClass(cls):
+        """Remove temporary region"""
+        cls.del_temp_region()
+
+    def test_remove_procedure(self):
+        """Test that maps are removed only with -f"""
+        for i in range(0, 10):
+            rmapcalc("test_map_%i = 100" % i)
+        rmapcalc("test_two = 2")
+
+        module = SimpleModule('g.remove',
+                              type='raster', pattern='test_map_*,*two')
+        self.assertModule(module)
+        self.assertMultiLineEqual(module.outputs.stdout,
+                                  REMOVE_RASTERS.replace('user1',
+                                                         get_current_mapset()))
+
+        module = SimpleModule('g.remove', type='raster',
+                              pattern='test_map_*,*two', flags='f')
+        self.assertModule(module)
+        self.assertMultiLineEqual(module.outputs.stdout, '')
+        self.assertMultiLineEqual(module.outputs.stderr, REMOVING_RASTERS_LOG)
+
+    def test_remove_procedure_exclude(self):
+        """Test that exclude does not list excluded maps"""
+        rmapcalc("test_apples = 100")
+        rmapcalc("test_oranges = 200")
+        rmapcalc("test_apples_big = 300")
+        rmapcalc("test_apples_small = 300")
+        module = SimpleModule('g.remove', type='raster',
+                              pattern='test_{apples,oranges}*',
+                              exclude="*_small")
+        self.assertModule(module)
+        self.assertMultiLineEqual(module.outputs.stdout,
+                                  'raster/test_apples at user1\n'
+                                  'raster/test_apples_big at user1\n'
+                                  'raster/test_oranges at user1\n'.replace(
+                                      'user1', get_current_mapset()))
+        module = SimpleModule('g.remove', type='raster',
+                              pattern='test_{apples,oranges}{_small,_big,*}',
+                              flags='f')
+        self.assertModule(module)
+        self.assertMultiLineEqual(module.outputs.stdout, '')
+        self.assertRegexpMatches(module.outputs.stderr, "(.*<.+>[^\n]*\n){4}",
+                                 msg="4 maps should be removed")
+
+
+class GMRemoveWrongInputTest(grass.gunittest.TestCase):
+    """Test wrong input of parameters for g.remove module"""
+
+    def test_re_flags(self):
+        """Test that -r and -e flags are exclusive"""
+        module = SimpleModule('g.remove', flags='re',
+                              type='raster', pattern='xxxyyyzzz')
+        self.assertModuleFail(module)
+        stderr = module.outputs.stderr
+        self.assertIn('-r', stderr)
+        self.assertIn('-e', stderr)
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()


Property changes on: grass/branches/releasebranch_7_0/general/g.remove/testsuite/test_g_remove.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Modified: grass/branches/releasebranch_7_0/general/g.setproj/get_stp.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.setproj/get_stp.c	2015-01-01 22:36:28 UTC (rev 63923)
+++ grass/branches/releasebranch_7_0/general/g.setproj/get_stp.c	2015-01-01 22:49:11 UTC (rev 63924)
@@ -40,7 +40,7 @@
 	    fprintf(stderr, "\nInvalid Co-ordinate System Specification\n");
     }
     if (get_stp_code(code, string, buff) == 0)
-	G_fatal_error(_("This should not happen see your system admin"));
+	G_fatal_error(_("This should not happen. See your system admin."));
 
     return;
 }
@@ -122,7 +122,7 @@
 	if (icode != 0)
 	    break;
 	else {			/* no match */
-	    G_warning(_("No match of fips state %d county %d"), SFIPS, CFIPS);
+	    G_warning(_("No match of FIPS state %d county %d"), SFIPS, CFIPS);
 	    fclose(fipsfile);
 	}
     }

Modified: grass/branches/releasebranch_7_0/general/g.tempfile/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.tempfile/main.c	2015-01-01 22:36:28 UTC (rev 63923)
+++ grass/branches/releasebranch_7_0/general/g.tempfile/main.c	2015-01-01 22:49:11 UTC (rev 63924)
@@ -29,7 +29,7 @@
     struct GModule *module;
     struct Option *pid;
     struct Flag *dry_run;
-    char *tempfile, *G__tempfile();
+    char *tempfile;
     int p;
     
     G_gisinit(argv[0]);



More information about the grass-commit mailing list