pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\missalignment.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021"""Missalignment Test
0022
0023**What is checked**
0024This test checks that if a set of controls were aligned on a particular axis
0025in the reference dialog that they are all aligned on the same axis.
0026
0027**How is it checked**
0028A list of all the reference controls that are aligned is created (ie more than
0029one control with the same Top, Left, Bottom or Right coordinates). These
0030controls are then analysed in the localised dialog to make sure that they are
0031all aligned on the same axis.
0032
0033**When is a bug reported**
0034A bug is reported when any of the controls that were aligned in the reference
0035dialog are no longer aligned in the localised control.
0036
0037**Bug Extra Information**
0038The bug contains the following extra information
0039Name Description
0040AlignmentType This is either LEFT, TOP, RIGHT or BOTTOM. It tells you how
0041the controls were aligned in the reference dialog. String
0042AlignmentRect Gives the smallest rectangle that surrounds ALL the controls
0043concerned in the bug, Rectangle
0044
0045**Is Reference dialog needed**
0046This test cannot be performed without the reference control. It is required
0047to see which controls should be aligned.
0048
0049**False positive bug reports**
0050It is quite possible that this test reports false positives:
00511. Where the controls only just happen to be aligned in the reference dialog
0052(by coincidence)
00532. Where the control does not have a clear boundary (for example static
0054labels or checkboxes) they may be miss-aligned but it is not noticeable that
0055they are not.
0056
0057
0058**Test Identifier**
0059The identifier for this test/bug is "Missalignment" """
0060
0061__revision__ = "$Revision: 221 $"
0062
0063testname = "Missalignment"
0064
0065from pywinauto.win32structures import RECT
0066
0067
0068def MissalignmentTest(windows):
0069 "Run the test on the windows passed in"
0070 refAlignments = {}
0071
0072
0073 for win in windows:
0074 if not win.ref:
0075 continue
0076
0077
0078 for side in ("top", "left", "right", "bottom"):
0079 sideValue = getattr(win.ref.Rectangle(), side)
0080
0081
0082 sideAlignments = refAlignments.setdefault(side, {})
0083
0084
0085
0086 sideAlignments.setdefault(sideValue, []).append(win)
0087
0088 bugs = []
0089 for side in refAlignments:
0090 for alignment in refAlignments[side]:
0091 controls = refAlignments[side][alignment]
0092 sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]
0093 sides = set(sides)
0094
0095 if len(sides) > 1:
0096
0097 overAllRect = RECT()
0098 overAllRect.left = min(
0099 [ctrl.Rectangle().left for ctrl in controls])
0100 overAllRect.top = min(
0101 [ctrl.Rectangle().top for ctrl in controls])
0102 overAllRect.right = max(
0103 [ctrl.Rectangle().right for ctrl in controls])
0104 overAllRect.bottom = max(
0105 [ctrl.Rectangle().bottom for ctrl in controls])
0106
0107
0108 bugs.append((
0109 controls,
0110 {
0111 "AlignmentType": side.upper(),
0112 "AlignmentRect": overAllRect
0113 },
0114 testname,
0115 0)
0116 )
0117
0118 return bugs