pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\__init__.py

0001# GUI Application automation and testing library
0002# Copyright (C) 2006 Mark Mc Mahon
0003#
0004# This library is free software; you can redistribute it and/or
0005# modify it under the terms of the GNU Lesser General Public License
0006# as published by the Free Software Foundation; either version 2.1
0007# of the License, or (at your option) any later version.
0008#
0009# This library is distributed in the hope that it will be useful,
0010# but WITHOUT ANY WARRANTY; without even the implied warranty of
0011# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0012# See the GNU Lesser General Public License for more details.
0013#
0014# You should have received a copy of the GNU Lesser General Public
0015# License along with this library; if not, write to the
0016#    Free Software Foundation, Inc.,
0017#    59 Temple Place,
0018#    Suite 330,
0019#    Boston, MA 02111-1307 USA
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    # allow either a string or list to be passed
0030    try:
0031        tests_to_run = tests_to_run.split()
0032    except AttributeError:
0033        pass
0034
0035    # if no tests specified run them all
0036    if tests_to_run is None:
0037        tests_to_run = _registered.keys()
0038
0039    # Filter out hidden controls if requested
0040    if test_visible_only:
0041        controls = [ctrl for ctrl in controls if ctrl.IsVisible()]
0042
0043    bugs = []
0044    # run each test
0045    for test_name in tests_to_run:
0046        #print test_name
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                #print e
0076                pass
0077
0078        print
0079
0080
0081# we need to register the modules
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        #   "menux",
0101    )
0102
0103    for test_name in standard_test_names:
0104
0105        test_module = __import__(test_name.lower(), globals(), locals())
0106
0107        # class name is the test name + "Test"
0108        test_class = getattr(test_module, test_name + "Test")
0109
0110        _registered[test_name] = test_class
0111
0112    # allow extension of the tests available through a separate file
0113    try:
0114        import extra_tests
0115        extra_tests.ModifyRegisteredTests(_registered)
0116    except ImportError:
0117        pass
0118
0119
0120if not _registered:
0121    __init_tests()