How to use addSuccess method in autotest

Best Python code snippet using autotest_python

buildbot_page_measurement_results_unittest.py

Source:buildbot_page_measurement_results_unittest.py Github

copy

Full Screen

1# Copyright (c) 2012 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import os5import unittest6from telemetry.page import buildbot_page_measurement_results7from telemetry.page import page_set8from telemetry.page import perf_tests_helper9def _MakePageSet():10 return page_set.PageSet.FromDict({11 "description": "hello",12 "archive_path": "foo.wpr",13 "pages": [14 {"url": "http://www.foo.com/"},15 {"url": "http://www.bar.com/"},16 {"url": "http://www.baz.com/"}17 ]18 }, os.path.dirname(__file__))19class SummarySavingPageMeasurementResults(20 buildbot_page_measurement_results.BuildbotPageMeasurementResults):21 def __init__(self, trace_tag=''):22 super(SummarySavingPageMeasurementResults, self).__init__(23 None, trace_tag=trace_tag)24 self.results = []25 def _PrintPerfResult(self, *args):26 res = perf_tests_helper.PrintPerfResult(*args, print_to_stdout=False)27 self.results.append(res)28class BuildbotPageMeasurementResultsTest(unittest.TestCase):29 def assertEquals(self, ex, res):30 # This helps diagnose result mismatches.31 if ex != res and isinstance(ex, list):32 def CleanList(l):33 res = []34 for x in l:35 x = x.split('\n')36 res.extend(x)37 return res38 ex = CleanList(ex)39 res = CleanList(res)40 max_len = max(len(ex), len(res))41 max_width = max([len(x) for x in ex + res])42 max_width = max(10, max_width)43 print "Lists differ!"44 print '%*s | %*s' % (max_width, 'expected', max_width, 'result')45 for i in range(max_len):46 if i < len(ex):47 e = ex[i]48 else:49 e = ''50 if i < len(res):51 r = res[i]52 else:53 r = ''54 if e != r:55 sep = '*'56 else:57 sep = '|'58 print '%*s %s %*s' % (max_width, e, sep, max_width, r)59 print ""60 super(BuildbotPageMeasurementResultsTest, self).assertEquals(ex, res)61 def test_basic_summary(self):62 test_page_set = _MakePageSet()63 measurement_results = SummarySavingPageMeasurementResults()64 measurement_results.WillMeasurePage(test_page_set.pages[0])65 measurement_results.Add('a', 'seconds', 3)66 measurement_results.DidMeasurePage()67 measurement_results.AddSuccess(test_page_set.pages[0])68 measurement_results.WillMeasurePage(test_page_set.pages[1])69 measurement_results.Add('a', 'seconds', 7)70 measurement_results.DidMeasurePage()71 measurement_results.AddSuccess(test_page_set.pages[1])72 measurement_results.PrintSummary()73 expected = ['RESULT a_by_url: http___www.bar.com_= 7 seconds',74 'RESULT a_by_url: http___www.foo.com_= 3 seconds',75 '*RESULT a: a= [3,7] seconds\nAvg a: 5.000000seconds\n' +76 'Sd a: 2.828427seconds',77 'RESULT telemetry_page_measurement_results: ' +78 'num_failed= 0 count',79 'RESULT telemetry_page_measurement_results: ' +80 'num_errored= 0 count']81 self.assertEquals(expected, measurement_results.results)82 def test_basic_summary_with_only_one_page(self):83 test_page_set = _MakePageSet()84 measurement_results = SummarySavingPageMeasurementResults()85 measurement_results.WillMeasurePage(test_page_set.pages[0])86 measurement_results.Add('a', 'seconds', 3)87 measurement_results.DidMeasurePage()88 measurement_results.AddSuccess(test_page_set.pages[0])89 measurement_results.PrintSummary()90 expected = ['*RESULT a: a= 3 seconds',91 'RESULT telemetry_page_measurement_results: ' +92 'num_failed= 0 count',93 'RESULT telemetry_page_measurement_results: ' +94 'num_errored= 0 count']95 self.assertEquals(expected, measurement_results.results)96 def test_basic_summary_nonuniform_results(self):97 test_page_set = _MakePageSet()98 measurement_results = SummarySavingPageMeasurementResults()99 measurement_results.WillMeasurePage(test_page_set.pages[0])100 measurement_results.Add('a', 'seconds', 3)101 measurement_results.Add('b', 'seconds', 10)102 measurement_results.DidMeasurePage()103 measurement_results.AddSuccess(test_page_set.pages[0])104 measurement_results.WillMeasurePage(test_page_set.pages[1])105 measurement_results.Add('a', 'seconds', 3)106 measurement_results.Add('b', 'seconds', 10)107 measurement_results.DidMeasurePage()108 measurement_results.AddSuccess(test_page_set.pages[1])109 measurement_results.WillMeasurePage(test_page_set.pages[2])110 measurement_results.Add('a', 'seconds', 7)111 # Note, page[2] does not report a 'b' metric.112 measurement_results.DidMeasurePage()113 measurement_results.AddSuccess(test_page_set.pages[2])114 measurement_results.PrintSummary()115 expected = ['RESULT a_by_url: http___www.bar.com_= 3 seconds',116 'RESULT a_by_url: http___www.baz.com_= 7 seconds',117 'RESULT a_by_url: http___www.foo.com_= 3 seconds',118 '*RESULT a: a= [3,3,7] seconds\nAvg a: 4.333333seconds\n' +119 'Sd a: 2.309401seconds',120 'RESULT b_by_url: http___www.bar.com_= 10 seconds',121 'RESULT b_by_url: http___www.foo.com_= 10 seconds',122 '*RESULT b: b= [10,10] seconds\nAvg b: 10.000000seconds',123 'RESULT telemetry_page_measurement_results: ' +124 'num_failed= 0 count',125 'RESULT telemetry_page_measurement_results: ' +126 'num_errored= 0 count']127 self.assertEquals(expected, measurement_results.results)128 def test_basic_summary_pass_and_fail_page(self):129 """If a page failed, only print summary for individual pages."""130 test_page_set = _MakePageSet()131 measurement_results = SummarySavingPageMeasurementResults()132 measurement_results.WillMeasurePage(test_page_set.pages[0])133 measurement_results.Add('a', 'seconds', 3)134 measurement_results.DidMeasurePage()135 measurement_results.AddFailureMessage(test_page_set.pages[0], 'message')136 measurement_results.WillMeasurePage(test_page_set.pages[1])137 measurement_results.Add('a', 'seconds', 7)138 measurement_results.DidMeasurePage()139 measurement_results.AddSuccess(test_page_set.pages[1])140 measurement_results.PrintSummary()141 expected = ['RESULT a_by_url: http___www.bar.com_= 7 seconds',142 'RESULT a_by_url: http___www.foo.com_= 3 seconds',143 'RESULT telemetry_page_measurement_results: ' +144 'num_failed= 1 count',145 'RESULT telemetry_page_measurement_results: ' +146 'num_errored= 0 count']147 self.assertEquals(expected, measurement_results.results)148 def test_repeated_pageset_one_iteration_one_page_fails(self):149 """Page fails on one iteration, no averaged results should print."""150 test_page_set = _MakePageSet()151 measurement_results = SummarySavingPageMeasurementResults()152 measurement_results.WillMeasurePage(test_page_set.pages[0])153 measurement_results.Add('a', 'seconds', 3)154 measurement_results.DidMeasurePage()155 measurement_results.WillMeasurePage(test_page_set.pages[1])156 measurement_results.Add('a', 'seconds', 7)157 measurement_results.DidMeasurePage()158 measurement_results.AddFailureMessage(test_page_set.pages[1], 'message')159 measurement_results.WillMeasurePage(test_page_set.pages[0])160 measurement_results.Add('a', 'seconds', 4)161 measurement_results.DidMeasurePage()162 measurement_results.AddSuccess(test_page_set.pages[0])163 measurement_results.WillMeasurePage(test_page_set.pages[1])164 measurement_results.Add('a', 'seconds', 8)165 measurement_results.DidMeasurePage()166 measurement_results.AddSuccess(test_page_set.pages[1])167 measurement_results.PrintSummary()168 expected = ['RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +169 'Avg a_by_url: 7.500000seconds\n' +170 'Sd a_by_url: 0.707107seconds',171 'RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +172 'Avg a_by_url: 3.500000seconds\n' +173 'Sd a_by_url: 0.707107seconds',174 'RESULT telemetry_page_measurement_results: ' +175 'num_failed= 1 count',176 'RESULT telemetry_page_measurement_results: ' +177 'num_errored= 0 count']178 self.assertEquals(expected, measurement_results.results)179 def test_repeated_pageset_one_iteration_one_page_error(self):180 """Page error on one iteration, no averaged results should print."""181 test_page_set = _MakePageSet()182 measurement_results = SummarySavingPageMeasurementResults()183 measurement_results.WillMeasurePage(test_page_set.pages[0])184 measurement_results.Add('a', 'seconds', 3)185 measurement_results.DidMeasurePage()186 measurement_results.AddSuccess(test_page_set.pages[0])187 measurement_results.WillMeasurePage(test_page_set.pages[1])188 measurement_results.Add('a', 'seconds', 7)189 measurement_results.DidMeasurePage()190 measurement_results.AddErrorMessage(test_page_set.pages[1], 'message')191 measurement_results.WillMeasurePage(test_page_set.pages[0])192 measurement_results.Add('a', 'seconds', 4)193 measurement_results.DidMeasurePage()194 measurement_results.AddSuccess(test_page_set.pages[0])195 measurement_results.WillMeasurePage(test_page_set.pages[1])196 measurement_results.Add('a', 'seconds', 8)197 measurement_results.DidMeasurePage()198 measurement_results.AddSuccess(test_page_set.pages[1])199 measurement_results.PrintSummary()200 expected = ['RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +201 'Avg a_by_url: 7.500000seconds\n' +202 'Sd a_by_url: 0.707107seconds',203 'RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +204 'Avg a_by_url: 3.500000seconds\n' +205 'Sd a_by_url: 0.707107seconds',206 'RESULT telemetry_page_measurement_results: ' +207 'num_failed= 0 count',208 'RESULT telemetry_page_measurement_results: ' +209 'num_errored= 1 count']210 self.assertEquals(expected, measurement_results.results)211 def test_repeated_pageset(self):212 test_page_set = _MakePageSet()213 measurement_results = SummarySavingPageMeasurementResults()214 measurement_results.WillMeasurePage(test_page_set.pages[0])215 measurement_results.Add('a', 'seconds', 3)216 measurement_results.DidMeasurePage()217 measurement_results.AddSuccess(test_page_set.pages[0])218 measurement_results.WillMeasurePage(test_page_set.pages[1])219 measurement_results.Add('a', 'seconds', 7)220 measurement_results.DidMeasurePage()221 measurement_results.AddSuccess(test_page_set.pages[1])222 measurement_results.WillMeasurePage(test_page_set.pages[0])223 measurement_results.Add('a', 'seconds', 4)224 measurement_results.DidMeasurePage()225 measurement_results.AddSuccess(test_page_set.pages[0])226 measurement_results.WillMeasurePage(test_page_set.pages[1])227 measurement_results.Add('a', 'seconds', 8)228 measurement_results.DidMeasurePage()229 measurement_results.AddSuccess(test_page_set.pages[1])230 measurement_results.PrintSummary()231 expected = ['RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +232 'Avg a_by_url: 7.500000seconds\n' +233 'Sd a_by_url: 0.707107seconds',234 'RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +235 'Avg a_by_url: 3.500000seconds\n' +236 'Sd a_by_url: 0.707107seconds',237 '*RESULT a: a= [3,7,4,8] seconds\n' +238 'Avg a: 5.500000seconds\n' +239 'Sd a: 2.380476seconds',240 'RESULT telemetry_page_measurement_results: ' +241 'num_failed= 0 count',242 'RESULT telemetry_page_measurement_results: ' +243 'num_errored= 0 count'244 ]245 self.assertEquals(expected, measurement_results.results)246 def test_repeated_pages(self):247 test_page_set = _MakePageSet()248 measurement_results = SummarySavingPageMeasurementResults()249 measurement_results.WillMeasurePage(test_page_set.pages[0])250 measurement_results.Add('a', 'seconds', 3)251 measurement_results.DidMeasurePage()252 measurement_results.AddSuccess(test_page_set.pages[0])253 measurement_results.WillMeasurePage(test_page_set.pages[0])254 measurement_results.Add('a', 'seconds', 4)255 measurement_results.DidMeasurePage()256 measurement_results.AddSuccess(test_page_set.pages[0])257 measurement_results.WillMeasurePage(test_page_set.pages[1])258 measurement_results.Add('a', 'seconds', 7)259 measurement_results.DidMeasurePage()260 measurement_results.AddSuccess(test_page_set.pages[1])261 measurement_results.WillMeasurePage(test_page_set.pages[1])262 measurement_results.Add('a', 'seconds', 8)263 measurement_results.DidMeasurePage()264 measurement_results.AddSuccess(test_page_set.pages[1])265 measurement_results.PrintSummary()266 expected = ['RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +267 'Avg a_by_url: 7.500000seconds\n' +268 'Sd a_by_url: 0.707107seconds',269 'RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +270 'Avg a_by_url: 3.500000seconds\n' +271 'Sd a_by_url: 0.707107seconds',272 '*RESULT a: a= [3,4,7,8] seconds\n' +273 'Avg a: 5.500000seconds\n' +274 'Sd a: 2.380476seconds',275 'RESULT telemetry_page_measurement_results: ' +276 'num_failed= 0 count',277 'RESULT telemetry_page_measurement_results: ' +278 'num_errored= 0 count'279 ]280 self.assertEquals(expected, measurement_results.results)281 def test_overall_results_trace_tag(self):282 test_page_set = _MakePageSet()283 measurement_results = SummarySavingPageMeasurementResults(trace_tag='_ref')284 measurement_results.AddSummary('a', 'seconds', 1)285 measurement_results.WillMeasurePage(test_page_set.pages[0])286 measurement_results.Add('b', 'seconds', 2)287 measurement_results.DidMeasurePage()288 measurement_results.AddSuccess(test_page_set.pages[0])289 measurement_results.WillMeasurePage(test_page_set.pages[1])290 measurement_results.Add('b', 'seconds', 3)291 measurement_results.DidMeasurePage()292 measurement_results.AddSuccess(test_page_set.pages[1])293 measurement_results.AddSummary('c', 'seconds', 4)294 measurement_results.PrintSummary()295 expected = [296 '*RESULT b: b_ref= [2,3] seconds\n' +297 'Avg b: 2.500000seconds\nSd b: 0.707107seconds',298 '*RESULT a: a_ref= 1 seconds',299 '*RESULT c: c_ref= 4 seconds',300 'RESULT telemetry_page_measurement_results: num_failed= 0 count',301 'RESULT telemetry_page_measurement_results: num_errored= 0 count']302 self.assertEquals(expected, measurement_results.results)303 def test_overall_results_page_runs_twice(self):304 test_page_set = _MakePageSet()305 measurement_results = SummarySavingPageMeasurementResults()306 measurement_results.AddSummary('a', 'seconds', 1)307 measurement_results.WillMeasurePage(test_page_set.pages[0])308 measurement_results.Add('b', 'seconds', 2)309 measurement_results.DidMeasurePage()310 measurement_results.AddSuccess(test_page_set.pages[0])311 measurement_results.WillMeasurePage(test_page_set.pages[0])312 measurement_results.Add('b', 'seconds', 3)313 measurement_results.DidMeasurePage()314 measurement_results.AddSuccess(test_page_set.pages[0])315 measurement_results.PrintSummary()316 expected = [317 'RESULT b_by_url: http___www.foo.com_= [2,3] seconds\n' +318 'Avg b_by_url: 2.500000seconds\nSd b_by_url: 0.707107seconds',319 '*RESULT b: b= [2,3] seconds\n' +320 'Avg b: 2.500000seconds\nSd b: 0.707107seconds',321 '*RESULT a: a= 1 seconds',322 'RESULT telemetry_page_measurement_results: num_failed= 0 count',323 'RESULT telemetry_page_measurement_results: num_errored= 0 count']324 self.assertEquals(expected, measurement_results.results)325 def test_unimportant_results(self):326 test_page_set = _MakePageSet()327 measurement_results = SummarySavingPageMeasurementResults()328 measurement_results.AddSummary('a', 'seconds', 1, data_type='unimportant')329 measurement_results.WillMeasurePage(test_page_set.pages[0])330 measurement_results.Add('b', 'seconds', 2, data_type='unimportant')331 measurement_results.DidMeasurePage()332 measurement_results.AddSuccess(test_page_set.pages[0])333 measurement_results.WillMeasurePage(test_page_set.pages[1])334 measurement_results.Add('b', 'seconds', 3, data_type='unimportant')335 measurement_results.DidMeasurePage()336 measurement_results.AddSuccess(test_page_set.pages[1])337 measurement_results.PrintSummary()338 self.assertEquals(339 measurement_results.results,340 ['RESULT b_by_url: http___www.bar.com_= 3 seconds',341 'RESULT b_by_url: http___www.foo.com_= 2 seconds',342 'RESULT b: b= [2,3] seconds\n' +343 'Avg b: 2.500000seconds\nSd b: 0.707107seconds',344 'RESULT a: a= 1 seconds',345 'RESULT telemetry_page_measurement_results: num_failed= 0 count',346 'RESULT telemetry_page_measurement_results: num_errored= 0 count'])347 def test_list_value(self):348 test_page_set = _MakePageSet()349 measurement_results = SummarySavingPageMeasurementResults()350 measurement_results.AddSummary('a', 'seconds', [1, 1])351 measurement_results.WillMeasurePage(test_page_set.pages[0])352 measurement_results.Add('b', 'seconds', [2, 2])353 measurement_results.DidMeasurePage()354 measurement_results.AddSuccess(test_page_set.pages[0])355 measurement_results.WillMeasurePage(test_page_set.pages[1])356 measurement_results.Add('b', 'seconds', [3, 3])357 measurement_results.DidMeasurePage()358 measurement_results.AddSuccess(test_page_set.pages[1])359 measurement_results.PrintSummary()360 expected = [361 'RESULT b_by_url: http___www.bar.com_= [3,3] seconds\n' +362 'Avg b_by_url: 3.000000seconds',363 'RESULT b_by_url: http___www.foo.com_= [2,2] seconds\n' +364 'Avg b_by_url: 2.000000seconds',365 '*RESULT b: b= [2,2,3,3] seconds\nAvg b: 2.500000seconds\n' +366 'Sd b: 0.577350seconds',367 '*RESULT a: a= [1,1] seconds\nAvg a: 1.000000seconds',368 'RESULT telemetry_page_measurement_results: num_failed= 0 count',369 'RESULT telemetry_page_measurement_results: num_errored= 0 count']370 self.assertEquals(expected, measurement_results.results)371 def test_histogram(self):372 test_page_set = _MakePageSet()373 measurement_results = SummarySavingPageMeasurementResults()374 measurement_results.WillMeasurePage(test_page_set.pages[0])375 measurement_results.Add('a', 'units',376 '{"buckets": [{"low": 1, "high": 2, "count": 1}]}',377 data_type='unimportant-histogram')378 measurement_results.DidMeasurePage()379 measurement_results.AddSuccess(test_page_set.pages[0])380 measurement_results.WillMeasurePage(test_page_set.pages[1])381 measurement_results.Add('a', 'units',382 '{"buckets": [{"low": 2, "high": 3, "count": 1}]}',383 data_type='unimportant-histogram')384 measurement_results.DidMeasurePage()385 measurement_results.AddSuccess(test_page_set.pages[1])386 measurement_results.PrintSummary()387 expected = [388 'HISTOGRAM a_by_url: http___www.bar.com_= ' +389 '{"buckets": [{"low": 2, "high": 3, "count": 1}]} units\n' +390 'Avg a_by_url: 2.500000units',391 'HISTOGRAM a_by_url: http___www.foo.com_= ' +392 '{"buckets": [{"low": 1, "high": 2, "count": 1}]} units\n' +393 'Avg a_by_url: 1.500000units',394 'RESULT telemetry_page_measurement_results: num_failed= 0 count',395 'RESULT telemetry_page_measurement_results: num_errored= 0 count']...

Full Screen

Full Screen

test_runner.py

Source:test_runner.py Github

copy

Full Screen

...83 message appropriate for the type of error84 @type printStatus: Boolean85 """86 self._calls.append('upDownError')87 def addSuccess(self, test):88 self._calls.append('addSuccess')89 def printErrors(self):90 pass91 def printSummary(self):92 pass93 def write(self, *args, **kw):94 pass95 def writeln(self, *args, **kw):96 pass97class TestImports(unittest.TestCase):98 def test_imports(self):99 from twisted.trial.runner import TrialRunner100class TestRunner(unittest.TestCase):101 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful