Skip to content

Commit

Permalink
Update of test_r_stats #10
Browse files Browse the repository at this point in the history
Adding test of checking number of pixels and testing total area value #10

Co-Authored-By: dekanluc <[email protected]>
  • Loading branch information
JosefPudil and dekanluc committed Jun 2, 2020
1 parent 436894f commit 98e610e
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions raster/r.stats/test_suite/test_r_stats.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 98e610e

Please sign in to comment.