test_start_command_functions_nc.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Tests of start_command function family in nc location"""
  2. LOCATION = 'nc'
  3. import grass.gunittest
  4. from grass.script.core import start_command, PIPE
  5. class TestPythonKeywordsInParameters(grass.gunittest.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 = 'elevation'
  10. # fresh region for each test function
  11. def setUp(self):
  12. self.use_temp_region()
  13. def tearDown(self):
  14. self.del_temp_region()
  15. def test_prefixed_underscore(self):
  16. proc = start_command(
  17. 'g.region', _raster=self.raster, stderr=PIPE)
  18. stderr = proc.communicate()[1]
  19. returncode = proc.poll()
  20. self.assertEquals(returncode, 0,
  21. msg="Underscore as prefix was not accepted")
  22. self.assertNotIn('_raster', stderr)
  23. def test_suffixed_underscore(self):
  24. proc = start_command(
  25. 'g.region', raster_=self.raster, stderr=PIPE)
  26. stderr = proc.communicate()[1]
  27. returncode = proc.poll()
  28. self.assertEquals(returncode, 0,
  29. msg="Underscore as suffix was not accepted, stderr is:\n%s" % stderr)
  30. self.assertNotIn('raster_', stderr)
  31. def test_multiple_underscores(self):
  32. proc = start_command(
  33. 'g.region', _raster_=self.raster, stderr=PIPE)
  34. stderr = proc.communicate()[1]
  35. returncode = proc.poll()
  36. self.assertEquals(returncode, 1,
  37. msg="Underscore at both sides was accepted")
  38. self.assertIn('raster', stderr)
  39. if __name__ == '__main__':
  40. grass.gunittest.test()