test_start_command_functions.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. # the utf-8 is important because we do use the characters
  3. """Tests of start_command function family (location independent)"""
  4. from grass.gunittest.case import TestCase
  5. from grass.gunittest.main import test
  6. from grass.script.core import start_command, PIPE, run_command
  7. class TestPythonKeywordsInParameters(TestCase):
  8. """Tests additional underscore syntax which helps to avoid Python keywords
  9. It works the same for keywords, buildins and any names.
  10. """
  11. raster = b'does_not_exist'
  12. def test_prefixed_underscore(self):
  13. proc = start_command(
  14. 'g.region', _raster=self.raster, stderr=PIPE)
  15. stderr = proc.communicate()[1]
  16. self.assertNotIn(b'_raster', stderr)
  17. self.assertIn(self.raster, stderr,
  18. msg="Raster map name should appear in the error output")
  19. def test_suffixed_underscore(self):
  20. proc = start_command(
  21. 'g.region', raster_=self.raster, stderr=PIPE)
  22. stderr = proc.communicate()[1]
  23. self.assertNotIn(b'raster_', stderr)
  24. self.assertIn(self.raster, stderr,
  25. msg="Raster map name should appear in the error output")
  26. def test_multiple_underscores(self):
  27. proc = start_command(
  28. 'g.region', _raster_=self.raster, stderr=PIPE)
  29. stderr = proc.communicate()[1]
  30. returncode = proc.poll()
  31. self.assertEquals(returncode, 1)
  32. self.assertIn(b'raster', stderr)
  33. class TestPythonModuleWithUnicodeParameters(TestCase):
  34. """Tests if unicode works in parameters of Python modules
  35. This in fact tests also the `parser()` function (original motivation
  36. for this tests).
  37. Using g.search.module because it takes any option values.
  38. """
  39. def test_python_module_ascii(self):
  40. """This tests if Python module works"""
  41. run_command('g.search.modules', keyword=b'Priserny kun')
  42. def test_python_module_czech_nonascii(self):
  43. """This likely fails on non-UTF-8 systems (i.e. MS Win)"""
  44. run_command('g.search.modules', keyword=b'Příšerný kůň')
  45. def test_python_module_czech_unicode(self):
  46. """This likely fails on non-UTF-8 systems (i.e. MS Win)"""
  47. run_command('g.search.modules', keyword=u'Příšerný kůň')
  48. if __name__ == '__main__':
  49. test()