test_what_strds.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. """Test v.what.strds
  3. (C) 2014 by the GRASS Development Team
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. @author Luca Delucchi
  8. """
  9. from grass.gunittest.case import TestCase
  10. from grass.gunittest.main import test
  11. from grass.gunittest.gmodules import SimpleModule
  12. import grass.script as gscript
  13. from grass.script.utils import decode
  14. class TestWhatStrds(TestCase):
  15. @classmethod
  16. def setUpClass(cls):
  17. """Initiate the temporal GIS and set the region
  18. """
  19. cls.use_temp_region()
  20. cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50,
  21. res=10, res3=10)
  22. cls.runModule("r.mapcalc", expression="a_1 = 100", overwrite=True)
  23. cls.runModule("r.mapcalc", expression="a_2 = 200", overwrite=True)
  24. cls.runModule("r.mapcalc", expression="a_3 = 300", overwrite=True)
  25. cls.runModule("r.mapcalc", expression="a_4 = 400", overwrite=True)
  26. cls.runModule("v.random", output="points", npoints=3, seed=1,
  27. overwrite=True)
  28. cls.runModule("t.create", type="strds", temporaltype="absolute",
  29. output="A", title="A test", description="A test",
  30. overwrite=True)
  31. cls.runModule("t.register", flags="i", type="raster", input="A",
  32. maps="a_1,a_2,a_3,a_4", start="2001-01-01",
  33. increment="3 months", overwrite=True)
  34. @classmethod
  35. def tearDownClass(cls):
  36. """Remove the temporary region
  37. """
  38. cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
  39. cls.del_temp_region()
  40. def test_output(self):
  41. self.assertModule("v.what.strds", input="points", strds="A",
  42. output="what_strds", overwrite=True)
  43. maps = gscript.list_strings('vector')
  44. self.assertIn('what_strds@{ma}'.format(ma=gscript.gisenv()['MAPSET']),
  45. maps)
  46. def test_values(self):
  47. self.assertModule("v.what.strds", input="points", strds="A",
  48. output="what_strds", overwrite=True)
  49. db_sel = SimpleModule("v.db.select", map="what_strds")
  50. self.assertModule(db_sel)
  51. output = """cat|A_2001_01_01|A_2001_04_01|A_2001_07_01|A_2001_10_01
  52. 1|100|200|300|400
  53. 2|100|200|300|400
  54. 3|100|200|300|400
  55. """
  56. self.assertMultiLineEqual(output, decode(db_sel.outputs.stdout))
  57. if __name__ == '__main__':
  58. test()