addon-sdk/source/python-lib/cuddlefish/tests/__init__.py

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:f28542e6f349
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
5 import os
6 import unittest
7 import doctest
8 import glob
9
10 env_root = os.environ['CUDDLEFISH_ROOT']
11
12 def get_tests():
13 import cuddlefish
14 import cuddlefish.tests
15
16 tests = []
17 packages = [cuddlefish, cuddlefish.tests]
18 for package in packages:
19 path = os.path.abspath(package.__path__[0])
20 pynames = glob.glob(os.path.join(path, '*.py'))
21 for filename in pynames:
22 basename = os.path.basename(filename)
23 module_name = os.path.splitext(basename)[0]
24 full_name = "%s.%s" % (package.__name__, module_name)
25 module = __import__(full_name, fromlist=[package.__name__])
26
27 loader = unittest.TestLoader()
28 suite = loader.loadTestsFromModule(module)
29 for test in suite:
30 tests.append(test)
31
32 finder = doctest.DocTestFinder()
33 doctests = finder.find(module)
34 for test in doctests:
35 if len(test.examples) > 0:
36 tests.append(doctest.DocTestCase(test))
37
38 return tests
39
40 def run(verbose=False):
41 if verbose:
42 verbosity = 2
43 else:
44 verbosity = 1
45
46 tests = get_tests()
47 suite = unittest.TestSuite(tests)
48 runner = unittest.TextTestRunner(verbosity=verbosity)
49 return runner.run(suite)
50
51 if __name__ == '__main__':
52 run()

mercurial