test_start_command_functions_nc.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Tests of start_command function family in nc location"""
  2. from grass.gunittest.case import TestCase
  3. from grass.gunittest.main import test
  4. from grass.script.core import start_command, PIPE
  5. LOCATION = "nc"
  6. class TestPythonKeywordsInParameters(TestCase):
  7. """Tests additional underscore syntax which helps to avoid Python keywords
  8. It works the same for keywords, buildins and any names.
  9. """
  10. raster = "elevation"
  11. # fresh region for each test function
  12. def setUp(self):
  13. self.use_temp_region()
  14. def tearDown(self):
  15. self.del_temp_region()
  16. def test_prefixed_underscore(self):
  17. proc = start_command("g.region", _raster=self.raster, stderr=PIPE)
  18. stderr = proc.communicate()[1]
  19. returncode = proc.poll()
  20. self.assertEquals(returncode, 0, msg="Underscore as prefix was not accepted")
  21. self.assertNotIn(b"_raster", stderr)
  22. def test_suffixed_underscore(self):
  23. proc = start_command("g.region", raster_=self.raster, stderr=PIPE)
  24. stderr = proc.communicate()[1]
  25. returncode = proc.poll()
  26. self.assertEquals(
  27. returncode,
  28. 0,
  29. msg="Underscore as suffix was not accepted, stderr is:\n%s" % stderr,
  30. )
  31. self.assertNotIn(b"raster_", stderr)
  32. def test_multiple_underscores(self):
  33. proc = start_command("g.region", _raster_=self.raster, stderr=PIPE)
  34. stderr = proc.communicate()[1]
  35. returncode = proc.poll()
  36. self.assertEquals(returncode, 1, msg="Underscore at both sides was accepted")
  37. self.assertIn(b"raster", stderr)
  38. if __name__ == "__main__":
  39. test()