test_pygrass_doctests.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.utils as gutils
  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. from grass.script.core import run_command
  26. gutils.create_test_vector_map(gutils.test_vector_name)
  27. run_command("g.region", n=50, s=0, e=60, w=0, res=1)
  28. run_command(
  29. "r.mapcalc", expression="%s = 1" % (gutils.test_raster_name), overwrite=True
  30. )
  31. # for now it is the only place where it works
  32. grass.gunittest.utils.do_doctest_gettext_workaround()
  33. # this should be called at some top level
  34. tests.addTests(doctest.DocTestSuite(gutils))
  35. return tests
  36. if __name__ == "__main__":
  37. grass.gunittest.main.test()