[GRASS-SVN] r74228 - in grass/trunk/raster/r.contour: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 13 00:11:02 PDT 2019


Author: lucadelu
Date: 2019-03-13 00:11:02 -0700 (Wed, 13 Mar 2019)
New Revision: 74228

Added:
   grass/trunk/raster/r.contour/testsuite/
   grass/trunk/raster/r.contour/testsuite/test_r_contour.py
   grass/trunk/raster/r.contour/testsuite/testrc.py
Log:
r.contour: added tests from GCI 2018

Added: grass/trunk/raster/r.contour/testsuite/test_r_contour.py
===================================================================
--- grass/trunk/raster/r.contour/testsuite/test_r_contour.py	                        (rev 0)
+++ grass/trunk/raster/r.contour/testsuite/test_r_contour.py	2019-03-13 07:11:02 UTC (rev 74228)
@@ -0,0 +1,83 @@
+"""
+Name:       r.contour test
+Purpose:    Tests r.contour module and its options.
+
+Author:     Shubham Sharma, Google Code-in 2018
+Copyright:  (C) 2018 by Shubham Sharma and the GRASS Development Team
+Licence:    This program is free software under the GNU General Public
+            License (>=v2). Read the file COPYING that comes with GRASS
+            for details.
+"""
+
+from grass.gunittest.case import TestCase
+import os
+
+class TestRasterWhat(TestCase):
+    input = 'elevation'
+    output = 'elevationVector'
+    step = 100
+    levels = (60, 90, 120, 150)
+    minlevel = 1000
+    maxlevel = 2000
+    cut = 200
+    test_ref_str = "cat|level\n1|60\n2|90\n3|120\n4|150\n"
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', raster=cls.input)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.output)
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.output+"_cut")
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.output+"_cut_flag_t")
+
+        if os.path.isfile('testReport'):
+            os.remove('testReport')
+        if os.path.isfile('testReportCut'):
+            os.remove('testReportCut')
+        if os.path.isfile('testReportCutFlagT'):
+            os.remove('testReportCutFlagT')
+
+
+
+    def test_raster_contour(self):
+        """Testing r.contour runs successfully with input steps,levels, minlevel, maxlevel"""
+        self.assertModule('r.contour', input=self.input, output=self.output, step=self.step, levels=self.levels, minlevel=self.minlevel, maxlevel=self.maxlevel)
+        self.assertVectorExists(name=self.output, msg=self.output+" was not created.")
+
+        # Check the attribute values of contours with v.db.select
+        self.assertModule('v.db.select', map=self.output, file='testReport')
+        self.assertFileExists('testReport', msg='testReport file was not created')
+        if os.path.isfile('testReport'):
+            file = open("testReport", "r")
+            fileData = file.read()
+            self.assertMultiLineEqual(fileData, self.test_ref_str)
+            file.close()
+
+    def test_raster_contour_cut(self):
+        """Testing r.contour runs successfully with input steps,levels, minlevel, maxlevel and cut=100"""
+        self.assertModule('r.contour', input=self.input, output=self.output+"_cut", step=self.step, levels=self.levels, minlevel=self.minlevel, maxlevel=self.maxlevel,cut=self.cut)
+        self.assertVectorExists(name=self.output+"_cut", msg=self.output+" was not created.")
+
+        # Check the attribute values of contours with v.db.select
+        self.assertModule('v.db.select', map=self.output+"_cut", file='testReportCut')
+        self.assertFileExists('testReportCut', msg='testReportCut file was not created')
+        if os.path.isfile('testReportCut'):
+            file = open("testReportCut", "r")
+            fileData = file.read()
+            self.assertMultiLineEqual(fileData, self.test_ref_str)
+            file.close()
+
+    def test_raster_contour_flag_t(self):
+        """Testing r.contour runs successfully with input steps,levels, minlevel, maxlevel ,cut=100 and flag t"""
+        self.assertModule('r.contour', input=self.input, output=self.output+"_cut_flag_t", flags='t', step=self.step, levels=self.levels, minlevel=self.minlevel, maxlevel=self.maxlevel, cut=self.cut)
+        self.assertVectorExists(name=self.output+"_cut_flag_t", msg=self.output+" was not created.")
+        # No need to check the attribute values of contours because attribute table was not created
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()

Added: grass/trunk/raster/r.contour/testsuite/testrc.py
===================================================================
--- grass/trunk/raster/r.contour/testsuite/testrc.py	                        (rev 0)
+++ grass/trunk/raster/r.contour/testsuite/testrc.py	2019-03-13 07:11:02 UTC (rev 74228)
@@ -0,0 +1,113 @@
+"""
+Name:       r.contour test
+Purpose:    Tests r.contour and its flags/options.
+	
+Author:     Sunveer Singh, Google Code-in 2018
+Copyright:  (C) 2018 by Sunveer Singh and the GRASS Development Team
+Licence:    This program is free software under the GNU General Public
+	            License (>=v2). Read the file COPYING that comes with GRASS
+	            for details.
+"""
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+from grass.gunittest.gmodules import SimpleModule
+
+out_where = """cat|level
+1|56
+2|58
+3|60
+4|62
+5|64
+6|66
+7|68
+8|70
+9|72
+10|74
+11|76
+12|78
+13|80
+14|82
+15|84
+16|86
+17|88
+18|90
+19|92
+20|94
+21|96
+22|98
+23|100
+24|102
+25|104
+26|106
+27|108
+28|110
+29|112
+30|114
+31|116
+32|118
+33|120
+34|122
+35|124
+36|126
+37|128
+38|130
+39|132
+40|134
+41|136
+42|138
+43|140
+44|142
+45|144
+46|146
+47|148
+48|150
+49|152
+50|154
+51|156
+"""
+
+class Testrr(TestCase):
+    input='elevation'
+    output='towns'
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', raster=cls.input)
+	
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+
+    def tearDown(cls):
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.output)
+
+
+    def test_flag_t(self):
+        """Testing flag t"""
+        string="""min=1
+        max=6"""
+        self.assertModule('r.contour', input=self.input, output=self.output, levels=1, step=1, flags='t')
+        self.assertRasterFitsUnivar(self.output,
+	                            reference=string, precision=2)
+
+    def test_vector(self):
+        """Testing vector output"""
+        self.assertModule('r.contour', input=self.input, output=self.output, step=5, flags='t')
+        self.assertModule('v.info', map=self.output, flags='t')
+        topology = dict(points=0, lines=2222, areas=0)
+	self.assertVectorFitsTopoInfo(self.output, topology)
+        
+
+    def test_v_db_select(self):
+        """Testing attribute values of contours with v.db.select """
+        self.assertModule('r.contour', input=self.input, output=self.output, step=2)
+        v_db_select = SimpleModule('v.db.select', map=self.output)
+        v_db_select.run()
+        self.assertLooksLike(reference=out_where, actual=v_db_select.outputs.stdout)
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()
+



More information about the grass-commit mailing list