test_rmapcalcsimple.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. Name: r.mapcalc.simple test
  3. Purpose: Tests r.mapcalc.simple and its flags/options.
  4. Author: Markus Neteler
  5. Copyright: (C) 2018 by Markus Neteler and the GRASS Development Team
  6. Licence: This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. class TestReport(TestCase):
  12. @classmethod
  13. def setUpClass(cls):
  14. """Use temporary region settings"""
  15. map_input = "elevation"
  16. cls.runModule("g.region", raster=map_input)
  17. cls.use_temp_region()
  18. @classmethod
  19. def tearDownClass(cls):
  20. map_output1 = "test1"
  21. map_output2 = "test2"
  22. cls.runModule("g.remove", flags="f", type="raster", name=map_output1)
  23. cls.runModule("g.remove", flags="f", type="raster", name=map_output2)
  24. cls.del_temp_region()
  25. def test_rmapcalcsimple(self):
  26. """Testing r.mapcalc.simple"""
  27. map_input = "elevation"
  28. map_output1 = "test1"
  29. map_output2 = "test2"
  30. # test 1
  31. self.assertModule("r.mapcalc.simple", expression="0", output=map_output1)
  32. self.assertRasterMinMax(
  33. map=map_output1, refmin=0, refmax=0, msg="Result must be 0 for all pixels"
  34. )
  35. # test 2
  36. formula = "if(%s > 2000, 1, 0)" % map_input # expected to be 0
  37. self.assertModule("r.mapcalc.simple", expression=formula, output=map_output2)
  38. self.assertRasterMinMax(
  39. map=map_output2, refmin=0, refmax=0, msg="Result must be 0 for all pixels"
  40. )
  41. if __name__ == "__main__":
  42. from grass.gunittest.main import test
  43. test()