pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\__init__.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021"Package of tests that can be run on controls or lists of controls"
0022
0023__revision__ = "$Revision: 434 $"
0024
0025
0026def run_tests(controls, tests_to_run = None, test_visible_only = True):
0027 "Run the tests"
0028
0029
0030 try:
0031 tests_to_run = tests_to_run.split()
0032 except AttributeError:
0033 pass
0034
0035
0036 if tests_to_run is None:
0037 tests_to_run = _registered.keys()
0038
0039
0040 if test_visible_only:
0041 controls = [ctrl for ctrl in controls if ctrl.IsVisible()]
0042
0043 bugs = []
0044
0045 for test_name in tests_to_run:
0046
0047 bugs.extend(_registered[test_name](controls))
0048
0049 return bugs
0050
0051
0052def print_bugs(bugs):
0053 "Print the bugs"
0054 for (ctrls, info, bug_type, is_in_ref) in bugs:
0055 print "BugType:", bug_type, is_in_ref,
0056
0057 for i in info:
0058 print i, info[i],
0059 print
0060
0061
0062 for i, ctrl in enumerate(ctrls):
0063 print '\t"%s" "%s" (%d %d %d %d) Vis: %d'% (
0064 ctrl.WindowText(),
0065 ctrl.FriendlyClassName(),
0066 ctrl.Rectangle().left,
0067 ctrl.Rectangle().top,
0068 ctrl.Rectangle().right,
0069 ctrl.Rectangle().bottom,
0070 ctrl.IsVisible(),)
0071
0072 try:
0073 ctrl.DrawOutline()
0074 except (AttributeError, KeyError):
0075
0076 pass
0077
0078 print
0079
0080
0081
0082_registered = {}
0083def __init_tests():
0084 "Initialize each test by loading it and then register it"
0085 global _registered
0086
0087 standard_test_names = (
0088 "AllControls",
0089 "AsianHotkey",
0090 "ComboBoxDroppedHeight",
0091 "CompareToRefFont",
0092 "LeadTrailSpaces",
0093 "MiscValues",
0094 "Missalignment",
0095 "MissingExtraString",
0096 "Overlapping",
0097 "RepeatedHotkey",
0098 "Translation",
0099 "Truncation",
0100
0101 )
0102
0103 for test_name in standard_test_names:
0104
0105 test_module = __import__(test_name.lower(), globals(), locals())
0106
0107
0108 test_class = getattr(test_module, test_name + "Test")
0109
0110 _registered[test_name] = test_class
0111
0112
0113 try:
0114 import extra_tests
0115 extra_tests.ModifyRegisteredTests(_registered)
0116 except ImportError:
0117 pass
0118
0119
0120if not _registered:
0121 __init_tests()