test_unregister.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. """Test t.unregister
  2. (C) 2014 by the GRASS Development Team
  3. This program is free software under the GNU General Public
  4. License (>=v2). Read the file COPYING that comes with GRASS
  5. for details.
  6. :authors: Soeren Gebbert
  7. """
  8. import os
  9. import grass.pygrass.modules as pymod
  10. import grass.temporal as tgis
  11. from grass.gunittest.case import TestCase
  12. from grass.gunittest.gmodules import SimpleModule
  13. class TestUnregister(TestCase):
  14. @classmethod
  15. def setUpClass(cls):
  16. """Initiate the temporal GIS and set the region
  17. """
  18. tgis.init()
  19. cls.use_temp_region()
  20. cls.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")
  21. cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0,
  22. t=50, res=10, res3=10)
  23. @classmethod
  24. def tearDownClass(cls):
  25. """Remove the temporary region
  26. """
  27. cls.del_temp_region()
  28. def setUp(self):
  29. """Create input data
  30. """
  31. self.runModule("r.mapcalc", expression="a1 = 100", overwrite=True)
  32. self.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
  33. self.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
  34. self.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)
  35. self.runModule("r.mapcalc", expression="a5 = 500", overwrite=True)
  36. self.runModule("r.mapcalc", expression="a6 = 600", overwrite=True)
  37. self.runModule("t.create", type="strds", temporaltype="absolute",
  38. output="A", title="A test",
  39. description="A test", overwrite=True)
  40. self.runModule("t.register", flags="i", type="raster", input="A",
  41. maps="a1,a2,a3,a4,a5,a6",
  42. start="2001-01-01", increment="3 months",
  43. overwrite=True)
  44. self.runModule("t.create", type="strds", temporaltype="absolute",
  45. output="B", title="B test",
  46. description="B test", overwrite=True)
  47. self.runModule("t.register", flags="i", type="raster", input="B",
  48. maps="a1,a2,a3,a4,a5,a6",
  49. start="2001-01-01", increment="3 months",
  50. overwrite=True)
  51. def tearDown(self):
  52. """Remove generated data"""
  53. self.runModule("g.remove", flags='f', type="raster",
  54. name="a1,a2,a3,a4,a5,a6")
  55. def test_1(self):
  56. """Perform several unregistration operations"""
  57. # Prepare some strings for the tests
  58. new_line = os.linesep
  59. a = ["a1","a2","a3","a4","a5","a6"]
  60. al = new_line.join(a)
  61. al += new_line
  62. a123 = new_line.join(a[:3])
  63. a123 += new_line
  64. a456 = new_line.join(a[3:])
  65. a456 += new_line
  66. # Unregister maps a1, a2 and a3 from STRDS A
  67. self.assertModule("t.unregister", input="A", maps="a1,a2,a3")
  68. lister = SimpleModule("t.rast.list", input="A", columns="name",
  69. flags="u")
  70. self.runModule(lister)
  71. self.assertEqual(a456, lister.outputs.stdout)
  72. # Check if all maps are present in STRDS B
  73. lister = SimpleModule("t.rast.list", input="B", columns="name",
  74. flags="u")
  75. self.runModule(lister)
  76. self.assertEqual(al, lister.outputs.stdout)
  77. # Check if maps a1, a2 and a3 are still present in the temporal database
  78. lister = SimpleModule("t.list", type="raster", columns="name",
  79. where='mapset = "%s" AND (name = "a1" OR name = "a2" OR name = "a3")'%(tgis.get_current_mapset()))
  80. self.runModule(lister)
  81. self.assertEqual(a123, lister.outputs.stdout)
  82. # Unregister maps a1, a2 and a3 from the temporal database
  83. self.assertModule("t.unregister", maps="a1,a2,a3")
  84. lister = SimpleModule("t.list", type="raster", columns="name",
  85. where='mapset = "%s" AND (name = "a1" OR name = "a2" OR name = "a3")'%(tgis.get_current_mapset()))
  86. self.runModule(lister)
  87. self.assertEqual("", lister.outputs.stdout)
  88. # Check that masp a1, a2 and a3 are not present in STRDS B
  89. lister = SimpleModule("t.rast.list", input="B", columns="name",
  90. flags="u")
  91. self.runModule(lister)
  92. self.assertEqual(a456, lister.outputs.stdout)
  93. # Remove STRDS A and B and check if maps a4, a5 and a6 are still in the temporal database
  94. self.assertModule("t.remove", type="strds", inputs="A,B")
  95. lister = SimpleModule("t.list", type="raster", columns="name",
  96. where='mapset = "%s" AND (name = "a4" OR name = "a5" OR name = "a6")'%(tgis.get_current_mapset()))
  97. self.runModule(lister)
  98. self.assertEqual(a456, lister.outputs.stdout)
  99. # Unregister maps a4, a5 and a6 from the temporal database
  100. self.assertModule("t.unregister", maps="a4,a5,a6")
  101. lister = SimpleModule("t.list", type="raster", columns="name",
  102. where='mapset = "%s" AND (name = "a4" OR name = "a5" OR name = "a6")'%(tgis.get_current_mapset()))
  103. self.runModule(lister)
  104. self.assertEqual("", lister.outputs.stdout)
  105. if __name__ == '__main__':
  106. from grass.gunittest.main import test
  107. test()