pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\asianhotkey.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021"""Asian Hotkey Format Test
0022
0023**What is checked**
0024
0025This test checks whether the format for shortcuts/hotkeys follows the
0026standards for localised Windows applications. This format is
0027{localised text}({uppercase hotkey})
0028so for example if the English control is
0029"&Help"
0030the localised control for Asian languages should be
0031"LocHelp(H)"
0032
0033**How is it checked**
0034
0035After checking whether this control displays hotkeys it examines the 1st
0036string of the control to make sure that the format is correct.
0037If the reference control is available then it also makes sure that the
0038hotkey character is the same as the reference.
0039Controls with a title of less than 4 characters are ignored. This has been
0040done to avoid false positive bug reports for strings like "&X:".
0041
0042**When is a bug reported**
0043
0044A bug is reported when a control has a hotkey and it is not in the correct
0045format.
0046Also if the reference control is available a bug will be reported if the
0047hotkey character is not the same as used in the reference
0048
0049**Bug Extra Information**
0050
0051This test produces 2 different types of bug:
0052BugType: "AsianHotkeyFormat"
0053There is no extra information associated with this bug type
0054
0055**BugType: "AsianHotkeyDiffRef"**
0056
0057There is no extra information associated with this bug type
0058
0059**Is Reference dialog needed**
0060
0061The reference dialog is not needed.
0062If it is unavailable then only bugs of type "AsianHotkeyFormat" will be
0063reported, bug of type "AsianHotkeyDiffRef" will not be found.
0064
0065**False positive bug reports**
0066
0067There should be very few false positive bug reports when testing Asian
0068software. If a string is very short (eg "&Y:") but is padded with spaces
0069then it will get reported.
0070
0071**Test Identifier**
0072
0073The identifier for this test/bug is "AsianHotkeyTests"
0074"""
0075
0076__revision__ = "$Revision: 286 $"
0077
0078
0079testname = "AsianHotkeyFormat"
0080
0081
0082import re
0083
0084from repeatedhotkey import ImplementsHotkey, GetHotkey
0085
0086
0087
0088def AsianHotkeyTest(windows):
0089 "Return the repeated hotkey errors"
0090
0091 bugs = []
0092
0093 for win in windows:
0094
0095 if not ImplementsHotkey(win):
0096 continue
0097
0098 if _IsAsianHotkeyFormatIncorrect(win.WindowText()):
0099
0100 bugs.append((
0101 [win,],
0102 {},
0103 testname,
0104 0)
0105 )
0106
0107 return bugs
0108
0109
0110_asianHotkeyRE = re.compile (r"""
0111 \(&.\) # the hotkey
0112 (
0113 (\t.*)| # tab, and then anything
0114 #(\\t.*)| # escaped tab, and then anything
0115 (\(.*\) # anything in brackets
0116 )|
0117 \s*| # any whitespace
0118 :| # colon
0119 (\.\.\.)| # elipsis
0120 >| # greater than sign
0121 <| # less than sign
0122 (\n.*) # newline, and then anything
0123 \s)*$""", re.VERBOSE)
0124
0125
0126def _IsAsianHotkeyFormatIncorrect(text):
0127 "Check if the format of the hotkey is correct or not"
0128
0129 pos, char = GetHotkey(text)
0130
0131
0132 if char:
0133 found = _asianHotkeyRE.search(text)
0134 if not found:
0135 return True
0136
0137
0138 return False
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155AsianHotkeyTest.TestsMenus = True