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

Side by Side Diff: tools/telemetry/telemetry/internal/story_runner_unittest.py

Issue 1126443002: Move user_story.user_story_set to story.story_set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up + rebase. Created 5 years, 7 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import StringIO 5 import StringIO
6 import sys 6 import sys
7 import unittest 7 import unittest
8 8
9 from telemetry import benchmark 9 from telemetry import benchmark
10 from telemetry import decorators 10 from telemetry import decorators
11 from telemetry.core import exceptions 11 from telemetry.core import exceptions
12 from telemetry.internal import story_runner 12 from telemetry.internal import story_runner
13 from telemetry.page import page as page_module 13 from telemetry.page import page as page_module
14 from telemetry.page import page_test 14 from telemetry.page import page_test
15 from telemetry.page import test_expectations 15 from telemetry.page import test_expectations
16 from telemetry.results import results_options 16 from telemetry.results import results_options
17 from telemetry import story
17 from telemetry.story import shared_state 18 from telemetry.story import shared_state
18 from telemetry.unittest_util import options_for_unittests 19 from telemetry.unittest_util import options_for_unittests
19 from telemetry.unittest_util import system_stub 20 from telemetry.unittest_util import system_stub
20 from telemetry import user_story 21 from telemetry import user_story as user_story_module
21 from telemetry.user_story import user_story_set
22 from telemetry.util import cloud_storage 22 from telemetry.util import cloud_storage
23 from telemetry.util import exception_formatter as exception_formatter_module 23 from telemetry.util import exception_formatter as exception_formatter_module
24 from telemetry.value import scalar 24 from telemetry.value import scalar
25 from telemetry.web_perf import timeline_based_measurement 25 from telemetry.web_perf import timeline_based_measurement
26 from telemetry.wpr import archive_info 26 from telemetry.wpr import archive_info
27 27
28 # This linter complains if we define classes nested inside functions. 28 # This linter complains if we define classes nested inside functions.
29 # pylint: disable=bad-super-call 29 # pylint: disable=bad-super-call
30 30
31 31
32 class FakePlatform(object): 32 class FakePlatform(object):
33 def CanMonitorThermalThrottling(self): 33 def CanMonitorThermalThrottling(self):
34 return False 34 return False
35 35
36 36
37 class TestSharedState(shared_state.SharedState): 37 class TestSharedState(shared_state.SharedState):
38 38
39 _platform = FakePlatform() 39 _platform = FakePlatform()
40 40
41 @classmethod 41 @classmethod
42 def SetTestPlatform(cls, platform): 42 def SetTestPlatform(cls, platform):
43 cls._platform = platform 43 cls._platform = platform
44 44
45 def __init__(self, test, options, user_story_setz): 45 def __init__(self, test, options, story_set):
46 super(TestSharedState, self).__init__( 46 super(TestSharedState, self).__init__(
47 test, options, user_story_setz) 47 test, options, story_set)
48 self._test = test 48 self._test = test
49 self._current_user_story = None 49 self._current_user_story = None
50 50
51 @property 51 @property
52 def platform(self): 52 def platform(self):
53 return self._platform 53 return self._platform
54 54
55 def WillRunUserStory(self, user_storyz): 55 def WillRunUserStory(self, user_storyz):
56 self._current_user_story = user_storyz 56 self._current_user_story = user_storyz
57 57
58 def GetTestExpectationAndSkipValue(self, expectations): 58 def GetTestExpectationAndSkipValue(self, expectations):
59 return 'pass', None 59 return 'pass', None
60 60
61 def RunUserStory(self, results): 61 def RunUserStory(self, results):
62 raise NotImplementedError 62 raise NotImplementedError
63 63
64 def DidRunUserStory(self, results): 64 def DidRunUserStory(self, results):
65 pass 65 pass
66 66
67 def TearDownState(self, results): 67 def TearDownState(self, results):
68 pass 68 pass
69 69
70 70
71 class TestSharedPageState(TestSharedState): 71 class TestSharedPageState(TestSharedState):
72 def RunUserStory(self, results): 72 def RunUserStory(self, results):
73 self._test.RunPage(self._current_user_story, None, results) 73 self._test.RunPage(self._current_user_story, None, results)
74 74
75 75
76 class FooUserStoryState(TestSharedPageState): 76 class FooStoryState(TestSharedPageState):
77 pass 77 pass
78 78
79 79
80 class BarUserStoryState(TestSharedPageState): 80 class BarStoryState(TestSharedPageState):
81 pass 81 pass
82 82
83 83
84 class DummyTest(page_test.PageTest): 84 class DummyTest(page_test.PageTest):
85 def RunPage(self, *_): 85 def RunPage(self, *_):
86 pass 86 pass
87 87
88 def ValidateAndMeasurePage(self, page, tab, results): 88 def ValidateAndMeasurePage(self, page, tab, results):
89 pass 89 pass
90 90
91 91
92 class EmptyMetadataForTest(benchmark.BenchmarkMetadata): 92 class EmptyMetadataForTest(benchmark.BenchmarkMetadata):
93 def __init__(self): 93 def __init__(self):
94 super(EmptyMetadataForTest, self).__init__('') 94 super(EmptyMetadataForTest, self).__init__('')
95 95
96 96
97 class DummyLocalUserStory(user_story.UserStory): 97 class DummyLocalUserStory(user_story_module.UserStory):
98 def __init__(self, shared_state_class, name=''): 98 def __init__(self, shared_state_class, name=''):
99 super(DummyLocalUserStory, self).__init__( 99 super(DummyLocalUserStory, self).__init__(
100 shared_state_class, name=name) 100 shared_state_class, name=name)
101 101
102 @property 102 @property
103 def is_local(self): 103 def is_local(self):
104 return True 104 return True
105 105
106 class MixedStateStorySet(user_story_set.UserStorySet): 106 class MixedStateStorySet(story.StorySet):
107 @property 107 @property
108 def allow_mixed_story_states(self): 108 def allow_mixed_story_states(self):
109 return True 109 return True
110 110
111 def SetupUserStorySet(allow_multiple_user_story_states, user_story_state_list): 111 def SetupStorySet(allow_multiple_user_story_states, user_story_state_list):
112 if allow_multiple_user_story_states: 112 if allow_multiple_user_story_states:
113 us = MixedStateStorySet() 113 us = MixedStateStorySet()
114 else: 114 else:
115 us = user_story_set.UserStorySet() 115 us = story.StorySet()
116 for user_story_state in user_story_state_list: 116 for user_story_state in user_story_state_list:
117 us.AddUserStory(DummyLocalUserStory(user_story_state)) 117 us.AddUserStory(DummyLocalUserStory(user_story_state))
118 return us 118 return us
119 119
120 def _GetOptionForUnittest(): 120 def _GetOptionForUnittest():
121 options = options_for_unittests.GetCopy() 121 options = options_for_unittests.GetCopy()
122 options.output_formats = ['none'] 122 options.output_formats = ['none']
123 options.suppress_gtest_report = False 123 options.suppress_gtest_report = False
124 parser = options.CreateParser() 124 parser = options.CreateParser()
125 story_runner.AddCommandLineArgs(parser) 125 story_runner.AddCommandLineArgs(parser)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 story_runner.exception_formatter = exception_formatter_module 161 story_runner.exception_formatter = exception_formatter_module
162 if self._story_runner_logging_stub: 162 if self._story_runner_logging_stub:
163 self._story_runner_logging_stub.Restore() 163 self._story_runner_logging_stub.Restore()
164 self._story_runner_logging_stub = None 164 self._story_runner_logging_stub = None
165 165
166 def tearDown(self): 166 def tearDown(self):
167 sys.stdout = self.actual_stdout 167 sys.stdout = self.actual_stdout
168 self.RestoreExceptionFormatter() 168 self.RestoreExceptionFormatter()
169 169
170 def testStoriesGroupedByStateClass(self): 170 def testStoriesGroupedByStateClass(self):
171 foo_states = [FooUserStoryState, FooUserStoryState, FooUserStoryState, 171 foo_states = [FooStoryState, FooStoryState, FooStoryState,
172 FooUserStoryState, FooUserStoryState] 172 FooStoryState, FooStoryState]
173 mixed_states = [FooUserStoryState, FooUserStoryState, FooUserStoryState, 173 mixed_states = [FooStoryState, FooStoryState, FooStoryState,
174 BarUserStoryState, FooUserStoryState] 174 BarStoryState, FooStoryState]
175 # UserStorySet's are only allowed to have one SharedState. 175 # StorySet's are only allowed to have one SharedState.
176 us = SetupUserStorySet(False, foo_states) 176 us = SetupStorySet(False, foo_states)
177 story_groups = ( 177 story_groups = (
178 story_runner.StoriesGroupedByStateClass( 178 story_runner.StoriesGroupedByStateClass(
179 us, False)) 179 us, False))
180 self.assertEqual(len(story_groups), 1) 180 self.assertEqual(len(story_groups), 1)
181 us = SetupUserStorySet(False, mixed_states) 181 us = SetupStorySet(False, mixed_states)
182 self.assertRaises( 182 self.assertRaises(
183 ValueError, 183 ValueError,
184 story_runner.StoriesGroupedByStateClass, 184 story_runner.StoriesGroupedByStateClass,
185 us, False) 185 us, False)
186 # BaseUserStorySets are allowed to have multiple SharedStates. 186 # BaseStorySets are allowed to have multiple SharedStates.
187 bus = SetupUserStorySet(True, mixed_states) 187 bus = SetupStorySet(True, mixed_states)
188 story_groups = ( 188 story_groups = (
189 story_runner.StoriesGroupedByStateClass( 189 story_runner.StoriesGroupedByStateClass(
190 bus, True)) 190 bus, True))
191 self.assertEqual(len(story_groups), 3) 191 self.assertEqual(len(story_groups), 3)
192 self.assertEqual(story_groups[0].shared_state_class, 192 self.assertEqual(story_groups[0].shared_state_class,
193 FooUserStoryState) 193 FooStoryState)
194 self.assertEqual(story_groups[1].shared_state_class, 194 self.assertEqual(story_groups[1].shared_state_class,
195 BarUserStoryState) 195 BarStoryState)
196 self.assertEqual(story_groups[2].shared_state_class, 196 self.assertEqual(story_groups[2].shared_state_class,
197 FooUserStoryState) 197 FooStoryState)
198 198
199 def RunUserStoryTest(self, us, expected_successes): 199 def RunUserStoryTest(self, us, expected_successes):
200 test = DummyTest() 200 test = DummyTest()
201 story_runner.Run( 201 story_runner.Run(
202 test, us, self.expectations, self.options, self.results) 202 test, us, self.expectations, self.options, self.results)
203 self.assertEquals(0, len(self.results.failures)) 203 self.assertEquals(0, len(self.results.failures))
204 self.assertEquals(expected_successes, 204 self.assertEquals(expected_successes,
205 GetNumberOfSuccessfulPageRuns(self.results)) 205 GetNumberOfSuccessfulPageRuns(self.results))
206 206
207 def testUserStoryTest(self): 207 def testUserStoryTest(self):
208 all_foo = [FooUserStoryState, FooUserStoryState, FooUserStoryState] 208 all_foo = [FooStoryState, FooStoryState, FooStoryState]
209 one_bar = [FooUserStoryState, FooUserStoryState, BarUserStoryState] 209 one_bar = [FooStoryState, FooStoryState, BarStoryState]
210 us = SetupUserStorySet(True, one_bar) 210 us = SetupStorySet(True, one_bar)
211 self.RunUserStoryTest(us, 3) 211 self.RunUserStoryTest(us, 3)
212 us = SetupUserStorySet(True, all_foo) 212 us = SetupStorySet(True, all_foo)
213 self.RunUserStoryTest(us, 6) 213 self.RunUserStoryTest(us, 6)
214 us = SetupUserStorySet(False, all_foo) 214 us = SetupStorySet(False, all_foo)
215 self.RunUserStoryTest(us, 9) 215 self.RunUserStoryTest(us, 9)
216 us = SetupUserStorySet(False, one_bar) 216 us = SetupStorySet(False, one_bar)
217 test = DummyTest() 217 test = DummyTest()
218 self.assertRaises(ValueError, story_runner.Run, test, us, 218 self.assertRaises(ValueError, story_runner.Run, test, us,
219 self.expectations, self.options, self.results) 219 self.expectations, self.options, self.results)
220 220
221 def testSuccessfulTimelineBasedMeasurementTest(self): 221 def testSuccessfulTimelineBasedMeasurementTest(self):
222 """Check that PageTest is not required for story_runner.Run. 222 """Check that PageTest is not required for story_runner.Run.
223 223
224 Any PageTest related calls or attributes need to only be called 224 Any PageTest related calls or attributes need to only be called
225 for PageTest tests. 225 for PageTest tests.
226 """ 226 """
227 class TestSharedTbmState(TestSharedState): 227 class TestSharedTbmState(TestSharedState):
228 def RunUserStory(self, results): 228 def RunUserStory(self, results):
229 pass 229 pass
230 230
231 test = timeline_based_measurement.TimelineBasedMeasurement( 231 test = timeline_based_measurement.TimelineBasedMeasurement(
232 timeline_based_measurement.Options()) 232 timeline_based_measurement.Options())
233 us = user_story_set.UserStorySet() 233 us = story.StorySet()
234 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState)) 234 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState))
235 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState)) 235 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState))
236 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState)) 236 us.AddUserStory(DummyLocalUserStory(TestSharedTbmState))
237 story_runner.Run( 237 story_runner.Run(
238 test, us, self.expectations, self.options, self.results) 238 test, us, self.expectations, self.options, self.results)
239 self.assertEquals(0, len(self.results.failures)) 239 self.assertEquals(0, len(self.results.failures))
240 self.assertEquals(3, GetNumberOfSuccessfulPageRuns(self.results)) 240 self.assertEquals(3, GetNumberOfSuccessfulPageRuns(self.results))
241 241
242 def testTearDownIsCalledOnceForEachUserStoryGroupWithPageSetRepeat(self): 242 def testTearDownIsCalledOnceForEachUserStoryGroupWithPageSetRepeat(self):
243 self.options.pageset_repeat = 3 243 self.options.pageset_repeat = 3
244 fooz_init_call_counter = [0] 244 fooz_init_call_counter = [0]
245 fooz_tear_down_call_counter = [0] 245 fooz_tear_down_call_counter = [0]
246 barz_init_call_counter = [0] 246 barz_init_call_counter = [0]
247 barz_tear_down_call_counter = [0] 247 barz_tear_down_call_counter = [0]
248 class FoozUserStoryState(FooUserStoryState): 248 class FoozStoryState(FooStoryState):
249 def __init__(self, test, options, user_story_setz): 249 def __init__(self, test, options, storyz):
250 super(FoozUserStoryState, self).__init__( 250 super(FoozStoryState, self).__init__(
251 test, options, user_story_setz) 251 test, options, storyz)
252 fooz_init_call_counter[0] += 1 252 fooz_init_call_counter[0] += 1
253 def TearDownState(self, _results): 253 def TearDownState(self, _results):
254 fooz_tear_down_call_counter[0] += 1 254 fooz_tear_down_call_counter[0] += 1
255 255
256 class BarzUserStoryState(BarUserStoryState): 256 class BarzStoryState(BarStoryState):
257 def __init__(self, test, options, user_story_setz): 257 def __init__(self, test, options, storyz):
258 super(BarzUserStoryState, self).__init__( 258 super(BarzStoryState, self).__init__(
259 test, options, user_story_setz) 259 test, options, storyz)
260 barz_init_call_counter[0] += 1 260 barz_init_call_counter[0] += 1
261 def TearDownState(self, _results): 261 def TearDownState(self, _results):
262 barz_tear_down_call_counter[0] += 1 262 barz_tear_down_call_counter[0] += 1
263 def AssertAndCleanUpFoo(): 263 def AssertAndCleanUpFoo():
264 self.assertEquals(1, fooz_init_call_counter[0]) 264 self.assertEquals(1, fooz_init_call_counter[0])
265 self.assertEquals(1, fooz_tear_down_call_counter[0]) 265 self.assertEquals(1, fooz_tear_down_call_counter[0])
266 fooz_init_call_counter[0] = 0 266 fooz_init_call_counter[0] = 0
267 fooz_tear_down_call_counter[0] = 0 267 fooz_tear_down_call_counter[0] = 0
268 268
269 uss1_list = [FoozUserStoryState, FoozUserStoryState, FoozUserStoryState, 269 story_set1_list = [FoozStoryState, FoozStoryState, FoozStoryState,
270 BarzUserStoryState, BarzUserStoryState] 270 BarzStoryState, BarzStoryState]
271 uss1 = SetupUserStorySet(True, uss1_list) 271 story_set1 = SetupStorySet(True, story_set1_list)
272 self.RunUserStoryTest(uss1, 15) 272 self.RunUserStoryTest(story_set1, 15)
273 AssertAndCleanUpFoo() 273 AssertAndCleanUpFoo()
274 self.assertEquals(1, barz_init_call_counter[0]) 274 self.assertEquals(1, barz_init_call_counter[0])
275 self.assertEquals(1, barz_tear_down_call_counter[0]) 275 self.assertEquals(1, barz_tear_down_call_counter[0])
276 barz_init_call_counter[0] = 0 276 barz_init_call_counter[0] = 0
277 barz_tear_down_call_counter[0] = 0 277 barz_tear_down_call_counter[0] = 0
278 278
279 uss2_list = [FoozUserStoryState, FoozUserStoryState, FoozUserStoryState, 279 story_set2_list = [FoozStoryState, FoozStoryState, FoozStoryState,
280 FoozUserStoryState] 280 FoozStoryState]
281 uss2 = SetupUserStorySet(False, uss2_list) 281 story_set2 = SetupStorySet(False, story_set2_list)
282 self.RunUserStoryTest(uss2, 27) 282 self.RunUserStoryTest(story_set2, 27)
283 AssertAndCleanUpFoo() 283 AssertAndCleanUpFoo()
284 self.assertEquals(0, barz_init_call_counter[0]) 284 self.assertEquals(0, barz_init_call_counter[0])
285 self.assertEquals(0, barz_tear_down_call_counter[0]) 285 self.assertEquals(0, barz_tear_down_call_counter[0])
286 286
287 def testAppCrashExceptionCausesFailureValue(self): 287 def testAppCrashExceptionCausesFailureValue(self):
288 self.SuppressExceptionFormatting() 288 self.SuppressExceptionFormatting()
289 us = user_story_set.UserStorySet() 289 us = story.StorySet()
290 class SharedUserStoryThatCausesAppCrash(TestSharedPageState): 290 class SharedUserStoryThatCausesAppCrash(TestSharedPageState):
291 def WillRunUserStory(self, user_storyz): 291 def WillRunUserStory(self, user_storyz):
292 raise exceptions.AppCrashException('App Foo crashes') 292 raise exceptions.AppCrashException('App Foo crashes')
293 293
294 us.AddUserStory(DummyLocalUserStory(SharedUserStoryThatCausesAppCrash)) 294 us.AddUserStory(DummyLocalUserStory(SharedUserStoryThatCausesAppCrash))
295 story_runner.Run( 295 story_runner.Run(
296 DummyTest(), us, self.expectations, self.options, self.results) 296 DummyTest(), us, self.expectations, self.options, self.results)
297 self.assertEquals(1, len(self.results.failures)) 297 self.assertEquals(1, len(self.results.failures))
298 self.assertEquals(0, GetNumberOfSuccessfulPageRuns(self.results)) 298 self.assertEquals(0, GetNumberOfSuccessfulPageRuns(self.results))
299 self.assertIn('App Foo crashes', self.fake_stdout.getvalue()) 299 self.assertIn('App Foo crashes', self.fake_stdout.getvalue())
300 300
301 def testUnknownExceptionIsFatal(self): 301 def testUnknownExceptionIsFatal(self):
302 self.SuppressExceptionFormatting() 302 self.SuppressExceptionFormatting()
303 uss = user_story_set.UserStorySet() 303 story_set = story.StorySet()
304 304
305 class UnknownException(Exception): 305 class UnknownException(Exception):
306 pass 306 pass
307 307
308 # This erroneous test is set up to raise exception for the 2nd user story 308 # This erroneous test is set up to raise exception for the 2nd user story
309 # run. 309 # run.
310 class Test(page_test.PageTest): 310 class Test(page_test.PageTest):
311 def __init__(self, *args): 311 def __init__(self, *args):
312 super(Test, self).__init__(*args) 312 super(Test, self).__init__(*args)
313 self.run_count = 0 313 self.run_count = 0
314 314
315 def RunPage(self, *_): 315 def RunPage(self, *_):
316 old_run_count = self.run_count 316 old_run_count = self.run_count
317 self.run_count += 1 317 self.run_count += 1
318 if old_run_count == 1: 318 if old_run_count == 1:
319 raise UnknownException('FooBarzException') 319 raise UnknownException('FooBarzException')
320 320
321 def ValidateAndMeasurePage(self, page, tab, results): 321 def ValidateAndMeasurePage(self, page, tab, results):
322 pass 322 pass
323 323
324 us1 = DummyLocalUserStory(TestSharedPageState) 324 us1 = DummyLocalUserStory(TestSharedPageState)
325 us2 = DummyLocalUserStory(TestSharedPageState) 325 us2 = DummyLocalUserStory(TestSharedPageState)
326 uss.AddUserStory(us1) 326 story_set.AddUserStory(us1)
327 uss.AddUserStory(us2) 327 story_set.AddUserStory(us2)
328 test = Test() 328 test = Test()
329 with self.assertRaises(UnknownException): 329 with self.assertRaises(UnknownException):
330 story_runner.Run( 330 story_runner.Run(
331 test, uss, self.expectations, self.options, self.results) 331 test, story_set, self.expectations, self.options, self.results)
332 self.assertEqual(set([us2]), self.results.pages_that_failed) 332 self.assertEqual(set([us2]), self.results.pages_that_failed)
333 self.assertEqual(set([us1]), self.results.pages_that_succeeded) 333 self.assertEqual(set([us1]), self.results.pages_that_succeeded)
334 self.assertIn('FooBarzException', self.fake_stdout.getvalue()) 334 self.assertIn('FooBarzException', self.fake_stdout.getvalue())
335 335
336 def testRaiseBrowserGoneExceptionFromRunPage(self): 336 def testRaiseBrowserGoneExceptionFromRunPage(self):
337 self.SuppressExceptionFormatting() 337 self.SuppressExceptionFormatting()
338 us = user_story_set.UserStorySet() 338 us = story.StorySet()
339 339
340 class Test(page_test.PageTest): 340 class Test(page_test.PageTest):
341 def __init__(self, *args): 341 def __init__(self, *args):
342 super(Test, self).__init__(*args) 342 super(Test, self).__init__(*args)
343 self.run_count = 0 343 self.run_count = 0
344 344
345 def RunPage(self, *_): 345 def RunPage(self, *_):
346 old_run_count = self.run_count 346 old_run_count = self.run_count
347 self.run_count += 1 347 self.run_count += 1
348 if old_run_count == 0: 348 if old_run_count == 0:
349 raise exceptions.BrowserGoneException('i am a browser instance') 349 raise exceptions.BrowserGoneException('i am a browser instance')
350 350
351 def ValidateAndMeasurePage(self, page, tab, results): 351 def ValidateAndMeasurePage(self, page, tab, results):
352 pass 352 pass
353 353
354 us.AddUserStory(DummyLocalUserStory(TestSharedPageState)) 354 us.AddUserStory(DummyLocalUserStory(TestSharedPageState))
355 us.AddUserStory(DummyLocalUserStory(TestSharedPageState)) 355 us.AddUserStory(DummyLocalUserStory(TestSharedPageState))
356 test = Test() 356 test = Test()
357 story_runner.Run( 357 story_runner.Run(
358 test, us, self.expectations, self.options, self.results) 358 test, us, self.expectations, self.options, self.results)
359 self.assertEquals(2, test.run_count) 359 self.assertEquals(2, test.run_count)
360 self.assertEquals(1, len(self.results.failures)) 360 self.assertEquals(1, len(self.results.failures))
361 self.assertEquals(1, GetNumberOfSuccessfulPageRuns(self.results)) 361 self.assertEquals(1, GetNumberOfSuccessfulPageRuns(self.results))
362 362
363 def testAppCrashThenRaiseInTearDownFatal(self): 363 def testAppCrashThenRaiseInTearDownFatal(self):
364 self.SuppressExceptionFormatting() 364 self.SuppressExceptionFormatting()
365 us = user_story_set.UserStorySet() 365 us = story.StorySet()
366 366
367 class DidRunTestError(Exception): 367 class DidRunTestError(Exception):
368 pass 368 pass
369 369
370 class TestTearDownSharedState(TestSharedPageState): 370 class TestTearDownSharedState(TestSharedPageState):
371 def TearDownState(self, results): 371 def TearDownState(self, results):
372 self._test.DidRunTest('app', results) 372 self._test.DidRunTest('app', results)
373 373
374 class Test(page_test.PageTest): 374 class Test(page_test.PageTest):
375 def __init__(self, *args): 375 def __init__(self, *args):
(...skipping 20 matching lines...) Expand all
396 test = Test() 396 test = Test()
397 397
398 with self.assertRaises(DidRunTestError): 398 with self.assertRaises(DidRunTestError):
399 story_runner.Run( 399 story_runner.Run(
400 test, us, self.expectations, self.options, self.results) 400 test, us, self.expectations, self.options, self.results)
401 self.assertEqual(['app-crash', 'did-run-test'], test._unit_test_events) 401 self.assertEqual(['app-crash', 'did-run-test'], test._unit_test_events)
402 # The AppCrashException gets added as a failure. 402 # The AppCrashException gets added as a failure.
403 self.assertEquals(1, len(self.results.failures)) 403 self.assertEquals(1, len(self.results.failures))
404 404
405 def testPagesetRepeat(self): 405 def testPagesetRepeat(self):
406 us = user_story_set.UserStorySet() 406 us = story.StorySet()
407 us.AddUserStory(DummyLocalUserStory(TestSharedPageState, name='blank')) 407 us.AddUserStory(DummyLocalUserStory(TestSharedPageState, name='blank'))
408 us.AddUserStory(DummyLocalUserStory(TestSharedPageState, name='green')) 408 us.AddUserStory(DummyLocalUserStory(TestSharedPageState, name='green'))
409 409
410 class Measurement(page_test.PageTest): 410 class Measurement(page_test.PageTest):
411 i = 0 411 i = 0
412 def RunPage(self, page, _, results): 412 def RunPage(self, page, _, results):
413 self.i += 1 413 self.i += 1
414 results.AddValue(scalar.ScalarValue( 414 results.AddValue(scalar.ScalarValue(
415 page, 'metric', 'unit', self.i)) 415 page, 'metric', 'unit', self.i))
416 416
(...skipping 13 matching lines...) Expand all
430 self.assertEquals(0, len(results.failures)) 430 self.assertEquals(0, len(results.failures))
431 self.assertIn('RESULT metric: blank= [1,3] unit', contents) 431 self.assertIn('RESULT metric: blank= [1,3] unit', contents)
432 self.assertIn('RESULT metric: green= [2,4] unit', contents) 432 self.assertIn('RESULT metric: green= [2,4] unit', contents)
433 self.assertIn('*RESULT metric: metric= [1,2,3,4] unit', contents) 433 self.assertIn('*RESULT metric: metric= [1,2,3,4] unit', contents)
434 434
435 @decorators.Disabled('chromeos') # crbug.com/483212 435 @decorators.Disabled('chromeos') # crbug.com/483212
436 def testUpdateAndCheckArchives(self): 436 def testUpdateAndCheckArchives(self):
437 usr_stub = system_stub.Override(story_runner, ['cloud_storage']) 437 usr_stub = system_stub.Override(story_runner, ['cloud_storage'])
438 wpr_stub = system_stub.Override(archive_info, ['cloud_storage']) 438 wpr_stub = system_stub.Override(archive_info, ['cloud_storage'])
439 try: 439 try:
440 uss = user_story_set.UserStorySet() 440 story_set = story.StorySet()
441 uss.AddUserStory(page_module.Page( 441 story_set.AddUserStory(page_module.Page(
442 'http://www.testurl.com', uss, uss.base_dir)) 442 'http://www.testurl.com', story_set, story_set.base_dir))
443 # Page set missing archive_data_file. 443 # Page set missing archive_data_file.
444 self.assertRaises( 444 self.assertRaises(
445 story_runner.ArchiveError, 445 story_runner.ArchiveError,
446 story_runner._UpdateAndCheckArchives, 446 story_runner._UpdateAndCheckArchives,
447 uss.archive_data_file, uss.wpr_archive_info, uss.user_stories) 447 story_set.archive_data_file,
448 story_set.wpr_archive_info,
449 story_set.user_stories)
448 450
449 uss = user_story_set.UserStorySet( 451 story_set = story.StorySet(
450 archive_data_file='missing_archive_data_file.json') 452 archive_data_file='missing_archive_data_file.json')
451 uss.AddUserStory(page_module.Page( 453 story_set.AddUserStory(page_module.Page(
452 'http://www.testurl.com', uss, uss.base_dir)) 454 'http://www.testurl.com', story_set, story_set.base_dir))
453 # Page set missing json file specified in archive_data_file. 455 # Page set missing json file specified in archive_data_file.
454 self.assertRaises( 456 self.assertRaises(
455 story_runner.ArchiveError, 457 story_runner.ArchiveError,
456 story_runner._UpdateAndCheckArchives, 458 story_runner._UpdateAndCheckArchives,
457 uss.archive_data_file, uss.wpr_archive_info, uss.user_stories) 459 story_set.archive_data_file,
460 story_set.wpr_archive_info,
461 story_set.user_stories)
458 462
459 uss = user_story_set.UserStorySet( 463 story_set = story.StorySet(
460 archive_data_file='../../unittest_data/archive_files/test.json', 464 archive_data_file='../../unittest_data/archive_files/test.json',
461 cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET) 465 cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
462 uss.AddUserStory(page_module.Page( 466 story_set.AddUserStory(page_module.Page(
463 'http://www.testurl.com', uss, uss.base_dir)) 467 'http://www.testurl.com', story_set, story_set.base_dir))
464 # Page set with valid archive_data_file. 468 # Page set with valid archive_data_file.
465 self.assertTrue(story_runner._UpdateAndCheckArchives( 469 self.assertTrue(story_runner._UpdateAndCheckArchives(
466 uss.archive_data_file, uss.wpr_archive_info, uss.user_stories)) 470 story_set.archive_data_file, story_set.wpr_archive_info,
467 uss.AddUserStory(page_module.Page( 471 story_set.user_stories))
468 'http://www.google.com', uss, uss.base_dir)) 472 story_set.AddUserStory(page_module.Page(
473 'http://www.google.com', story_set, story_set.base_dir))
469 # Page set with an archive_data_file which exists but is missing a page. 474 # Page set with an archive_data_file which exists but is missing a page.
470 self.assertRaises( 475 self.assertRaises(
471 story_runner.ArchiveError, 476 story_runner.ArchiveError,
472 story_runner._UpdateAndCheckArchives, 477 story_runner._UpdateAndCheckArchives,
473 uss.archive_data_file, uss.wpr_archive_info, uss.user_stories) 478 story_set.archive_data_file,
479 story_set.wpr_archive_info,
480 story_set.user_stories)
474 481
475 uss = user_story_set.UserStorySet( 482 story_set = story.StorySet(
476 archive_data_file='../../unittest_data/test_missing_wpr_file.json', 483 archive_data_file='../../unittest_data/test_missing_wpr_file.json',
477 cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET) 484 cloud_storage_bucket=cloud_storage.PUBLIC_BUCKET)
478 uss.AddUserStory(page_module.Page( 485 story_set.AddUserStory(page_module.Page(
479 'http://www.testurl.com', uss, uss.base_dir)) 486 'http://www.testurl.com', story_set, story_set.base_dir))
480 uss.AddUserStory(page_module.Page( 487 story_set.AddUserStory(page_module.Page(
481 'http://www.google.com', uss, uss.base_dir)) 488 'http://www.google.com', story_set, story_set.base_dir))
482 # Page set with an archive_data_file which exists and contains all pages 489 # Page set with an archive_data_file which exists and contains all pages
483 # but fails to find a wpr file. 490 # but fails to find a wpr file.
484 self.assertRaises( 491 self.assertRaises(
485 story_runner.ArchiveError, 492 story_runner.ArchiveError,
486 story_runner._UpdateAndCheckArchives, 493 story_runner._UpdateAndCheckArchives,
487 uss.archive_data_file, uss.wpr_archive_info, uss.user_stories) 494 story_set.archive_data_file,
495 story_set.wpr_archive_info,
496 story_set.user_stories)
488 finally: 497 finally:
489 usr_stub.Restore() 498 usr_stub.Restore()
490 wpr_stub.Restore() 499 wpr_stub.Restore()
491 500
492 501
493 def _testMaxFailuresOptionIsRespectedAndOverridable( 502 def _testMaxFailuresOptionIsRespectedAndOverridable(
494 self, num_failing_user_stories, runner_max_failures, options_max_failures, 503 self, num_failing_user_stories, runner_max_failures, options_max_failures,
495 expected_num_failures): 504 expected_num_failures):
496 class SimpleSharedState( 505 class SimpleSharedState(
497 shared_state.SharedState): 506 shared_state.SharedState):
498 _fake_platform = FakePlatform() 507 _fake_platform = FakePlatform()
499 _current_user_story = None 508 _current_user_story = None
500 509
501 @property 510 @property
502 def platform(self): 511 def platform(self):
503 return self._fake_platform 512 return self._fake_platform
504 513
505 def WillRunUserStory(self, story): 514 def WillRunUserStory(self, user_story):
506 self._current_user_story = story 515 self._current_user_story = user_story
507 516
508 def RunUserStory(self, results): 517 def RunUserStory(self, results):
509 self._current_user_story.Run() 518 self._current_user_story.Run()
510 519
511 def DidRunUserStory(self, results): 520 def DidRunUserStory(self, results):
512 pass 521 pass
513 522
514 def GetTestExpectationAndSkipValue(self, expectations): 523 def GetTestExpectationAndSkipValue(self, expectations):
515 return 'pass', None 524 return 'pass', None
516 525
517 def TearDownState(self, results): 526 def TearDownState(self, results):
518 pass 527 pass
519 528
520 class FailingUserStory(user_story.UserStory): 529 class FailingUserStory(user_story_module.UserStory):
521 def __init__(self): 530 def __init__(self):
522 super(FailingUserStory, self).__init__( 531 super(FailingUserStory, self).__init__(
523 shared_state_class=SimpleSharedState, 532 shared_state_class=SimpleSharedState,
524 is_local=True) 533 is_local=True)
525 self.was_run = False 534 self.was_run = False
526 535
527 def Run(self): 536 def Run(self):
528 self.was_run = True 537 self.was_run = True
529 raise page_test.Failure 538 raise page_test.Failure
530 539
531 self.SuppressExceptionFormatting() 540 self.SuppressExceptionFormatting()
532 541
533 uss = user_story_set.UserStorySet() 542 story_set = story.StorySet()
534 for _ in range(num_failing_user_stories): 543 for _ in range(num_failing_user_stories):
535 uss.AddUserStory(FailingUserStory()) 544 story_set.AddUserStory(FailingUserStory())
536 545
537 options = _GetOptionForUnittest() 546 options = _GetOptionForUnittest()
538 options.output_formats = ['none'] 547 options.output_formats = ['none']
539 options.suppress_gtest_report = True 548 options.suppress_gtest_report = True
540 if options_max_failures: 549 if options_max_failures:
541 options.max_failures = options_max_failures 550 options.max_failures = options_max_failures
542 551
543 results = results_options.CreateResults(EmptyMetadataForTest(), options) 552 results = results_options.CreateResults(EmptyMetadataForTest(), options)
544 story_runner.Run( 553 story_runner.Run(
545 DummyTest(), uss, test_expectations.TestExpectations(), options, 554 DummyTest(), story_set, test_expectations.TestExpectations(), options,
546 results, max_failures=runner_max_failures) 555 results, max_failures=runner_max_failures)
547 self.assertEquals(0, GetNumberOfSuccessfulPageRuns(results)) 556 self.assertEquals(0, GetNumberOfSuccessfulPageRuns(results))
548 self.assertEquals(expected_num_failures, len(results.failures)) 557 self.assertEquals(expected_num_failures, len(results.failures))
549 for ii, story in enumerate(uss.user_stories): 558 for ii, user_story in enumerate(story_set.user_stories):
550 self.assertEqual(story.was_run, ii < expected_num_failures) 559 self.assertEqual(user_story.was_run, ii < expected_num_failures)
551 560
552 def testMaxFailuresNotSpecified(self): 561 def testMaxFailuresNotSpecified(self):
553 self._testMaxFailuresOptionIsRespectedAndOverridable( 562 self._testMaxFailuresOptionIsRespectedAndOverridable(
554 num_failing_user_stories=5, runner_max_failures=None, 563 num_failing_user_stories=5, runner_max_failures=None,
555 options_max_failures=None, expected_num_failures=5) 564 options_max_failures=None, expected_num_failures=5)
556 565
557 def testMaxFailuresSpecifiedToRun(self): 566 def testMaxFailuresSpecifiedToRun(self):
558 # Runs up to max_failures+1 failing tests before stopping, since 567 # Runs up to max_failures+1 failing tests before stopping, since
559 # every tests after max_failures failures have been encountered 568 # every tests after max_failures failures have been encountered
560 # may all be passing. 569 # may all be passing.
561 self._testMaxFailuresOptionIsRespectedAndOverridable( 570 self._testMaxFailuresOptionIsRespectedAndOverridable(
562 num_failing_user_stories=5, runner_max_failures=3, 571 num_failing_user_stories=5, runner_max_failures=3,
563 options_max_failures=None, expected_num_failures=4) 572 options_max_failures=None, expected_num_failures=4)
564 573
565 def testMaxFailuresOption(self): 574 def testMaxFailuresOption(self):
566 # Runs up to max_failures+1 failing tests before stopping, since 575 # Runs up to max_failures+1 failing tests before stopping, since
567 # every tests after max_failures failures have been encountered 576 # every tests after max_failures failures have been encountered
568 # may all be passing. 577 # may all be passing.
569 self._testMaxFailuresOptionIsRespectedAndOverridable( 578 self._testMaxFailuresOptionIsRespectedAndOverridable(
570 num_failing_user_stories=5, runner_max_failures=3, 579 num_failing_user_stories=5, runner_max_failures=3,
571 options_max_failures=1, expected_num_failures=2) 580 options_max_failures=1, expected_num_failures=2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698