test_r_grow.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(
  25. "g.remove",
  26. flags="f",
  27. type="raster",
  28. name=(cls.mapGrownOutput, cls.mapShrunkOutput, cls.mapShrunkNoNULL),
  29. )
  30. cls.del_temp_region()
  31. def test_grow(self):
  32. """Grow test"""
  33. module = SimpleModule(
  34. "r.grow", input=self.mapName, output=self.mapGrownOutput, radius=10
  35. )
  36. self.assertModule(module)
  37. def test_shrink(self):
  38. """Shrink test"""
  39. module = SimpleModule(
  40. "r.grow", input=self.mapName, output=self.mapShrunkOutput, radius=-10
  41. )
  42. self.assertModule(module)
  43. def test_shrink_null(self):
  44. """Shrinking of map without NULL values
  45. Based on https://github.com/OSGeo/grass/pull/343"""
  46. shrinked_string = "56-156"
  47. shrinked = SimpleModule(
  48. "r.grow", input=self.mapNoNULL, output=self.mapShrunkNoNULL, radius=-10
  49. )
  50. self.assertModule(shrinked)
  51. shrined_range = SimpleModule("r.describe", flags="i", _map=self.mapShrunkNoNULL)
  52. self.runModule(shrined_range)
  53. self.assertLooksLike(shrinked_string, str(shrined_range.outputs.stdout).strip())
  54. if __name__ == "__main__":
  55. test()