test_start_command_functions_nc.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """Tests of start_command function family in nc location"""
  2. LOCATION = 'nc'
  3. from grass.gunittest.case import TestCase
  4. from grass.gunittest.main import test
  5. from grass.script.core import start_command, PIPE
  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(
  18. 'g.region', _raster=self.raster, stderr=PIPE)
  19. stderr = proc.communicate()[1]
  20. returncode = proc.poll()
  21. self.assertEquals(returncode, 0,
  22. msg="Underscore as prefix was not accepted")
  23. self.assertNotIn(b'_raster', stderr)
  24. def test_suffixed_underscore(self):
  25. proc = start_command(
  26. 'g.region', raster_=self.raster, stderr=PIPE)
  27. stderr = proc.communicate()[1]
  28. returncode = proc.poll()
  29. self.assertEquals(returncode, 0,
  30. msg="Underscore as suffix was not accepted, stderr is:\n%s" % stderr)
  31. self.assertNotIn(b'raster_', stderr)
  32. def test_multiple_underscores(self):
  33. proc = start_command(
  34. 'g.region', _raster_=self.raster, stderr=PIPE)
  35. stderr = proc.communicate()[1]
  36. returncode = proc.poll()
  37. self.assertEquals(returncode, 1,
  38. msg="Underscore at both sides was accepted")
  39. self.assertIn(b'raster', stderr)
  40. if __name__ == '__main__':
  41. test()