test_pygrass_gis_doctests.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. from grass.pygrass import gis
  10. from grass.pygrass.gis import region
  11. # doctest does not allow changing the base classes of test case, skip test case
  12. # and test suite, so we need to create a new type which inherits from our class
  13. # and contains doctest's methods
  14. # the alternative is to copy 500 from doctest and change what is needed
  15. # (this might be necessary anyway because of the reports and stdout and stderr)
  16. doctest.DocFileCase = type(
  17. "DocFileCase", (grass.gunittest.case.TestCase,), dict(doctest.DocFileCase.__dict__)
  18. )
  19. doctest.SkipDocTestCase = type(
  20. "SkipDocTestCase",
  21. (grass.gunittest.case.TestCase,),
  22. dict(doctest.SkipDocTestCase.__dict__),
  23. )
  24. def load_tests(loader, tests, ignore):
  25. # TODO: this must be somewhere when doctest is called, not here
  26. # TODO: ultimate solution is not to use _ as a buildin in lib/python
  27. # for now it is the only place where it works
  28. grass.gunittest.utils.do_doctest_gettext_workaround()
  29. from grass.pygrass import utils
  30. from grass.script.core import run_command
  31. utils.create_test_vector_map(gis.test_vector_name)
  32. utils.create_test_vector_map(gis.region.test_vector_name)
  33. run_command("g.region", n=50, s=0, e=60, w=0, res=1)
  34. run_command(
  35. "r.mapcalc", expression="%s = 1" % (gis.test_raster_name), overwrite=True
  36. )
  37. run_command(
  38. "r.mapcalc", expression="%s = 1" % (gis.region.test_raster_name), overwrite=True
  39. )
  40. run_command("g.region", n=40, s=0, e=40, w=0, res=2)
  41. # this should be called at some top level
  42. tests.addTests(doctest.DocTestSuite(gis))
  43. tests.addTests(doctest.DocTestSuite(region))
  44. return tests
  45. if __name__ == "__main__":
  46. grass.gunittest.main.test()