Back to index

python3.2  3.2.2
Functions | Variables
tkinter.test.runtktests Namespace Reference

Functions

def is_package
def get_tests_modules
def get_tests

Variables

tuple this_dir_path = os.path.abspath(os.path.dirname(__file__))

Detailed Description

Use this module to get and run all tk tests.

tkinter tests should live in a package inside the directory where this file
lives, like test_tkinter.
Extensions also should live in packages following the same rule as above.

Function Documentation

def tkinter.test.runtktests.get_tests (   text = True,
  gui = True,
  packages = None 
)
Yield all the tests in the modules found by get_tests_modules.

If nogui is True, only tests that do not require a GUI will be
returned.

Definition at line 55 of file runtktests.py.

00055 
00056 def get_tests(text=True, gui=True, packages=None):
00057     """Yield all the tests in the modules found by get_tests_modules.
00058 
00059     If nogui is True, only tests that do not require a GUI will be
00060     returned."""
00061     attrs = []
00062     if text:
00063         attrs.append('tests_nogui')
00064     if gui:
00065         attrs.append('tests_gui')
00066     for module in get_tests_modules(gui=gui, packages=packages):
00067         for attr in attrs:
00068             for test in getattr(module, attr, ()):
00069                 yield test

Here is the call graph for this function:

def tkinter.test.runtktests.get_tests_modules (   basepath = this_dir_path,
  gui = True,
  packages = None 
)
This will import and yield modules whose names start with test_
and are inside packages found in the path starting at basepath.

If packages is specified it should contain package names that
want their tests collected.

Definition at line 23 of file runtktests.py.

00023 
00024 def get_tests_modules(basepath=this_dir_path, gui=True, packages=None):
00025     """This will import and yield modules whose names start with test_
00026     and are inside packages found in the path starting at basepath.
00027 
00028     If packages is specified it should contain package names that
00029     want their tests collected.
00030     """
00031     py_ext = '.py'
00032 
00033     for dirpath, dirnames, filenames in os.walk(basepath):
00034         for dirname in list(dirnames):
00035             if dirname[0] == '.':
00036                 dirnames.remove(dirname)
00037 
00038         if is_package(dirpath) and filenames:
00039             pkg_name = dirpath[len(basepath) + len(os.sep):].replace('/', '.')
00040             if packages and pkg_name not in packages:
00041                 continue
00042 
00043             filenames = filter(
00044                     lambda x: x.startswith('test_') and x.endswith(py_ext),
00045                     filenames)
00046 
00047             for name in filenames:
00048                 try:
00049                     yield importlib.import_module(
00050                         ".%s.%s" % (pkg_name, name[:-len(py_ext)]),
00051                         "tkinter.test")
00052                 except test.support.ResourceDenied:
00053                     if gui:
00054                         raise

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 17 of file runtktests.py.

00017 
00018 def is_package(path):
00019     for name in os.listdir(path):
00020         if name in ('__init__.py', '__init__.pyc', '__init.pyo'):
00021             return True
00022     return False

Here is the caller graph for this function:


Variable Documentation

tuple tkinter.test.runtktests.this_dir_path = os.path.abspath(os.path.dirname(__file__))

Definition at line 15 of file runtktests.py.