testrra.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """
  2. Name: r.reclass.area test
  3. Purpose: Tests r.reclass.area and its flags/options.
  4. Author: Sunveer Singh, Google Code-in 2018
  5. Copyright: (C) 2018 by Sunveer Singh 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. from grass.gunittest.main import test
  12. class Testrr(TestCase):
  13. input = "zipcodes"
  14. output = "rraoutput"
  15. @classmethod
  16. def setUpClass(cls):
  17. cls.use_temp_region()
  18. cls.runModule("g.region", raster=cls.input)
  19. @classmethod
  20. def tearDownClass(cls):
  21. cls.del_temp_region()
  22. def tearDown(cls):
  23. cls.runModule("g.remove", type="raster", flags="f", name=cls.output)
  24. def test_flag_c(self):
  25. """Testing flag c"""
  26. string = """min=27603
  27. max=27607
  28. cells=2025000"""
  29. self.assertModule(
  30. "r.reclass.area",
  31. input=self.input,
  32. output=self.output,
  33. value=2000,
  34. mode="greater",
  35. flags="c",
  36. )
  37. self.assertRasterFitsUnivar(self.output, reference=string, precision=2)
  38. def test_flag_d(self):
  39. """Testing flag d"""
  40. self.assertModule(
  41. "r.reclass.area",
  42. input=self.input,
  43. output=self.output,
  44. value=2000,
  45. mode="lesser",
  46. flags="d",
  47. )
  48. self.assertRasterMinMax(
  49. map=self.output,
  50. refmin=27511,
  51. refmax=27610,
  52. msg="Output Map in degrees must be between 27511 and 27610",
  53. )
  54. def test_module_output(self):
  55. """Testing Module without flags"""
  56. self.assertModule(
  57. "r.reclass.area",
  58. input=self.input,
  59. output=self.output,
  60. value=2000,
  61. mode="greater",
  62. )
  63. self.assertRasterMinMax(
  64. map=self.output,
  65. refmin=27603,
  66. refmax=27607,
  67. msg="Output Map in degrees must be between 27603 and 27607",
  68. )
  69. def test_method_rmarea(self):
  70. """Testing Module without flags"""
  71. self.assertModule(
  72. "r.reclass.area",
  73. input=self.input,
  74. output=self.output,
  75. value=2000,
  76. mode="lesser",
  77. method="rmarea",
  78. )
  79. self.assertRasterMinMax(
  80. map=self.output,
  81. refmin=27603,
  82. refmax=27607,
  83. msg="Output Map in degrees must be between 27603 and 27607",
  84. )
  85. if __name__ == "__main__":
  86. from grass.gunittest.main import test
  87. test()