test_start_command_functions.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Tests of start_command function family (location independent)"""
  2. from grass.gunittest.case import TestCase
  3. from grass.gunittest.main import test
  4. from grass.script.core import start_command, PIPE
  5. class TestPythonKeywordsInParameters(TestCase):
  6. """Tests additional underscore syntax which helps to avoid Python keywords
  7. It works the same for keywords, buildins and any names.
  8. """
  9. raster = b'does_not_exist'
  10. def test_prefixed_underscore(self):
  11. proc = start_command(
  12. 'g.region', _raster=self.raster, stderr=PIPE)
  13. stderr = proc.communicate()[1]
  14. self.assertNotIn(b'_raster', stderr)
  15. self.assertIn(self.raster, stderr,
  16. msg="Raster map name should appear in the error output")
  17. def test_suffixed_underscore(self):
  18. proc = start_command(
  19. 'g.region', raster_=self.raster, stderr=PIPE)
  20. stderr = proc.communicate()[1]
  21. self.assertNotIn(b'raster_', stderr)
  22. self.assertIn(self.raster, stderr,
  23. msg="Raster map name should appear in the error output")
  24. def test_multiple_underscores(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, 1)
  30. self.assertIn(b'raster', stderr)
  31. if __name__ == '__main__':
  32. test()