ยปCore Development>Code coverage>Lib/tkinter/test/runtktests.py

Python code coverage for Lib/tkinter/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 importlib
11n/aimport test.support
12n/a
13n/athis_dir_path = os.path.abspath(os.path.dirname(__file__))
14n/a
15n/adef is_package(path):
16n/a for name in os.listdir(path):
17n/a if name in ('__init__.py', '__init__.pyc'):
18n/a return True
19n/a return False
20n/a
21n/adef get_tests_modules(basepath=this_dir_path, gui=True, packages=None):
22n/a """This will import and yield modules whose names start with test_
23n/a and are inside packages found in the path starting at basepath.
24n/a
25n/a If packages is specified it should contain package names that
26n/a want their tests collected.
27n/a """
28n/a py_ext = '.py'
29n/a
30n/a for dirpath, dirnames, filenames in os.walk(basepath):
31n/a for dirname in list(dirnames):
32n/a if dirname[0] == '.':
33n/a dirnames.remove(dirname)
34n/a
35n/a if is_package(dirpath) and filenames:
36n/a pkg_name = dirpath[len(basepath) + len(os.sep):].replace('/', '.')
37n/a if packages and pkg_name not in packages:
38n/a continue
39n/a
40n/a filenames = filter(
41n/a lambda x: x.startswith('test_') and x.endswith(py_ext),
42n/a filenames)
43n/a
44n/a for name in filenames:
45n/a try:
46n/a yield importlib.import_module(
47n/a ".%s.%s" % (pkg_name, name[:-len(py_ext)]),
48n/a "tkinter.test")
49n/a except test.support.ResourceDenied:
50n/a if gui:
51n/a raise
52n/a
53n/adef get_tests(text=True, gui=True, packages=None):
54n/a """Yield all the tests in the modules found by get_tests_modules.
55n/a
56n/a If nogui is True, only tests that do not require a GUI will be
57n/a returned."""
58n/a attrs = []
59n/a if text:
60n/a attrs.append('tests_nogui')
61n/a if gui:
62n/a attrs.append('tests_gui')
63n/a for module in get_tests_modules(gui=gui, packages=packages):
64n/a for attr in attrs:
65n/a for test in getattr(module, attr, ()):
66n/a yield test
67n/a
68n/aif __name__ == "__main__":
69n/a test.support.run_unittest(*get_tests())