test_pygrass_gis_doctests.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. Tests checkers
  3. """
  4. import doctest
  5. import grass.gunittest.case
  6. import grass.gunittest.main
  7. import grass.gunittest.utils
  8. from grass.pygrass import gis
  9. from grass.pygrass.gis import region
  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. from grass.pygrass import utils
  29. from grass.script.core import run_command
  30. utils.create_test_vector_map(gis.test_vector_name)
  31. utils.create_test_vector_map(gis.region.test_vector_name)
  32. run_command("g.region", n=50, s=0, e=60, w=0, res=1)
  33. run_command(
  34. "r.mapcalc", expression="%s = 1" % (gis.test_raster_name), overwrite=True
  35. )
  36. run_command(
  37. "r.mapcalc", expression="%s = 1" % (gis.region.test_raster_name), overwrite=True
  38. )
  39. run_command("g.region", n=40, s=0, e=40, w=0, res=2)
  40. # this should be called at some top level
  41. tests.addTests(doctest.DocTestSuite(gis))
  42. tests.addTests(doctest.DocTestSuite(region))
  43. return tests
  44. if __name__ == "__main__":
  45. grass.gunittest.main.test()