test_modules.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 import TestCase, test
  8. from grass.script.core import get_commands
  9. from grass.pygrass.modules.interface import Module
  10. SKIP = ["g.parser", ]
  11. class TestModulesMeta(type):
  12. def __new__(mcs, name, bases, dict):
  13. def gen_test(cmd):
  14. def test(self):
  15. Module(cmd)
  16. return test
  17. cmds = [c for c in sorted(list(get_commands()[0]))
  18. if c not in SKIP and not fnmatch(c, "g.gui.*")]
  19. for cmd in cmds:
  20. test_name = "test__%s" % cmd.replace('.', '_')
  21. dict[test_name] = gen_test(cmd)
  22. return type.__new__(mcs, name, bases, dict)
  23. class TestModules(TestCase):
  24. __metaclass__ = TestModulesMeta
  25. class TestModulesPickability(TestCase):
  26. def test_rsun(self):
  27. """Test if a Module instance is pickable"""
  28. import pickle
  29. from StringIO import StringIO
  30. out = StringIO()
  31. pickle.dump(Module('r.sun'), out)
  32. out.close()
  33. if __name__ == '__main__':
  34. test()