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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/.
     5 import os
     6 import unittest
     7 import doctest
     8 import glob
    10 env_root = os.environ['CUDDLEFISH_ROOT']
    12 def get_tests():
    13     import cuddlefish
    14     import cuddlefish.tests
    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__])
    27             loader = unittest.TestLoader()
    28             suite = loader.loadTestsFromModule(module)
    29             for test in suite:
    30                 tests.append(test)
    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))
    38     return tests
    40 def run(verbose=False):
    41     if verbose:
    42         verbosity = 2
    43     else:
    44         verbosity = 1
    46     tests = get_tests()
    47     suite = unittest.TestSuite(tests)
    48     runner = unittest.TextTestRunner(verbosity=verbosity)
    49     return runner.run(suite)
    51 if __name__ == '__main__':
    52     run()

mercurial