pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\leadtrailspaces.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"""Different Leading and Trailing Spaces Test
0022
0023**What is checked**
0024Checks that the same space characters (<space>, <tab>, <enter>, <vertical tab>)
0025are before and after all non space characters in the title of the control when
0026compared to the reference control.
0027
0028**How is it checked**
0029Find the 1st non-space character, and the characters of the title up to that
0030are the leading spaces.
0031Find the last non-space character, and the characters of the title after that
0032are the trailing spaces.
0033These are then compared to the lead and trail spaces from the reference
0034control and if they are not exactly the then a bug is reported.
0035
0036**When is a bug reported**
0037When either the leading or trailing spaces of the control being tested does
0038not match the equivalent spaces of the reference control exactly.
0039
0040**Bug Extra Information**
0041The bug contains the following extra information
0042
0043  * **Lead-Trail**  Whether this bug report is for the leading or
0044    trailing spaces of the control, String
0045
0046    This will be either:
0047
0048      - "Leading"  bug relating to leading spaces
0049      - "Trailing"  bug relating to trailing spaces
0050
0051  * **Ref**  The leading or trailings spaces of the reference string
0052    (depending on Lead-Trail value), String
0053  * **Loc**  The leading or trailings spaces of the local string (depending on
0054    Lead-Trail value), String
0055
0056**Is Reference dialog needed**
0057This test will not run if the reference controls are not available.
0058
0059**False positive bug reports**
0060This is usually not a very important test, so if it generates many false
0061positives then we should consider removing it.
0062
0063**Test Identifier**
0064The identifier for this test/bug is "LeadTrailSpaces"
0065"""
0066__revision__ = "$Revision: 412 $"
0067
0068
0069testname = "LeadTrailSpaces"
0070def LeadTrailSpacesTest(windows):
0071    "Return the leading/trailing space bugs for the windows"
0072    bugs = []
0073    for win in windows:
0074        if not win.ref:
0075            continue
0076
0077        locLeadSpaces = GetLeadSpaces(win.WindowText())
0078        locTrailSpaces = GetTrailSpaces(win.WindowText())
0079
0080        refLeadSpaces = GetLeadSpaces(win.ref.WindowText())
0081        refTrailSpaces = GetTrailSpaces(win.ref.WindowText())
0082
0083        diffs = []
0084        if locLeadSpaces != refLeadSpaces:
0085            diffs.append(("Leading", locLeadSpaces, locTrailSpaces))
0086
0087        if locTrailSpaces != refTrailSpaces:
0088            diffs.append(("Trailing", locTrailSpaces, refTrailSpaces))
0089
0090        for diff, loc, ref in diffs:
0091            bugs.append((
0092                [win, ],
0093                {
0094                    "Lead-Trail": diff,
0095                    "Ref": ref,
0096                    "Loc": loc,
0097                },
0098                testname,
0099                0,)
0100            )
0101    return bugs
0102
0103
0104def GetLeadSpaces(title):
0105    "Return the leading spaces of the string"
0106    spaces = ''
0107
0108    for i in range(0, len(title)):
0109        if not title[i].isspace():
0110            break
0111
0112        spaces += title[i]
0113
0114    return spaces
0115
0116
0117def GetTrailSpaces(title):
0118    "Return the trailing spaces of the string"
0119    rev = "".join(reversed(title))
0120    spaces = GetLeadSpaces(rev)
0121    return "".join(reversed(spaces))
0122
0123
0124LeadTrailSpacesTest.TestsMenus = True