__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import os
  5. import unittest
  6. import doctest
  7. import glob
  8. env_root = os.environ['CUDDLEFISH_ROOT']
  9. def get_tests():
  10. import cuddlefish
  11. import cuddlefish.tests
  12. tests = []
  13. packages = [cuddlefish, cuddlefish.tests]
  14. for package in packages:
  15. path = os.path.abspath(package.__path__[0])
  16. pynames = glob.glob(os.path.join(path, '*.py'))
  17. for filename in pynames:
  18. basename = os.path.basename(filename)
  19. module_name = os.path.splitext(basename)[0]
  20. full_name = "%s.%s" % (package.__name__, module_name)
  21. module = __import__(full_name, fromlist=[package.__name__])
  22. loader = unittest.TestLoader()
  23. suite = loader.loadTestsFromModule(module)
  24. for test in suite:
  25. tests.append(test)
  26. finder = doctest.DocTestFinder()
  27. doctests = finder.find(module)
  28. for test in doctests:
  29. if len(test.examples) > 0:
  30. tests.append(doctest.DocTestCase(test))
  31. return tests
  32. def run(verbose=False):
  33. if verbose:
  34. verbosity = 2
  35. else:
  36. verbosity = 1
  37. tests = get_tests()
  38. suite = unittest.TestSuite(tests)
  39. runner = unittest.TextTestRunner(verbosity=verbosity)
  40. return runner.run(suite)
  41. if __name__ == '__main__':
  42. run()