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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/python-lib/cuddlefish/tests/__init__.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import os
     1.9 +import unittest
    1.10 +import doctest
    1.11 +import glob
    1.12 +
    1.13 +env_root = os.environ['CUDDLEFISH_ROOT']
    1.14 +
    1.15 +def get_tests():
    1.16 +    import cuddlefish
    1.17 +    import cuddlefish.tests
    1.18 +
    1.19 +    tests = []
    1.20 +    packages = [cuddlefish, cuddlefish.tests]
    1.21 +    for package in packages:
    1.22 +        path = os.path.abspath(package.__path__[0])
    1.23 +        pynames = glob.glob(os.path.join(path, '*.py'))
    1.24 +        for filename in pynames:
    1.25 +            basename = os.path.basename(filename)
    1.26 +            module_name = os.path.splitext(basename)[0]
    1.27 +            full_name = "%s.%s" % (package.__name__, module_name)
    1.28 +            module = __import__(full_name, fromlist=[package.__name__])
    1.29 +
    1.30 +            loader = unittest.TestLoader()
    1.31 +            suite = loader.loadTestsFromModule(module)
    1.32 +            for test in suite:
    1.33 +                tests.append(test)
    1.34 +
    1.35 +            finder = doctest.DocTestFinder()
    1.36 +            doctests = finder.find(module)
    1.37 +            for test in doctests:
    1.38 +                if len(test.examples) > 0:
    1.39 +                    tests.append(doctest.DocTestCase(test))
    1.40 +
    1.41 +    return tests
    1.42 +
    1.43 +def run(verbose=False):
    1.44 +    if verbose:
    1.45 +        verbosity = 2
    1.46 +    else:
    1.47 +        verbosity = 1
    1.48 +
    1.49 +    tests = get_tests()
    1.50 +    suite = unittest.TestSuite(tests)
    1.51 +    runner = unittest.TextTestRunner(verbosity=verbosity)
    1.52 +    return runner.run(suite)
    1.53 +
    1.54 +if __name__ == '__main__':
    1.55 +    run()

mercurial