Debian Codegraph @

raster/r.grow.distance/testsuite/r_grow_distance_test.py

raw
1 """
2 Name: r_grow_distance_test
3 Purpose: This script is to demonstrate a unit test for r.grow.distance
4 module.
5 """
6
7 from grass.gunittest.case import TestCase
8 from grass.gunittest.main import test
9
10
11 class TestGrowDistance(TestCase):
12 """Test case for grow distance module"""
13
14 # Setup variables to be used for outputs
15 distance = "test_distance"
16 lakes = "lakes"
17 elevation = "elevation"
18
19 @classmethod
20 def setUpClass(cls):
21 """Ensures expected computational region and setup"""
22 # Always use the computational region of the raster elevation
23 cls.use_temp_region()
24 cls.runModule("g.region", raster=cls.elevation)
25
26 @classmethod
27 def tearDownClass(cls):
28 """Remove the temporary region"""
29 cls.del_temp_region()
30
31 def tearDown(self):
32 """Remove the outputs created from the grow distance module
33
34 This is executed after each test run.
35 """
36 self.runModule("g.remove", flags="f", type="raster", name=self.distance)
37
38 def test_grow(self):
39 """Test to see if the outputs are created"""
40 # run the grow distance module
41 self.assertModule("r.grow.distance", input=self.lakes, distance=self.distance)
42 # check to see if distance output is in mapset
43 self.assertRasterExists(self.distance, msg="distance output was not created")
44 self.assertRasterMinMax(
45 self.distance, 0, 5322, msg="distance output not in range"
46 )
47
48
49 if __name__ == "__main__":
50 test()