test_r_grow_quoting.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Created on Mon 17 Feb 2020 02:27:26 PM UTC
  3. @author: Markus Neteler, Maris Nartiss upon https://github.com/OSGeo/grass/pull/277
  4. """
  5. import os
  6. from grass.gunittest.case import TestCase
  7. from grass.gunittest.main import test
  8. from grass.gunittest.gmodules import SimpleModule
  9. from grass.script.core import run_command
  10. from grass.gunittest.utils import silent_rmtree
  11. class TestRGrow(TestCase):
  12. """Test r.grow script"""
  13. map1 = "elevation"
  14. temp1 = "grown"
  15. mapsets_to_remove = []
  16. # mapset with a name is also a valid mathematical expression
  17. mapset_name = "1234-56-78"
  18. gisenv = SimpleModule("g.gisenv", get="MAPSET")
  19. TestCase.runModule(gisenv, expecting_stdout=True)
  20. old_mapset = gisenv.outputs.stdout.strip()
  21. @classmethod
  22. def setUpClass(cls):
  23. """Create maps in a small region."""
  24. # create a mapset with a name is also a valid mathematical expression
  25. cls.runModule("g.mapset", flags="c", mapset=cls.mapset_name)
  26. cls.mapsets_to_remove.append(cls.mapset_name)
  27. run_command("g.copy", raster=cls.map1 + "@PERMANENT," + cls.map1)
  28. cls.runModule("g.region", raster=cls.map1, flags="p")
  29. @classmethod
  30. def tearDownClass(cls):
  31. """Remove temporary data"""
  32. gisenv = SimpleModule("g.gisenv", get="GISDBASE")
  33. cls.runModule(gisenv, expecting_stdout=True)
  34. gisdbase = gisenv.outputs.stdout.strip()
  35. gisenv = SimpleModule("g.gisenv", get="LOCATION_NAME")
  36. cls.runModule(gisenv, expecting_stdout=True)
  37. location = gisenv.outputs.stdout.strip()
  38. cls.runModule("g.remove", flags="f", type="raster", name=(cls.temp1,))
  39. cls.runModule("g.mapset", mapset=cls.old_mapset)
  40. for mapset_name in cls.mapsets_to_remove:
  41. mapset_path = os.path.join(gisdbase, location, mapset_name)
  42. silent_rmtree(mapset_path)
  43. def test_grow(self):
  44. """grows test with special mapset name"""
  45. # should not lead to syntax error, unexpected INTEGER, expecting VARNAME or NAME
  46. module = SimpleModule(
  47. "r.grow", input=self.map1 + "@" + self.mapset_name, output=self.temp1
  48. )
  49. self.assertModule(module)
  50. if __name__ == "__main__":
  51. test()