test_start_command_functions.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Tests of start_command function family (location independent)"""
  2. import grass.gunittest
  3. from grass.script.core import start_command, PIPE
  4. class TestPythonKeywordsInParameters(grass.gunittest.TestCase):
  5. """Tests additional underscore syntax which helps to avoid Python keywords
  6. It works the same for keywords, buildins and any names.
  7. """
  8. raster = 'does_not_exist'
  9. def test_prefixed_underscore(self):
  10. proc = start_command(
  11. 'g.region', _rast=self.raster, stderr=PIPE)
  12. stderr = proc.communicate()[1]
  13. self.assertNotIn('_rast', stderr)
  14. self.assertIn(self.raster, stderr,
  15. msg="Raster map name should appear in the error output")
  16. def test_suffixed_underscore(self):
  17. proc = start_command(
  18. 'g.region', rast_=self.raster, stderr=PIPE)
  19. stderr = proc.communicate()[1]
  20. self.assertNotIn('rast_', stderr)
  21. self.assertIn(self.raster, stderr,
  22. msg="Raster map name should appear in the error output")
  23. def test_multiple_underscores(self):
  24. proc = start_command(
  25. 'g.region', _rast_=self.raster, stderr=PIPE)
  26. stderr = proc.communicate()[1]
  27. returncode = proc.poll()
  28. self.assertEquals(returncode, 1)
  29. self.assertIn('rast', stderr)
  30. if __name__ == '__main__':
  31. grass.gunittest.test()