test_pygrass_raster_doctests.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(
  16. "DocFileCase", (grass.gunittest.case.TestCase,), dict(doctest.DocFileCase.__dict__)
  17. )
  18. doctest.SkipDocTestCase = type(
  19. "SkipDocTestCase",
  20. (grass.gunittest.case.TestCase,),
  21. dict(doctest.SkipDocTestCase.__dict__),
  22. )
  23. def load_tests(loader, tests, ignore):
  24. # TODO: this must be somewhere when doctest is called, not here
  25. # TODO: ultimate solution is not to use _ as a buildin in lib/python
  26. # for now it is the only place where it works
  27. grass.gunittest.utils.do_doctest_gettext_workaround()
  28. # this should be called at some top level
  29. from grass.pygrass.modules import Module
  30. Module("g.region", n=40, s=0, e=40, w=0, res=10)
  31. Module(
  32. "r.mapcalc",
  33. expression="%s = row() + (10 * col())" % (pgrass.test_raster_name),
  34. overwrite=True,
  35. )
  36. Module(
  37. "r.support",
  38. map=pgrass.test_raster_name,
  39. title="A test map",
  40. history="Generated by r.mapcalc",
  41. description="This is a test map",
  42. )
  43. cats = """11:A
  44. 12:B
  45. 13:C
  46. 14:D
  47. 21:E
  48. 22:F
  49. 23:G
  50. 24:H
  51. 31:I
  52. 32:J
  53. 33:K
  54. 34:L
  55. 41:M
  56. 42:n
  57. 43:O
  58. 44:P"""
  59. Module(
  60. "r.category", rules="-", map=pgrass.test_raster_name, stdin_=cats, separator=":"
  61. )
  62. Module(
  63. "r.mapcalc",
  64. expression="%s = row() + (10 * col())" % (pgrass.abstract.test_raster_name),
  65. overwrite=True,
  66. )
  67. tests.addTests(doctest.DocTestSuite(pgrass))
  68. tests.addTests(doctest.DocTestSuite(pgrass.abstract))
  69. return tests
  70. if __name__ == "__main__":
  71. grass.gunittest.main.test()