@@ -72,31 +72,31 @@ def testPGTSStrings(self):
72
72
def testParseAll (self ):
73
73
user_agent_string = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; fr; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5,gzip(gfe),gzip(gfe)'
74
74
expected = {
75
- 'device' : {
76
- 'family' : 'Other' ,
77
- 'brand' : None ,
78
- 'model' : None
79
- },
80
- 'os' : {
81
- 'family' : 'Mac OS X' ,
82
- 'major' : '10' ,
83
- 'minor' : '4' ,
84
- 'patch' : None ,
85
- 'patch_minor' : None
86
- },
87
- 'user_agent' : {
88
- 'family' : 'Firefox' ,
89
- 'major' : '3' ,
90
- 'minor' : '5' ,
91
- 'patch' : '5'
92
- },
93
- 'string' : user_agent_string
75
+ 'device' : {
76
+ 'family' : 'Other' ,
77
+ 'brand' : None ,
78
+ 'model' : None
79
+ },
80
+ 'os' : {
81
+ 'family' : 'Mac OS X' ,
82
+ 'major' : '10' ,
83
+ 'minor' : '4' ,
84
+ 'patch' : None ,
85
+ 'patch_minor' : None
86
+ },
87
+ 'user_agent' : {
88
+ 'family' : 'Firefox' ,
89
+ 'major' : '3' ,
90
+ 'minor' : '5' ,
91
+ 'patch' : '5'
92
+ },
93
+ 'string' : user_agent_string
94
94
}
95
95
96
96
result = user_agent_parser .Parse (user_agent_string )
97
- self .assertEqual (result , expected ,
97
+ self .assertEqual (
98
+ result , expected ,
98
99
"UA: {0}\n expected<{1}> != actual<{2}>" .format (user_agent_string , expected , result ))
99
-
100
100
# Make a YAML file for manual comparsion with pgts_browser_list-orig.yaml
101
101
def makePGTSComparisonYAML (self ):
102
102
import codecs
@@ -146,11 +146,12 @@ def runUserAgentTestsFromYAML(self, file_name):
146
146
147
147
result = {}
148
148
result = user_agent_parser .ParseUserAgent (user_agent_string , ** kwds )
149
- self .assertEqual (result , expected ,
150
- "UA: {0}\n expected<{1}, {2}, {3}, {4}> != actual<{5}, {6}, {7}, {8}>" .format (\
151
- user_agent_string ,
152
- expected ['family' ], expected ['major' ], expected ['minor' ], expected ['patch' ],
153
- result ['family' ], result ['major' ], result ['minor' ], result ['patch' ]))
149
+ self .assertEqual (
150
+ result , expected ,
151
+ "UA: {0}\n expected<{1}, {2}, {3}, {4}> != actual<{5}, {6}, {7}, {8}>" .format (
152
+ user_agent_string ,
153
+ expected ['family' ], expected ['major' ], expected ['minor' ], expected ['patch' ],
154
+ result ['family' ], result ['major' ], result ['minor' ], result ['patch' ]))
154
155
155
156
def runOSTestsFromYAML (self , file_name ):
156
157
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , file_name ))
@@ -166,27 +167,28 @@ def runOSTestsFromYAML(self, file_name):
166
167
167
168
# The expected results
168
169
expected = {
169
- 'family' : test_case ['family' ],
170
- 'major' : test_case ['major' ],
171
- 'minor' : test_case ['minor' ],
172
- 'patch' : test_case ['patch' ],
173
- 'patch_minor' : test_case ['patch_minor' ]
170
+ 'family' : test_case ['family' ],
171
+ 'major' : test_case ['major' ],
172
+ 'minor' : test_case ['minor' ],
173
+ 'patch' : test_case ['patch' ],
174
+ 'patch_minor' : test_case ['patch_minor' ]
174
175
}
175
176
176
177
result = user_agent_parser .ParseOS (user_agent_string , ** kwds )
177
- self .assertEqual (result , expected ,
178
- "UA: {0}\n expected<{1} {2} {3} {4} {5}> != actual<{6} {7} {8} {9} {10}>" .format (\
179
- user_agent_string ,
180
- expected ['family' ],
181
- expected ['major' ],
182
- expected ['minor' ],
183
- expected ['patch' ],
184
- expected ['patch_minor' ],
185
- result ['family' ],
186
- result ['major' ],
187
- result ['minor' ],
188
- result ['patch' ],
189
- result ['patch_minor' ]))
178
+ self .assertEqual (
179
+ result , expected ,
180
+ "UA: {0}\n expected<{1} {2} {3} {4} {5}> != actual<{6} {7} {8} {9} {10}>" .format (
181
+ user_agent_string ,
182
+ expected ['family' ],
183
+ expected ['major' ],
184
+ expected ['minor' ],
185
+ expected ['patch' ],
186
+ expected ['patch_minor' ],
187
+ result ['family' ],
188
+ result ['major' ],
189
+ result ['minor' ],
190
+ result ['patch' ],
191
+ result ['patch_minor' ]))
190
192
191
193
def runDeviceTestsFromYAML (self , file_name ):
192
194
yamlFile = open (os .path .join (TEST_RESOURCES_DIR , file_name ))
@@ -202,13 +204,14 @@ def runDeviceTestsFromYAML(self, file_name):
202
204
203
205
# The expected results
204
206
expected = {
205
- 'family' : test_case ['family' ],
206
- 'brand' : test_case ['brand' ],
207
- 'model' : test_case ['model' ]
207
+ 'family' : test_case ['family' ],
208
+ 'brand' : test_case ['brand' ],
209
+ 'model' : test_case ['model' ]
208
210
}
209
211
210
212
result = user_agent_parser .ParseDevice (user_agent_string , ** kwds )
211
- self .assertEqual (result , expected ,
213
+ self .assertEqual (
214
+ result , expected ,
212
215
"UA: {0}\n expected<{1} {2} {3}> != actual<{4} {5} {6}>" .format (
213
216
user_agent_string ,
214
217
expected ['family' ],
@@ -223,23 +226,25 @@ class GetFiltersTest(unittest.TestCase):
223
226
def testGetFiltersNoMatchesGiveEmptyDict (self ):
224
227
user_agent_string = 'foo'
225
228
filters = user_agent_parser .GetFilters (
226
- user_agent_string , js_user_agent_string = None )
229
+ user_agent_string , js_user_agent_string = None )
227
230
self .assertEqual ({}, filters )
228
231
229
232
def testGetFiltersJsUaPassedThrough (self ):
230
233
user_agent_string = 'foo'
231
234
filters = user_agent_parser .GetFilters (
232
- user_agent_string , js_user_agent_string = 'bar' )
235
+ user_agent_string , js_user_agent_string = 'bar' )
233
236
self .assertEqual ({'js_user_agent_string' : 'bar' }, filters )
234
237
235
238
def testGetFiltersJsUserAgentFamilyAndVersions (self ):
236
- user_agent_string = ('Mozilla/4.0 (compatible; MSIE 8.0; '
237
- 'Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 2.0.50727; '
238
- '.NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)' )
239
+ user_agent_string = (
240
+ 'Mozilla/4.0 (compatible; MSIE 8.0; '
241
+ 'Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 2.0.50727; '
242
+ '.NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)' )
239
243
filters = user_agent_parser .GetFilters (
240
- user_agent_string , js_user_agent_string = 'bar' ,
241
- js_user_agent_family = 'foo' )
242
- self .assertEqual ({'js_user_agent_string' : 'bar' ,
244
+ user_agent_string , js_user_agent_string = 'bar' ,
245
+ js_user_agent_family = 'foo' )
246
+ self .assertEqual ({
247
+ 'js_user_agent_string' : 'bar' ,
243
248
'js_user_agent_family' : 'foo' }, filters )
244
249
245
250
0 commit comments