test_pygrass_raster_doctests.py 2.2 KB

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