pyWinAuto: c:\.projects\py_pywinauto\pywinauto\tests\missingextrastring.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021"""Different number of special character sequences Test
0022
0023**What is checked**
0024This test checks to make sure that certain special character sequences
0025appear the in the localised if they appear in the reference title strings.
0026These strings usually mean something to the user but the software internally
0027does not care if they exist or not. The list that is currently checked is:
0028">>", ">", "<<", "<", ":"(colon), "...", "&&", "&", ""
0029
0030**How is it checked**
0031For each of the string to check for we make sure that if it appears in the
0032reference that it also appears in the localised title.
0033
0034**When is a bug reported**
0035 - If the reference has one of the text strings but the localised does
0036 not a bug is reported.
0037 - If the localised has one of the text strings but the reference does
0038 not a bug is reported.
0039
0040Bug Extra Information
0041The bug contains the following extra information
0042
0043**MissingOrExtra** Whether the characters are missing or extra from the
0044controls being check as compared to the reference, (String with
0045following possible values)
0046
0047 - "MissingCharacters" The characters are in the reference but not in
0048 the localised.
0049 - "ExtraCharacters" The characters are not in the reference but are in
0050 the localised.
0051
0052**MissingOrExtraText** What character string is missing or added, String
0053
0054**Is Reference dialog needed**
0055This test will not run if the reference controls are not available.
0056
0057**False positive bug reports**
0058Currently this test is at a beta stage filtering of the results is probably
0059necessary at the moment.
0060
0061**Test Identifier**
0062The identifier for this test/bug is "MissingExtraString"
0063"""
0064
0065__revision__ = "$Revision: 286 $"
0066
0067
0068
0069testname = "MissingExtraString"
0070
0071CharsToCheck = (
0072 ">",
0073 ">>",
0074 "<",
0075 "<<",
0076 "&",
0077 "&&",
0078 "...",
0079 ":",
0080 "@",
0081
0082)
0083
0084
0085def MissingExtraStringTest(windows):
0086 "Return the errors from running the test"
0087 bugs = []
0088 for win in windows:
0089 if not win.ref:
0090 continue
0091
0092 for char in CharsToCheck:
0093 missing_extra = ''
0094
0095 if win.WindowText().count(char) > win.ref.WindowText().count(char):
0096 missing_extra = "ExtraCharacters"
0097 elif win.WindowText().count(char) < win.ref.WindowText().count(char):
0098 missing_extra = "MissingCharacters"
0099
0100 if missing_extra:
0101 bugs.append((
0102 [win,],
0103 {
0104 "MissingOrExtra": missing_extra,
0105 "MissingOrExtraText": char
0106 },
0107 testname,
0108 0))
0109
0110 return bugs
0111
0112
0113MissingExtraStringTest.TestsMenus = True
0114
0115def _unittests():
0116 "Run the unit tests for this test"
0117
0118
0119
0120 test_strings = (
0121 ("Nospecial", "NietherHere", 0),
0122
0123 ("Nob>ug", "Niet>herHere", 0),
0124 ("No>>bug", ">>NietherHere", 0),
0125 ("<Nobug", "NietherHere<", 0),
0126 ("Nobug<<", "NietherHere<<", 0),
0127 ("No&bu&g", "&NietherHere&", 0),
0128 ("No&&bug", "NietherHere&&", 0),
0129 ("Nobug...", "Nieth...erHere", 0),
0130 ("Nobug:", ":NietherHere", 0),
0131 ("No@bug", "Ni@etherHere", 0),
0132 (">Th&&>>is &str<<ing >>has ju<st about @everything :but ...no bug",
0133 "This s&tr...in<<g has jus<t abou&&t every>th:ing >>but no @bug",
0134 0),
0135
0136 ("GreaterAdded >", "No Greater", 1),
0137 ("GreaterMissing", "Greater > here", 1),
0138
0139 ("doubleGreater added >>", "No double greater", 1),
0140 ("doubleGreater added >>", "No double greater >", 1),
0141 ("doubleGreater Missing >", "No double greater >>", 1),
0142 )
0143
0144 class Control(object):
0145 def Text(self):
0146 return self.text
0147 pass
0148
0149 ctrls = []
0150 total_bug_count = 0
0151 for loc, ref, num_bugs in test_strings:
0152 ctrl = Control()
0153 ctrl.text = loc
0154 ctrl.ref = Control()
0155 ctrl.ref.text = ref
0156
0157 total_bug_count += num_bugs
0158 num_found = len(MissingExtraStringTest([ctrl]))
0159 try:
0160 assert num_found == num_bugs
0161 except:
0162 print num_found, num_bugs, loc, ref
0163
0164
0165 ctrls.append(ctrl)
0166
0167 assert len(MissingExtraStringTest(ctrls)) == total_bug_count
0168
0169
0170
0171if __name__ == "__main__":
0172 _unittests()