test_r_grow.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """
  2. Created on Sun Jun 07 22:09:41 2018
  3. @author: Sanjeet Bhatti, Maris Nartiss
  4. """
  5. from grass.gunittest.case import TestCase
  6. from grass.gunittest.main import test
  7. from grass.gunittest.gmodules import SimpleModule
  8. from grass.script.core import run_command
  9. class TestRGrow(TestCase):
  10. """Test r.grow script"""
  11. mapName = 'lakes'
  12. mapGrownOutput = 'lakes_grown_100m'
  13. mapShrunkOutput = 'lakes_shrunk_100m'
  14. mapNoNULL = 'elevation'
  15. mapShrunkNoNULL = 'elevation_shrunk'
  16. @classmethod
  17. def setUpClass(cls):
  18. """Create maps in a small region."""
  19. cls.use_temp_region()
  20. cls.runModule('g.region', raster=cls.mapName, flags='p')
  21. @classmethod
  22. def tearDownClass(cls):
  23. """Remove temporary region"""
  24. cls.runModule('g.remove', flags='f', type='raster',
  25. name=(cls.mapGrownOutput,
  26. cls.mapShrunkOutput,
  27. cls.mapShrunkNoNULL))
  28. cls.del_temp_region()
  29. def test_grow(self):
  30. """Grow test"""
  31. module = SimpleModule('r.grow', input=self.mapName,
  32. output=self.mapGrownOutput,
  33. radius=10)
  34. self.assertModule(module)
  35. def test_shrink(self):
  36. """Shrink test"""
  37. module = SimpleModule('r.grow', input=self.mapName,
  38. output=self.mapShrunkOutput,
  39. radius=-10)
  40. self.assertModule(module)
  41. def test_shrink_null(self):
  42. """Shrinking of map without NULL values
  43. Based on https://github.com/OSGeo/grass/pull/343"""
  44. shrinked_string = '56-156'
  45. shrinked = SimpleModule('r.grow', input=self.mapNoNULL,
  46. output=self.mapShrunkNoNULL,
  47. radius=-10)
  48. self.assertModule(shrinked)
  49. shrined_range = SimpleModule('r.describe', flags='i', _map=self.mapShrunkNoNULL)
  50. self.runModule(shrined_range)
  51. self.assertLooksLike(shrinked_string, str(shrined_range.outputs.stdout).strip())
  52. if __name__ == '__main__':
  53. test()