test_pygrass_doctests.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.utils as gutils
  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('DocFileCase',
  16. (grass.gunittest.case.TestCase,),
  17. dict(doctest.DocFileCase.__dict__))
  18. doctest.SkipDocTestCase = type('SkipDocTestCase',
  19. (grass.gunittest.case.TestCase,),
  20. dict(doctest.SkipDocTestCase.__dict__))
  21. def load_tests(loader, tests, ignore):
  22. # TODO: this must be somewhere when doctest is called, not here
  23. # TODO: ultimate solution is not to use _ as a buildin in lib/python
  24. from grass.script.core import run_command
  25. gutils.create_test_vector_map(gutils.test_vector_name)
  26. run_command("g.region", n=50, s=0, e=60, w=0, res=1)
  27. run_command("r.mapcalc", expression="%s = 1"%(gutils.test_raster_name),
  28. overwrite=True)
  29. # for now it is the only place where it works
  30. grass.gunittest.utils.do_doctest_gettext_workaround()
  31. # this should be called at some top level
  32. tests.addTests(doctest.DocTestSuite(gutils))
  33. return tests
  34. if __name__ == '__main__':
  35. grass.gunittest.main.test()