test_g_search_modules.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. TEST: test_g.search.modules.py
  3. AUTHOR(S): Jachym Cepicky <jachym.cepicky gmail com>
  4. PURPOSE: Test g.search.modules script outputs
  5. COPYRIGHT: (C) 2015 Jachym Ceppicky, and by the GRASS Development Team
  6. This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. from grass.gunittest.main import test
  12. from grass.gunittest.gmodules import SimpleModule
  13. import termcolor
  14. import os
  15. class TestSearchModule(TestCase):
  16. def test_terminal_output(self):
  17. """ """
  18. module = SimpleModule('g.search.modules', keyword="water")
  19. self.assertModule(module)
  20. stdout = module.outputs.stdout
  21. self.assertEqual(stdout.split()[0], 'r.watershed')
  22. def test_json_output(self):
  23. import json
  24. module = SimpleModule('g.search.modules', keyword="water", flags="j")
  25. self.assertModule(module)
  26. stdout = json.loads(module.outputs.stdout)
  27. self.assertEqual(len(stdout), 6, 'Six modules found')
  28. self.assertEqual(stdout[3]['name'], 'r.basins.fill', 'r.basins.fill')
  29. self.assertTrue('keywords' in stdout[3]['attributes'])
  30. def test_shell_outout(self):
  31. module = SimpleModule('g.search.modules', keyword="water", flags="g")
  32. self.assertModule(module)
  33. stdout = module.outputs.stdout.split()
  34. self.assertEqual(len(stdout), 6)
  35. self.assertEqual(stdout[3], 'r.basins.fill')
  36. def test_colored_terminal(self):
  37. module = SimpleModule('g.search.modules', keyword="water", flags="c")
  38. self.assertModule(module)
  39. stdout = module.outputs.stdout.split()
  40. self.assertEqual(stdout[0],
  41. termcolor.colored('r.watershed',
  42. attrs=['bold']))
  43. def test_manual_pages(self):
  44. module = SimpleModule('g.search.modules', keyword="kapri", flags="gm")
  45. self.assertModule(module)
  46. stdout = module.outputs.stdout.split()
  47. self.assertEqual(len(stdout), 2)
  48. if __name__ == '__main__':
  49. test()