test_doctests.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests checkers
  4. """
  5. import doctest
  6. import grass.gunittest.case
  7. import grass.gunittest.main
  8. import grass.gunittest.utils
  9. import grass.pygrass.raster as pgrass
  10. # doctest does not allow changing the base classes of test case, skip test case
  11. # and test suite, so we need to create a new type which inherits from our class
  12. # and contains doctest's methods
  13. # the alternative is to copy 500 from doctest and change what is needed
  14. # (this might be necessary anyway because of the reports and stdout and stderr)
  15. doctest.DocFileCase = type('DocFileCase',
  16. (grass.gunittest.case.TestCase,),
  17. dict(doctest.DocFileCase.__dict__))
  18. doctest.SkipDocTestCase = type('SkipDocTestCase',
  19. (grass.gunittest.case.TestCase,),
  20. dict(doctest.SkipDocTestCase.__dict__))
  21. def load_tests(loader, tests, ignore):
  22. # TODO: this must be somewhere when doctest is called, not here
  23. # TODO: ultimate solution is not to use _ as a buildin in lib/python
  24. # for now it is the only place where it works
  25. grass.gunittest.utils.do_doctest_gettext_workaround()
  26. # this should be called at some top level
  27. from grass.pygrass.modules import Module
  28. Module("g.region", n=40, s=0, e=40, w=0, res=10)
  29. Module("r.mapcalc",
  30. expression="%s = row() + (10 * col())" % (pgrass.test_raster_name),
  31. overwrite=True)
  32. Module("r.support", map=pgrass.test_raster_name,
  33. title="A test map",
  34. history="Generated by r.mapcalc",
  35. description="This is a test map")
  36. cats = """11:A
  37. 12:B
  38. 13:C
  39. 14:D
  40. 21:E
  41. 22:F
  42. 23:G
  43. 24:H
  44. 31:I
  45. 32:J
  46. 33:K
  47. 34:L
  48. 41:M
  49. 42:n
  50. 43:O
  51. 44:P"""
  52. Module("r.category", rules="-", map=pgrass.test_raster_name,
  53. stdin_=cats, separator=":")
  54. Module("r.mapcalc",
  55. expression="%s = row() + (10 * col())" % (pgrass.abstract.test_raster_name),
  56. overwrite=True)
  57. tests.addTests(doctest.DocTestSuite(pgrass))
  58. tests.addTests(doctest.DocTestSuite(pgrass.abstract))
  59. return tests
  60. if __name__ == '__main__':
  61. grass.gunittest.main.test()