summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tools/__init__.py
blob: 9b94cb4483eaa5b9c87800e33614d9676206969c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Support functions for testing scripts in the Tools directory."""
import os
import unittest
import importlib
from test import support
from fnmatch import fnmatch

basepath = os.path.dirname(                 # <src/install dir>
                os.path.dirname(                # Lib
                    os.path.dirname(                # test
                        os.path.dirname(__file__))))    # test_tools

toolsdir = os.path.join(basepath, 'Tools')
scriptsdir = os.path.join(toolsdir, 'scripts')

def skip_if_missing():
    if not os.path.isdir(scriptsdir):
        raise unittest.SkipTest('scripts directory could not be found')

def import_tool(toolname):
    with support.DirsOnSysPath(scriptsdir):
        return importlib.import_module(toolname)

def load_tests(loader, standard_tests, pattern):
    this_dir = os.path.dirname(__file__)
    if pattern is None:
        pattern = "test*"
    with support.DirsOnSysPath():
        package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    standard_tests.addTests(package_tests)
    return standard_tests