[GRASS-SVN] r62147 - in grass/trunk/raster/r.mapcalc: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 1 09:10:14 PDT 2014
Author: wenzeslaus
Date: 2014-10-01 09:10:14 -0700 (Wed, 01 Oct 2014)
New Revision: 62147
Added:
grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py
Modified:
grass/trunk/raster/r.mapcalc/map3.c
grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py
Log:
use no workers (#2074)
one still creates one worker, zero avoids any creation (see lib/gis/worker.c)
one worker was still causing Rast3d_get_tile_ptr error
added also tests for r3.mapcalc which should sometimes show the error for WORKERS=1
Modified: grass/trunk/raster/r.mapcalc/map3.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map3.c 2014-10-01 16:00:37 UTC (rev 62146)
+++ grass/trunk/raster/r.mapcalc/map3.c 2014-10-01 16:10:14 UTC (rev 62147)
@@ -525,7 +525,7 @@
* avoid that several threads access a single map for reading
* at the same time. The raster3d library is not thread safe.
* */
- putenv("WORKERS=1");
+ putenv("WORKERS=0");
for (i = 0; i < num_maps; i++)
setup_map(&maps[i]);
Added: grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py
===================================================================
--- grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py (rev 0)
+++ grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py 2014-10-01 16:10:14 UTC (rev 62147)
@@ -0,0 +1,56 @@
+import grass.gunittest
+
+
+# TODO: add more expressions
+# TODO: add tests with prepared data
+
+class TestBasicOperations(grass.gunittest.TestCase):
+
+ # TODO: replace by unified handing of maps
+ to_remove = []
+
+ @classmethod
+ def setUpClass(cls):
+ cls.use_temp_region()
+ cls.runModule('g.region',
+ n=85, s=5, e=85, w=5,
+ b=0, t=2000,
+ res=1e-07)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.del_temp_region()
+ if cls.to_remove:
+ cls.runModule('g.remove', flags='f', type='rast3d',
+ pattern=','.join(cls.to_remove), verbose=True)
+
+ def test_difference_of_the_same_map_double(self):
+ """Test zero difference of map with itself"""
+ self.runModule('r3.mapcalc', flags='s',
+ expression='a = rand(1.0, 200)')
+ self.to_remove.append('a')
+ self.assertModule('r3.mapcalc',
+ expression='diff_a_a = a - a')
+ self.to_remove.append('diff_a_a')
+ self.assertRaster3dMinMax('diff_a_a', refmin=0, refmax=0)
+
+ def test_difference_of_the_same_map_float(self):
+ """Test zero difference of map with itself"""
+ self.runModule('r3.mapcalc', flags='s',
+ expression='af = rand(float(1), 200)')
+ self.to_remove.append('af')
+ self.assertModule('r3.mapcalc',
+ expression='diff_af_af = af - af')
+ self.to_remove.append('diff_af_af')
+ self.assertRaster3dMinMax('diff_af_af', refmin=0, refmax=0)
+
+ def test_difference_of_the_same_expression(self):
+ """Test zero difference of two same expressions"""
+ self.assertModule('r3.mapcalc',
+ expression='diff_e_e = 3 * x() * y() * z() - 3 * x() * y() * z()')
+ self.to_remove.append('diff_e_e')
+ self.assertRaster3dMinMax('diff_e_e', refmin=0, refmax=0)
+
+
+if __name__ == '__main__':
+ grass.gunittest.test()
Modified: grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py
===================================================================
--- grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py 2014-10-01 16:00:37 UTC (rev 62146)
+++ grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py 2014-10-01 16:10:14 UTC (rev 62147)
@@ -72,11 +72,14 @@
@classmethod
def tearDownClass(cls):
cls.del_temp_region()
- cls.runModule('g.remove', flags='f', type='rast',
- pattern=','.join(cls.to_remove))
+ if cls.to_remove:
+ cls.runModule('g.remove', flags='f', type='rast',
+ pattern=','.join(cls.to_remove))
def rinfo_contains_number(self, raster, number):
- """Test that r.info stdandard output for raster contains a given number
+ """Test that r.info standard output for raster contains a given number
+
+ To be used in test methods for testing presence of a given number.
"""
rinfo = SimpleModule('r.info', map=raster)
self.runModule(rinfo)
@@ -88,9 +91,13 @@
self.to_remove.append('nonrand_cell')
def test_seed_required(self):
- """Test that seed is required when rand() is used"""
+ """Test that seed is required when rand() is used
+
+ This test can, and probably should, generate an error message.
+ """
self.assertModuleFail('r.mapcalc', expression='rand_x = rand(1, 200)')
# TODO: assert map not exists but it would be handy here
+ # TODO: test that error message was generated
def test_seed_cell(self):
"""Test given seed with CELL against reference map"""
@@ -153,5 +160,64 @@
statistics=dict(min=-1, max=1, mean=0),
precision=0.5) # low precision, we have few cells
+
+# TODO: add more expressions
+# TODO: add tests with prepared data
+
+class TestBasicOperations(grass.gunittest.TestCase):
+
+ # TODO: replace by unified handing of maps
+ to_remove = []
+
+ @classmethod
+ def setUpClass(cls):
+ cls.use_temp_region()
+ cls.runModule('g.region', n=20, s=10, e=25, w=15, res=1)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.del_temp_region()
+ if cls.to_remove:
+ cls.runModule('g.remove', flags='f', type='rast',
+ pattern=','.join(cls.to_remove), verbose=True)
+
+ def test_difference_of_the_same_map_double(self):
+ """Test zero difference of map with itself"""
+ self.runModule('r.mapcalc', flags='s',
+ expression='a = rand(1.0, 200)')
+ self.to_remove.append('a')
+ self.assertModule('r.mapcalc',
+ expression='diff_a_a = a - a')
+ self.to_remove.append('diff_a_a')
+ self.assertRasterMinMax('diff_a_a', refmin=0, refmax=0)
+
+ def test_difference_of_the_same_map_float(self):
+ """Test zero difference of map with itself"""
+ self.runModule('r.mapcalc', flags='s',
+ expression='af = rand(float(1), 200)')
+ self.to_remove.append('af')
+ self.assertModule('r.mapcalc',
+ expression='diff_af_af = af - af')
+ self.to_remove.append('diff_af_af')
+ self.assertRasterMinMax('diff_af_af', refmin=0, refmax=0)
+
+ def test_difference_of_the_same_map_int(self):
+ """Test zero difference of map with itself"""
+ self.runModule('r.mapcalc', flags='s',
+ expression='ai = rand(1, 200)')
+ self.to_remove.append('ai')
+ self.assertModule('r.mapcalc',
+ expression='diff_ai_ai = ai - ai')
+ self.to_remove.append('diff_ai_ai')
+ self.assertRasterMinMax('diff_ai_ai', refmin=0, refmax=0)
+
+ def test_difference_of_the_same_expression(self):
+ """Test zero difference of two same expressions"""
+ self.assertModule('r.mapcalc',
+ expression='diff_e_e = 3 * x() * y() - 3 * x() * y()')
+ self.to_remove.append('diff_e_e')
+ self.assertRasterMinMax('diff_e_e', refmin=0, refmax=0)
+
+
if __name__ == '__main__':
grass.gunittest.test()
More information about the grass-commit
mailing list