ยปCore Development>Code coverage>Lib/lib-tk/test/runtktests.py

Python code coverage for Lib/lib-tk/test/runtktests.py

#countcontent
1n/a"""
2n/aUse this module to get and run all tk tests.
3n/a
4n/aTkinter tests should live in a package inside the directory where this file
5n/alives, like test_tkinter.
6n/aExtensions also should live in packages following the same rule as above.
7n/a"""
8n/a
9n/aimport os
10n/aimport sys
11n/aimport unittest
12n/aimport importlib
13n/aimport test.test_support
14n/a
15n/athis_dir_path = os.path.abspath(os.path.dirname(__file__))
16n/a
17n/adef is_package(path):
18n/a for name in os.listdir(path):
19n/a if name in ('__init__.py', '__init__.pyc', '__init.pyo'):
20n/a return True
21n/a return False
22n/a
23n/adef get_tests_modules(basepath=this_dir_path, gui=True, packages=None):
24n/a """This will import and yield modules whose names start with test_
25n/a and are inside packages found in the path starting at basepath.
26n/a
27n/a If packages is specified it should contain package names that want
28n/a their tests colleted.
29n/a """
30n/a py_ext = '.py'
31n/a
32n/a for dirpath, dirnames, filenames in os.walk(basepath):
33n/a for dirname in list(dirnames):
34n/a if dirname[0] == '.':
35n/a dirnames.remove(dirname)
36n/a
37n/a if is_package(dirpath) and filenames:
38n/a pkg_name = dirpath[len(basepath) + len(os.sep):].replace('/', '.')
39n/a if packages and pkg_name not in packages:
40n/a continue
41n/a
42n/a filenames = filter(
43n/a lambda x: x.startswith('test_') and x.endswith(py_ext),
44n/a filenames)
45n/a
46n/a for name in filenames:
47n/a try:
48n/a yield importlib.import_module(
49n/a ".%s" % name[:-len(py_ext)], pkg_name)
50n/a except test.test_support.ResourceDenied:
51n/a if gui:
52n/a raise
53n/a
54n/adef get_tests(text=True, gui=True, packages=None):
55n/a """Yield all the tests in the modules found by get_tests_modules.
56n/a
57n/a If nogui is True, only tests that do not require a GUI will be
58n/a returned."""
59n/a attrs = []
60n/a if text:
61n/a attrs.append('tests_nogui')
62n/a if gui:
63n/a attrs.append('tests_gui')
64n/a for module in get_tests_modules(gui=gui, packages=packages):
65n/a for attr in attrs:
66n/a for test in getattr(module, attr, ()):
67n/a yield test
68n/a
69n/aif __name__ == "__main__":
70n/a test.test_support.use_resources = ['gui']
71n/a test.test_support.run_unittest(*get_tests())