From 98e610ed74fbcabab258633f283c6468c95dc8ba Mon Sep 17 00:00:00 2001 From: JosefPudil Date: Tue, 2 Jun 2020 22:00:58 +0200 Subject: [PATCH] Update of test_r_stats #10 Adding test of checking number of pixels and testing total area value #10 Co-Authored-By: dekanluc --- raster/r.stats/test_suite/test_r_stats.py | 64 +++++++++++------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/raster/r.stats/test_suite/test_r_stats.py b/raster/r.stats/test_suite/test_r_stats.py index 71de3cbfd..7c3864b0b 100644 --- a/raster/r.stats/test_suite/test_r_stats.py +++ b/raster/r.stats/test_suite/test_r_stats.py @@ -1,35 +1,35 @@ #!/usr/bin/env python3 -from grass.gunittest.case import TestCase -from grass.gunittest.main import test -import grass.script as gscript - -output = 'test1' -stats = 'lakes' -data = [['34300=44200.000000'], - ['39000=3509900.000000'], - ['43600=47000.000000']] - - -class Test_r_stats(TestCase): - @classmethod - def setUpClass(cls): - cls.use_temp_region() - cls.runModule('g.region', raster = stats) - - - @classmethod - def tearDownClass(cls): - cls.del_temp_region() - -# testing total area - def test_check_area(self): - #self.assertModule('r.stats', input = stats , flags = 'aN') - module = self.assertModule('r.stats', input = stats , flags = 'aN',separator = '=') - print(self.assertModule('r.stats', input = stats , flags = 'aN',separator = '=')) - #self.assertModuleKeyValue(module, - # reference=dict('34300'='44200' , '39000'='3509900' , '43600'='47000'), - # precision=1, sep='=') - self.assertEqual(data,module) -if __name__ == '__main__': +from grass.gunittest.case import TestCase +from grass.gunittest.main import test +from grass.gunittest.gmodules import call_module + +input = 'lakes' +#count of pixels with different ID +ref_stats = '34300 442\n39000 35099\n43600 470\n* 1988989' +#area of pixels with different ID +ref_stats2 = '34300 44200.000000\n39000 3509900.000000\n43600 47000.000000' + +class Test_r_stats(TestCase): + + @classmethod + def setUpClass(cls): + cls.use_temp_region() + cls.runModule('g.region', raster = input) + + @classmethod + def tearDownClass(cls): + cls.del_temp_region() + + # Testing total area + def test_number_of_pixels(self): + stats = call_module('r.stats', input=input, flags='c').rstrip('\n') + self.assertEqual(stats, ref_stats) + + def test_area(self) + stats = call_module('r.stats', input=input, flags='aN').rstrip('\n') + self.assertEqual(stats, ref_stats2) + + +if __name__ == '__main__': test() \ No newline at end of file