| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ Source file for annotated command testcases.""" | 6 """ Source file for annotated command testcases.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import time | 9 import time |
| 10 import unittest | 10 import unittest |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 def finish(self): | 65 def finish(self): |
| 66 self.finished = True | 66 self.finished = True |
| 67 | 67 |
| 68 | 68 |
| 69 class FakeBuildstepStatus(mock.Mock): | 69 class FakeBuildstepStatus(mock.Mock): |
| 70 def __init__(self, name, build): | 70 def __init__(self, name, build): |
| 71 mock.Mock.__init__(self) | 71 mock.Mock.__init__(self) |
| 72 self.name = name | 72 self.name = name |
| 73 self.urls = {} | 73 self.urls = {} |
| 74 self.aliases = {} |
| 74 self.build = build | 75 self.build = build |
| 75 self.text = None | 76 self.text = None |
| 76 self.step = None | 77 self.step = None |
| 77 self.logs = [] | 78 self.logs = [] |
| 78 self.started = False | 79 self.started = False |
| 79 self.finished = False | 80 self.finished = False |
| 80 | 81 |
| 81 def stepStarted(self): | 82 def stepStarted(self): |
| 82 self.started = True | 83 self.started = True |
| 83 | 84 |
| 84 def isStarted(self): | 85 def isStarted(self): |
| 85 return self.started | 86 return self.started |
| 86 | 87 |
| 87 def setText(self, text): | 88 def setText(self, text): |
| 88 self.text = text | 89 self.text = text |
| 89 | 90 |
| 90 def setText2(self, text): | 91 def setText2(self, text): |
| 91 self.text = text | 92 self.text = text |
| 92 | 93 |
| 93 def getBuild(self): | 94 def getBuild(self): |
| 94 return self.build | 95 return self.build |
| 95 | 96 |
| 96 def getURLs(self): | 97 def getURLs(self): |
| 97 return self.urls.copy() | 98 return self.urls.copy() |
| 98 | 99 |
| 100 def getAliases(self): |
| 101 return self.aliases.copy() |
| 102 |
| 99 def addURL(self, label, url): | 103 def addURL(self, label, url): |
| 100 self.urls[label] = url | 104 self.urls[label] = url |
| 101 | 105 |
| 106 def addAlias(self, label, url, text=None): |
| 107 self.aliases.setdefault(label, []).append((text, url)) |
| 108 |
| 102 def addLog(self, log): | 109 def addLog(self, log): |
| 103 l = FakeLog(log) | 110 l = FakeLog(log) |
| 104 self.logs.append(l) | 111 self.logs.append(l) |
| 105 return l | 112 return l |
| 106 | 113 |
| 107 def getLogs(self): | 114 def getLogs(self): |
| 108 return self.logs | 115 return self.logs |
| 109 | 116 |
| 110 def getLog(self, log): | 117 def getLog(self, log): |
| 111 candidates = [x for x in self.logs if x.name == log] | 118 candidates = [x for x in self.logs if x.name == log] |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 self.handleOutputLine('@@@BUILD_STEP step@@@') | 217 self.handleOutputLine('@@@BUILD_STEP step@@@') |
| 211 | 218 |
| 212 statuses = [x['status'] for x in self.step.script_observer.sections] | 219 statuses = [x['status'] for x in self.step.script_observer.sections] |
| 213 | 220 |
| 214 self.assertEquals(statuses, [builder.EXCEPTION, builder.SUCCESS]) | 221 self.assertEquals(statuses, [builder.EXCEPTION, builder.SUCCESS]) |
| 215 self.assertEquals(self.step.script_observer.annotate_status, | 222 self.assertEquals(self.step.script_observer.annotate_status, |
| 216 builder.EXCEPTION) | 223 builder.EXCEPTION) |
| 217 | 224 |
| 218 def testStepLink(self): | 225 def testStepLink(self): |
| 219 self.handleOutputLine('@@@STEP_LINK@label@http://localhost/@@@') | 226 self.handleOutputLine('@@@STEP_LINK@label@http://localhost/@@@') |
| 220 testurls = [('label', 'http://localhost/')] | 227 testurls = [('label', 'http://localhost/', None)] |
| 221 testurl_hash = {'label': 'http://localhost/'} | 228 testurl_hash = {'label': 'http://localhost/'} |
| 222 | 229 |
| 223 annotatedLinks = [x['links'] for x in self.step.script_observer.sections] | 230 annotatedLinks = [x['links'] for x in self.step.script_observer.sections] |
| 224 stepLinks = [x['step'].getURLs() for x in | 231 stepLinks = [x['step'].getURLs() for x in |
| 225 self.step.script_observer.sections] | 232 self.step.script_observer.sections] |
| 226 | 233 |
| 227 self.assertEquals(annotatedLinks, [testurls]) | 234 self.assertEquals(annotatedLinks, [testurls]) |
| 228 self.assertEquals(stepLinks, [testurl_hash]) | 235 self.assertEquals(stepLinks, [testurl_hash]) |
| 229 | 236 |
| 237 def testStepAlias(self): |
| 238 self.handleOutputLine('@@@STEP_LINK@alias-->label@http://localhost/@@@') |
| 239 testurls = [('label', 'http://localhost/', 'alias')] |
| 240 testalias_hash = {'label': [('alias', 'http://localhost/')]} |
| 241 |
| 242 annotatedLinks = [x['links'] for x in self.step.script_observer.sections] |
| 243 stepAliases = [x['step'].getAliases() for x in |
| 244 self.step.script_observer.sections] |
| 245 |
| 246 self.assertEquals(annotatedLinks, [testurls]) |
| 247 self.assertEquals(stepAliases, [testalias_hash]) |
| 248 |
| 230 def testStepWarning(self): | 249 def testStepWarning(self): |
| 231 self.handleOutputLine('@@@STEP_WARNINGS@@@') | 250 self.handleOutputLine('@@@STEP_WARNINGS@@@') |
| 232 self.handleOutputLine('@@@BUILD_STEP step@@@') | 251 self.handleOutputLine('@@@BUILD_STEP step@@@') |
| 233 | 252 |
| 234 statuses = [x['status'] for x in self.step.script_observer.sections] | 253 statuses = [x['status'] for x in self.step.script_observer.sections] |
| 235 | 254 |
| 236 self.assertEquals(statuses, [builder.WARNINGS, builder.SUCCESS]) | 255 self.assertEquals(statuses, [builder.WARNINGS, builder.SUCCESS]) |
| 237 self.assertEquals(self.step.script_observer.annotate_status, | 256 self.assertEquals(self.step.script_observer.annotate_status, |
| 238 builder.WARNINGS) | 257 builder.WARNINGS) |
| 239 | 258 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 self.handleOutputLine('@@@STEP_CURSOR annotated_steps@@@') | 574 self.handleOutputLine('@@@STEP_CURSOR annotated_steps@@@') |
| 556 self.handleOutputLine('@@@STEP_CLOSED@@@') | 575 self.handleOutputLine('@@@STEP_CLOSED@@@') |
| 557 | 576 |
| 558 self.step.script_observer.handleReturnCode(0) | 577 self.step.script_observer.handleReturnCode(0) |
| 559 | 578 |
| 560 self.assertNothingToWait() | 579 self.assertNothingToWait() |
| 561 | 580 |
| 562 | 581 |
| 563 if __name__ == '__main__': | 582 if __name__ == '__main__': |
| 564 unittest.main() | 583 unittest.main() |
| OLD | NEW |