5
To run tests against installed code rather than files extracted from package,
6
use the -i command line option.
8
For further help, enter this at a command prompt:
14
# Modules containing tests to run -- a test is anything named *Tests, which
15
# should be classes deriving from unittest.TestCase.
16
MODULE_NAMES = ["test_misc", "test_date", "test_headers", "test_cookies",
19
import sys, os, traceback
20
from unittest import TestCase
28
#ClientCookie.CLIENTCOOKIE_DEBUG = True
29
#level = ClientCookie.DEBUG
30
#level = ClientCookie.INFO
31
#level = ClientCookie.NOTSET
32
#ClientCookie.getLogger("ClientCookie").setLevel(level)
34
RUN_AGAINST_INSTALLED = False
36
def import_tests(module_names):
37
"""Import everything named *Tests from named modules.
39
This is so unittest.main() will run test cases in other modules.
43
from ClientCookie._Util import endswith
46
if RUN_AGAINST_INSTALLED:
47
sys.exit("Perhaps ClientCookie isn't installed properly?")
49
sys.exit("Perhaps the locally extracted source files aren't in "
53
for module_name in module_names:
55
__import__(module_name)
58
sys.exit("Import of test module failed -- Couldn't find tests?")
59
module = sys.modules[module_name]
60
candidates = dir(module)
61
for name in candidates:
62
if endswith(name, "Tests"):
63
test_class = getattr(module, name)
67
if __name__ == "__main__":
69
test_path = os.path.join(os.path.dirname(sys.argv[0]), "test")
71
i = sys.argv.index("-i")
73
RUN_AGAINST_INSTALLED = False
74
sys.path.insert(0, test_path)
77
RUN_AGAINST_INSTALLED = True
78
sys.path[0] = test_path
79
import_tests(MODULE_NAMES)