Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1016)

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 28 matching lines...) Expand all
39 return all_test_configurations 39 return all_test_configurations
40 40
41 MOCK_MACROS = { 41 MOCK_MACROS = {
42 'mac': ['snowleopard'], 42 'mac': ['snowleopard'],
43 'win': ['xp', 'vista', 'win7'], 43 'win': ['xp', 'vista', 'win7'],
44 'linux': ['lucid'], 44 'linux': ['lucid'],
45 } 45 }
46 46
47 47
48 class TestConfigurationTest(unittest.TestCase): 48 class TestConfigurationTest(unittest.TestCase):
49
49 def test_items(self): 50 def test_items(self):
50 config = TestConfiguration('xp', 'x86', 'release') 51 config = TestConfiguration('xp', 'x86', 'release')
51 result_config_dict = {} 52 result_config_dict = {}
52 for category, specifier in config.items(): 53 for category, specifier in config.items():
53 result_config_dict[category] = specifier 54 result_config_dict[category] = specifier
54 self.assertEqual({'version': 'xp', 'architecture': 'x86', 'build_type': 'release'}, result_config_dict) 55 self.assertEqual({'version': 'xp', 'architecture': 'x86', 'build_type': 'release'}, result_config_dict)
55 56
56 def test_keys(self): 57 def test_keys(self):
57 config = TestConfiguration('xp', 'x86', 'release') 58 config = TestConfiguration('xp', 'x86', 'release')
58 result_config_keys = [] 59 result_config_keys = []
(...skipping 14 matching lines...) Expand all
73 config_dict[TestConfiguration('xp', 'x86', 'release')] = True 74 config_dict[TestConfiguration('xp', 'x86', 'release')] = True
74 self.assertIn(TestConfiguration('xp', 'x86', 'release'), config_dict) 75 self.assertIn(TestConfiguration('xp', 'x86', 'release'), config_dict)
75 self.assertTrue(config_dict[TestConfiguration('xp', 'x86', 'release')]) 76 self.assertTrue(config_dict[TestConfiguration('xp', 'x86', 'release')])
76 77
77 def query_unknown_key(): 78 def query_unknown_key():
78 return config_dict[TestConfiguration('xp', 'x86', 'debug')] 79 return config_dict[TestConfiguration('xp', 'x86', 'debug')]
79 80
80 self.assertRaises(KeyError, query_unknown_key) 81 self.assertRaises(KeyError, query_unknown_key)
81 self.assertIn(TestConfiguration('xp', 'x86', 'release'), config_dict) 82 self.assertIn(TestConfiguration('xp', 'x86', 'release'), config_dict)
82 self.assertNotIn(TestConfiguration('xp', 'x86', 'debug'), config_dict) 83 self.assertNotIn(TestConfiguration('xp', 'x86', 'debug'), config_dict)
83 configs_list = [TestConfiguration('xp', 'x86', 'release'), TestConfigura tion('xp', 'x86', 'debug'), TestConfiguration('xp', 'x86', 'debug')] 84 configs_list = [
85 TestConfiguration(
86 'xp', 'x86', 'release'), TestConfiguration(
87 'xp', 'x86', 'debug'), TestConfiguration(
88 'xp', 'x86', 'debug')]
84 self.assertEqual(len(configs_list), 3) 89 self.assertEqual(len(configs_list), 3)
85 self.assertEqual(len(set(configs_list)), 2) 90 self.assertEqual(len(set(configs_list)), 2)
86 91
87 def test_eq(self): 92 def test_eq(self):
88 self.assertEqual(TestConfiguration('xp', 'x86', 'release'), TestConfigur ation('xp', 'x86', 'release')) 93 self.assertEqual(TestConfiguration('xp', 'x86', 'release'), TestConfigur ation('xp', 'x86', 'release'))
89 self.assertNotEquals(TestConfiguration('xp', 'x86', 'release'), TestConf iguration('xp', 'x86', 'debug')) 94 self.assertNotEquals(TestConfiguration('xp', 'x86', 'release'), TestConf iguration('xp', 'x86', 'debug'))
90 95
91 def test_values(self): 96 def test_values(self):
92 config = TestConfiguration('xp', 'x86', 'release') 97 config = TestConfiguration('xp', 'x86', 'release')
93 result_config_values = [] 98 result_config_values = []
94 for value in config.values(): 99 for value in config.values():
95 result_config_values.append(value) 100 result_config_values.append(value)
96 self.assertEqual(set(['xp', 'x86', 'release']), set(result_config_values )) 101 self.assertEqual(set(['xp', 'x86', 'release']), set(result_config_values ))
97 102
98 103
99 class SpecifierSorterTest(unittest.TestCase): 104 class SpecifierSorterTest(unittest.TestCase):
105
100 def __init__(self, testFunc): 106 def __init__(self, testFunc):
101 self._all_test_configurations = make_mock_all_test_configurations_set() 107 self._all_test_configurations = make_mock_all_test_configurations_set()
102 unittest.TestCase.__init__(self, testFunc) 108 unittest.TestCase.__init__(self, testFunc)
103 109
104 def test_init(self): 110 def test_init(self):
105 sorter = SpecifierSorter() 111 sorter = SpecifierSorter()
106 self.assertIsNone(sorter.category_for_specifier('control')) 112 self.assertIsNone(sorter.category_for_specifier('control'))
107 sorter = SpecifierSorter(self._all_test_configurations) 113 sorter = SpecifierSorter(self._all_test_configurations)
108 self.assertEqual(sorter.category_for_specifier('xp'), 'version') 114 self.assertEqual(sorter.category_for_specifier('xp'), 'version')
109 sorter = SpecifierSorter(self._all_test_configurations, MOCK_MACROS) 115 sorter = SpecifierSorter(self._all_test_configurations, MOCK_MACROS)
(...skipping 26 matching lines...) Expand all
136 sorter = SpecifierSorter(self._all_test_configurations) 142 sorter = SpecifierSorter(self._all_test_configurations)
137 self.assertEqual(sorter.specifier_priority('x86'), 1) 143 self.assertEqual(sorter.specifier_priority('x86'), 1)
138 self.assertEqual(sorter.specifier_priority('snowleopard'), 0) 144 self.assertEqual(sorter.specifier_priority('snowleopard'), 0)
139 145
140 def test_sort_specifiers(self): 146 def test_sort_specifiers(self):
141 sorter = SpecifierSorter(self._all_test_configurations, MOCK_MACROS) 147 sorter = SpecifierSorter(self._all_test_configurations, MOCK_MACROS)
142 self.assertEqual(sorter.sort_specifiers(set()), []) 148 self.assertEqual(sorter.sort_specifiers(set()), [])
143 self.assertEqual(sorter.sort_specifiers(set(['x86'])), ['x86']) 149 self.assertEqual(sorter.sort_specifiers(set(['x86'])), ['x86'])
144 self.assertEqual(sorter.sort_specifiers(set(['x86', 'win7'])), ['win7', 'x86']) 150 self.assertEqual(sorter.sort_specifiers(set(['x86', 'win7'])), ['win7', 'x86'])
145 self.assertEqual(sorter.sort_specifiers(set(['x86', 'debug', 'win7'])), ['win7', 'x86', 'debug']) 151 self.assertEqual(sorter.sort_specifiers(set(['x86', 'debug', 'win7'])), ['win7', 'x86', 'debug'])
146 self.assertEqual(sorter.sort_specifiers(set(['snowleopard', 'x86', 'debu g', 'win7'])), ['snowleopard', 'win7', 'x86', 'debug']) 152 self.assertEqual(sorter.sort_specifiers(set(['snowleopard', 'x86', 'debu g', 'win7'])), [
153 'snowleopard', 'win7', 'x86', 'debug'])
147 self.assertEqual(sorter.sort_specifiers(set(['x86', 'mac', 'debug', 'win 7'])), ['mac', 'win7', 'x86', 'debug']) 154 self.assertEqual(sorter.sort_specifiers(set(['x86', 'mac', 'debug', 'win 7'])), ['mac', 'win7', 'x86', 'debug'])
148 155
149 156
150 class TestConfigurationConverterTest(unittest.TestCase): 157 class TestConfigurationConverterTest(unittest.TestCase):
158
151 def __init__(self, testFunc): 159 def __init__(self, testFunc):
152 self._all_test_configurations = make_mock_all_test_configurations_set() 160 self._all_test_configurations = make_mock_all_test_configurations_set()
153 unittest.TestCase.__init__(self, testFunc) 161 unittest.TestCase.__init__(self, testFunc)
154 162
155 def test_symmetric_difference(self): 163 def test_symmetric_difference(self):
156 self.assertEqual(TestConfigurationConverter.symmetric_difference([set([' a', 'b']), set(['b', 'c'])]), set(['a', 'c'])) 164 self.assertEqual(TestConfigurationConverter.symmetric_difference([set([' a', 'b']), set(['b', 'c'])]), set(['a', 'c']))
157 self.assertEqual(TestConfigurationConverter.symmetric_difference([set([' a', 'b']), set(['b', 'c']), set(['b', 'd'])]), set(['a', 'c', 'd'])) 165 self.assertEqual(TestConfigurationConverter.symmetric_difference(
166 [set(['a', 'b']), set(['b', 'c']), set(['b', 'd'])]), set(['a', 'c', 'd']))
158 167
159 def test_to_config_set(self): 168 def test_to_config_set(self):
160 converter = TestConfigurationConverter(self._all_test_configurations) 169 converter = TestConfigurationConverter(self._all_test_configurations)
161 170
162 self.assertEqual(converter.to_config_set(set()), self._all_test_configur ations) 171 self.assertEqual(converter.to_config_set(set()), self._all_test_configur ations)
163 172
164 self.assertEqual(converter.to_config_set(set(['foo'])), set()) 173 self.assertEqual(converter.to_config_set(set(['foo'])), set())
165 174
166 self.assertEqual(converter.to_config_set(set(['xp', 'foo'])), set()) 175 self.assertEqual(converter.to_config_set(set(['xp', 'foo'])), set())
167 176
168 errors = [] 177 errors = []
169 self.assertEqual(converter.to_config_set(set(['xp', 'foo']), errors), se t()) 178 self.assertEqual(converter.to_config_set(set(['xp', 'foo']), errors), se t())
170 self.assertEqual(errors, ["Unrecognized specifier 'foo'"]) 179 self.assertEqual(errors, ["Unrecognized specifier 'foo'"])
171 180
172 self.assertEqual(converter.to_config_set(set(['xp', 'x86_64'])), set()) 181 self.assertEqual(converter.to_config_set(set(['xp', 'x86_64'])), set())
173 182
174 configs_to_match = set([ 183 configs_to_match = set([
175 TestConfiguration('xp', 'x86', 'release'), 184 TestConfiguration('xp', 'x86', 'release'),
176 ]) 185 ])
177 self.assertEqual(converter.to_config_set(set(['xp', 'release'])), config s_to_match) 186 self.assertEqual(converter.to_config_set(set(['xp', 'release'])), config s_to_match)
178 187
179 configs_to_match = set([ 188 configs_to_match = set([
180 TestConfiguration('snowleopard', 'x86', 'release'), 189 TestConfiguration('snowleopard', 'x86', 'release'),
181 TestConfiguration('vista', 'x86', 'release'), 190 TestConfiguration('vista', 'x86', 'release'),
182 TestConfiguration('win7', 'x86', 'release'), 191 TestConfiguration('win7', 'x86', 'release'),
183 TestConfiguration('xp', 'x86', 'release'), 192 TestConfiguration('xp', 'x86', 'release'),
184 TestConfiguration('lucid', 'x86', 'release'), 193 TestConfiguration('lucid', 'x86', 'release'),
185 TestConfiguration('lucid', 'x86_64', 'release'), 194 TestConfiguration('lucid', 'x86_64', 'release'),
186 ]) 195 ])
187 self.assertEqual(converter.to_config_set(set(['release'])), configs_to_m atch) 196 self.assertEqual(converter.to_config_set(set(['release'])), configs_to_m atch)
188 197
189 configs_to_match = set([ 198 configs_to_match = set([
190 TestConfiguration('lucid', 'x86_64', 'release'), 199 TestConfiguration('lucid', 'x86_64', 'release'),
191 TestConfiguration('lucid', 'x86_64', 'debug'), 200 TestConfiguration('lucid', 'x86_64', 'debug'),
192 ]) 201 ])
193 self.assertEqual(converter.to_config_set(set(['x86_64'])), configs_to_ma tch) 202 self.assertEqual(converter.to_config_set(set(['x86_64'])), configs_to_ma tch)
194 203
195 configs_to_match = set([ 204 configs_to_match = set([
196 TestConfiguration('lucid', 'x86_64', 'release'), 205 TestConfiguration('lucid', 'x86_64', 'release'),
197 TestConfiguration('lucid', 'x86_64', 'debug'), 206 TestConfiguration('lucid', 'x86_64', 'debug'),
198 TestConfiguration('lucid', 'x86', 'release'), 207 TestConfiguration('lucid', 'x86', 'release'),
199 TestConfiguration('lucid', 'x86', 'debug'), 208 TestConfiguration('lucid', 'x86', 'debug'),
200 TestConfiguration('snowleopard', 'x86', 'release'), 209 TestConfiguration('snowleopard', 'x86', 'release'),
201 TestConfiguration('snowleopard', 'x86', 'debug'), 210 TestConfiguration('snowleopard', 'x86', 'debug'),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 configs_to_match = set([ 267 configs_to_match = set([
259 TestConfiguration('xp', 'x86', 'release'), 268 TestConfiguration('xp', 'x86', 'release'),
260 TestConfiguration('xp', 'x86', 'debug'), 269 TestConfiguration('xp', 'x86', 'debug'),
261 ]) 270 ])
262 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' xp'])]) 271 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' xp'])])
263 272
264 configs_to_match = set([ 273 configs_to_match = set([
265 TestConfiguration('lucid', 'x86_64', 'debug'), 274 TestConfiguration('lucid', 'x86_64', 'debug'),
266 TestConfiguration('xp', 'x86', 'release'), 275 TestConfiguration('xp', 'x86', 'release'),
267 ]) 276 ])
268 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' release', 'xp']), set(['debug', 'x86_64', 'linux'])]) 277 self.assertEqual(converter.to_specifiers_list(
278 configs_to_match), [set(['release', 'xp']), set(['debug', 'x86_64', 'linux'])])
269 279
270 configs_to_match = set([ 280 configs_to_match = set([
271 TestConfiguration('xp', 'x86', 'release'), 281 TestConfiguration('xp', 'x86', 'release'),
272 TestConfiguration('xp', 'x86', 'release'), 282 TestConfiguration('xp', 'x86', 'release'),
273 TestConfiguration('lucid', 'x86_64', 'debug'), 283 TestConfiguration('lucid', 'x86_64', 'debug'),
274 TestConfiguration('lucid', 'x86', 'debug'), 284 TestConfiguration('lucid', 'x86', 'debug'),
275 TestConfiguration('lucid', 'x86_64', 'debug'), 285 TestConfiguration('lucid', 'x86_64', 'debug'),
276 TestConfiguration('lucid', 'x86', 'debug'), 286 TestConfiguration('lucid', 'x86', 'debug'),
277 ]) 287 ])
278 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' release', 'xp']), set(['debug', 'linux'])]) 288 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' release', 'xp']), set(['debug', 'linux'])])
(...skipping 14 matching lines...) Expand all
293 ]) 303 ])
294 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' xp', 'mac', 'release'])]) 304 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' xp', 'mac', 'release'])])
295 305
296 configs_to_match = set([ 306 configs_to_match = set([
297 TestConfiguration('xp', 'x86', 'release'), 307 TestConfiguration('xp', 'x86', 'release'),
298 TestConfiguration('snowleopard', 'x86', 'release'), 308 TestConfiguration('snowleopard', 'x86', 'release'),
299 TestConfiguration('win7', 'x86', 'release'), 309 TestConfiguration('win7', 'x86', 'release'),
300 TestConfiguration('win7', 'x86', 'debug'), 310 TestConfiguration('win7', 'x86', 'debug'),
301 TestConfiguration('lucid', 'x86', 'release'), 311 TestConfiguration('lucid', 'x86', 'release'),
302 ]) 312 ])
303 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' win7']), set(['release', 'linux', 'x86']), set(['release', 'xp', 'mac'])]) 313 self.assertEqual(converter.to_specifiers_list(configs_to_match), [
314 set(['win7']), set(['release', 'linux', 'x86']), set([' release', 'xp', 'mac'])])
304 315
305 def test_macro_collapsing(self): 316 def test_macro_collapsing(self):
306 macros = {'foo': ['bar', 'baz'], 'people': ['bob', 'alice', 'john']} 317 macros = {'foo': ['bar', 'baz'], 'people': ['bob', 'alice', 'john']}
307 318
308 specifiers_list = [set(['john', 'godzilla', 'bob', 'alice'])] 319 specifiers_list = [set(['john', 'godzilla', 'bob', 'alice'])]
309 TestConfigurationConverter.collapse_macros(macros, specifiers_list) 320 TestConfigurationConverter.collapse_macros(macros, specifiers_list)
310 self.assertEqual(specifiers_list, [set(['people', 'godzilla'])]) 321 self.assertEqual(specifiers_list, [set(['people', 'godzilla'])])
311 322
312 specifiers_list = [set(['john', 'godzilla', 'alice'])] 323 specifiers_list = [set(['john', 'godzilla', 'alice'])]
313 TestConfigurationConverter.collapse_macros(macros, specifiers_list) 324 TestConfigurationConverter.collapse_macros(macros, specifiers_list)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 TestConfiguration('xp', 'x86', 'release'), 371 TestConfiguration('xp', 'x86', 'release'),
361 TestConfiguration('vista', 'x86', 'release'), 372 TestConfiguration('vista', 'x86', 'release'),
362 TestConfiguration('win7', 'x86', 'release'), 373 TestConfiguration('win7', 'x86', 'release'),
363 ]) 374 ])
364 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' win', 'release'])]) 375 self.assertEqual(converter.to_specifiers_list(configs_to_match), [set([' win', 'release'])])
365 376
366 def test_specifier_converter_access(self): 377 def test_specifier_converter_access(self):
367 specifier_sorter = TestConfigurationConverter(self._all_test_configurati ons, MOCK_MACROS).specifier_sorter() 378 specifier_sorter = TestConfigurationConverter(self._all_test_configurati ons, MOCK_MACROS).specifier_sorter()
368 self.assertEqual(specifier_sorter.category_for_specifier('snowleopard'), 'version') 379 self.assertEqual(specifier_sorter.category_for_specifier('snowleopard'), 'version')
369 self.assertEqual(specifier_sorter.category_for_specifier('mac'), 'versio n') 380 self.assertEqual(specifier_sorter.category_for_specifier('mac'), 'versio n')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698