test_history.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """
  2. Created on Mon Sep 15 17:09:40 2014
  3. @author: lucadelu
  4. """
  5. from grass.gunittest.case import TestCase
  6. from grass.gunittest.main import test
  7. from grass.pygrass.raster import RasterRow
  8. from grass.pygrass.raster.history import History
  9. from grass.script.utils import decode
  10. class RasterHistoryTestCate(TestCase):
  11. name = "RasterCategoryTestCase_map"
  12. @classmethod
  13. def setUpClass(cls):
  14. """Create test raster map and region"""
  15. cls.use_temp_region()
  16. cls.runModule("g.region", n=40, s=0, e=40, w=0, res=10)
  17. cls.runModule(
  18. "r.mapcalc",
  19. expression="%s = row() + (10 * col())" % (cls.name),
  20. overwrite=True,
  21. )
  22. cls.runModule(
  23. "r.support",
  24. map=cls.name,
  25. title="A test map",
  26. history="Generated by r.mapcalc",
  27. description="This is a test map",
  28. )
  29. @classmethod
  30. def tearDownClass(cls):
  31. """Remove the generated vector map, if exist"""
  32. cls.runModule("g.remove", flags="f", type="raster", name=cls.name)
  33. cls.del_temp_region()
  34. def testHistory(self):
  35. r = RasterRow(self.name)
  36. r.open("r")
  37. hist = r.hist
  38. self.assertEqual(decode(hist.title), self.name)
  39. self.assertEqual(decode(hist.keyword), "This is a test map")
  40. hist1 = History(self.name)
  41. hist1.read()
  42. self.assertEqual(decode(hist1.title), self.name)
  43. self.assertEqual(decode(hist1.keyword), "This is a test map")
  44. self.assertEqual(hist, hist1)
  45. self.assertEqual(decode(hist.creator), decode(hist1.creator))
  46. hist1.creator = "Markus"
  47. self.assertNotEqual(decode(hist.creator), decode(hist1.creator))
  48. r.close()
  49. hist1.title = "No such title"
  50. hist1.keyword = "No such description"
  51. hist1.src1 = "No such source 1"
  52. hist1.src2 = "No such source 2"
  53. hist1.write()
  54. r.open("r")
  55. hist = r.hist
  56. self.assertEqual(decode(hist.title), "No such title")
  57. self.assertEqual(decode(hist.keyword), "No such description")
  58. self.assertEqual(decode(hist.creator), "Markus")
  59. self.assertEqual(decode(hist.creator), "Markus")
  60. self.assertEqual(decode(hist.src1), "No such source 1")
  61. self.assertEqual(decode(hist.src2), "No such source 2")
  62. r.close()
  63. if __name__ == "__main__":
  64. test()