test_history.py 2.5 KB

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