test_history.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Sep 15 17:09:40 2014
  4. @author: lucadelu
  5. """
  6. from grass.gunittest.case import TestCase
  7. from grass.gunittest.main import test
  8. from grass.pygrass.raster import RasterRow
  9. from grass.pygrass.raster.history import History
  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("r.mapcalc", expression="%s = row() + (10 * col())"%(cls.name),
  18. overwrite=True)
  19. cls.runModule("r.support", map=cls.name,
  20. title="A test map",
  21. history="Generated by r.mapcalc",
  22. description="This is a test map")
  23. @classmethod
  24. def tearDownClass(cls):
  25. """Remove the generated vector map, if exist"""
  26. cls.runModule("g.remove", flags='f', type='raster',
  27. name=cls.name)
  28. cls.del_temp_region()
  29. def testHistory(self):
  30. r = RasterRow(self.name)
  31. r.open("r")
  32. hist = r.hist
  33. self.assertEqual(hist.title, "A test map")
  34. self.assertEqual(hist.keyword, "This is a test map")
  35. hist1 = History(self.name)
  36. hist1.read()
  37. self.assertEqual(hist1.title, "A test map")
  38. self.assertEqual(hist1.keyword, "This is a test map")
  39. self.assertEqual(hist, hist1)
  40. self.assertEqual(hist.creator, hist1.creator)
  41. hist1.creator = "Markus"
  42. self.assertNotEqual(hist.creator, hist1.creator)
  43. r.close()
  44. hist1.title = "No such title"
  45. hist1.keyword = "No such description"
  46. hist1.src1 = "No such source 1"
  47. hist1.src2 = "No such source 2"
  48. hist1.write()
  49. r.open("r")
  50. hist = r.hist
  51. self.assertEqual(hist.title, "No such title")
  52. self.assertEqual(hist.keyword, "No such description")
  53. self.assertEqual(hist.creator, "Markus")
  54. self.assertEqual(hist.creator, "Markus")
  55. self.assertEqual(hist.src1, "No such source 1")
  56. self.assertEqual(hist.src2, "No such source 2")
  57. r.close()
  58. if __name__ == '__main__':
  59. test()