test_rmapcalcsimple.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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(map=map_output1, refmin=0, refmax=0,
  33. msg="Result must be 0 for all pixels")
  34. # test 2
  35. formula='if(%s > 2000, 1, 0)' % map_input # expected to be 0
  36. self.assertModule('r.mapcalc.simple', expression=formula, output=map_output2)
  37. self.assertRasterMinMax(map=map_output2, refmin=0, refmax=0,
  38. msg="Result must be 0 for all pixels")
  39. if __name__ == '__main__':
  40. from grass.gunittest.main import test
  41. test()