test_modules.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Jun 24 09:43:53 2014
  4. @author: pietro
  5. """
  6. from fnmatch import fnmatch
  7. from grass.gunittest.case import TestCase
  8. from grass.gunittest.main import test
  9. from grass.script.core import get_commands
  10. from grass.pygrass.modules.interface import Module
  11. SKIP = ["g.parser", ]
  12. class TestModulesMeta(type):
  13. def __new__(mcs, name, bases, dict):
  14. def gen_test(cmd):
  15. def test(self):
  16. Module(cmd)
  17. return test
  18. cmds = [c for c in sorted(list(get_commands()[0]))
  19. if c not in SKIP and not fnmatch(c, "g.gui.*")]
  20. for cmd in cmds:
  21. test_name = "test__%s" % cmd.replace('.', '_')
  22. dict[test_name] = gen_test(cmd)
  23. return type.__new__(mcs, name, bases, dict)
  24. class TestModules(TestCase):
  25. __metaclass__ = TestModulesMeta
  26. class TestModulesPickability(TestCase):
  27. def test_rsun(self):
  28. """Test if a Module instance is pickable"""
  29. import pickle
  30. from StringIO import StringIO
  31. out = StringIO()
  32. pickle.dump(Module('r.sun'), out)
  33. out.close()
  34. if __name__ == '__main__':
  35. test()