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

Side by Side Diff: scripts/master/unittests/annotator_test.py

Issue 10830251: Remove preamble link if annotated step has no extra sections. (Closed) Base URL: http://git.chromium.org/chromium/tools/build.git@master
Patch Set: Created 8 years, 4 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
« no previous file with comments | « scripts/master/chromium_step.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 test_env # pylint: disable=W0611 8 import test_env # pylint: disable=W0611
9 import unittest 9 import unittest
10 import mock # using third_party mock for now 10 import mock # using third_party mock for now
11 11
12 from twisted.internet import defer 12 from twisted.internet import defer
13 from buildbot.status import builder 13 from buildbot.status import builder
14 from master import chromium_step 14 from master import chromium_step
15 15
16 # Mocks confuse pylint. 16 # Mocks confuse pylint.
17 # pylint: disable=E1101 17 # pylint: disable=E1101
18 # pylint: disable=R0201 18 # pylint: disable=R0201
19 19
20 20
21 class FakeCommand(mock.Mock): 21 class FakeCommand(mock.Mock):
22 def addLog(self, ignored): 22 def __init__(self):
23 return mock.Mock() 23 self.rc = builder.SUCCESS
24 24 mock.Mock.__init__(self)
25 def getLogs(self):
26 return [mock.Mock()]
27 25
28 26
29 class FakeBuildStep(mock.Mock): 27 class FakeBuildStep(mock.Mock):
30 def __init__(self, name): 28 def __init__(self, name):
31 self.name = name 29 self.name = name
32 self.text = None 30 self.text = None
33 self.receivedStatus = [] 31 self.receivedStatus = []
34 self.urls = [] 32 self.step_status = None
35 mock.Mock.__init__(self) 33 mock.Mock.__init__(self)
36 34
35 def setStatus(self, status):
36 self.step_status = status
37
37 def addURL(self, label, url): 38 def addURL(self, label, url):
38 self.urls.append((label, url)) 39 self.step_status.addURL(label, url)
39 40
40 def stepStarted(self): 41 def stepStarted(self):
41 return mock.Mock() 42 return mock.Mock()
42 43
43 def addLog(self, ignored): 44 def addLog(self, logname):
44 return mock.Mock() 45 return self.step_status.addLog(logname)
46
47 def getURLs(self):
48 return self.step_status.getURLs()
45 49
46 def getLogs(self): 50 def getLogs(self):
47 return [mock.Mock()] 51 return self.step_status.getLogs()
48 52
49 def setText(self, text): 53 def setText(self, text):
50 self.text = text 54 self.text = text
51 55
52 def setText2(self, text): 56 def setText2(self, text):
53 self.text = text 57 self.text = text
54 58
55 def stepFinished(self, status): 59 def stepFinished(self, status):
56 self.receivedStatus.append(status) 60 self.receivedStatus.append(status)
57 61
(...skipping 13 matching lines...) Expand all
71 def addHeader(self, msg): 75 def addHeader(self, msg):
72 pass 76 pass
73 77
74 def finish(self): 78 def finish(self):
75 pass 79 pass
76 80
77 81
78 class FakeBuildstepStatus(mock.Mock): 82 class FakeBuildstepStatus(mock.Mock):
79 def __init__(self): 83 def __init__(self):
80 self.steps = [FakeBuildStep('init')] 84 self.steps = [FakeBuildStep('init')]
85 self.steps[0].setStatus(self)
81 self.receivedStatus = [] 86 self.receivedStatus = []
82 self.logs = {} 87 self.logs = []
88 self.urls = {}
83 mock.Mock.__init__(self) 89 mock.Mock.__init__(self)
84 90
85 def getBuild(self): 91 def getBuild(self):
86 return self 92 return self
87 93
88 def addStepWithName(self, step_name): 94 def addStepWithName(self, step_name):
89 newstep = FakeBuildStep(step_name) 95 newstep = FakeBuildStep(step_name)
96 newstep.setStatus(self)
90 self.steps.append(newstep) 97 self.steps.append(newstep)
91 return newstep 98 return newstep
92 99
93 def addLog(self, log): 100 def addLog(self, log):
94 l = FakeLog(log) 101 l = FakeLog(log)
95 self.logs[log] = l 102 self.logs.append(l)
96 return l 103 return l
97 104
105 def addURL(self, label, url):
106 self.urls[label] = url
107
108 def getURLs(self):
109 return self.urls.copy()
110
98 def getLogs(self): 111 def getLogs(self):
99 return self.logs.values() 112 return self.logs
100 113
101 def getLog(self, log): 114 def getLog(self, log):
102 if log in self.logs: 115 candidates = [x for x in self.logs if x.name == log]
103 return self.logs[log] 116 if candidates:
117 return candidates[0]
104 else: 118 else:
105 return None 119 return None
106 120
107 def stepFinished(self, status): 121 def stepFinished(self, status):
108 self.receivedStatus.append(status) 122 self.receivedStatus.append(status)
109 123
110 124
111 class AnnotatorCommandsTest(unittest.TestCase): 125 class AnnotatorCommandsTest(unittest.TestCase):
112 def setUp(self): 126 def setUp(self):
127 self.command = FakeCommand()
113 self.step = chromium_step.AnnotatedCommand(name='annotated_steps', 128 self.step = chromium_step.AnnotatedCommand(name='annotated_steps',
114 description='annotated_steps', 129 description='annotated_steps',
115 command=FakeCommand()) 130 command=self.command)
116 131
117 self.step_status = FakeBuildstepStatus() 132 self.step_status = FakeBuildstepStatus()
118 self.step.setStepStatus(self.step_status) 133 self.step.setStepStatus(self.step_status)
119 self.handleOutputLine = self.step.script_observer.handleOutputLine 134 self.handleOutputLine = self.step.script_observer.handleOutputLine
120 135
121 def testAddAnnotatedSteps(self): 136 def testAddAnnotatedSteps(self):
122 self.handleOutputLine('@@@BUILD_STEP step@@@') 137 self.handleOutputLine('@@@BUILD_STEP step@@@')
123 self.handleOutputLine('@@@BUILD_STEP step2@@@') 138 self.handleOutputLine('@@@BUILD_STEP step2@@@')
124 self.handleOutputLine('@@@BUILD_STEP done@@@') 139 self.handleOutputLine('@@@BUILD_STEP done@@@')
125 self.step.script_observer.handleReturnCode(0) 140 self.step.script_observer.handleReturnCode(0)
(...skipping 23 matching lines...) Expand all
149 164
150 statuses = [x['status'] for x in self.step.script_observer.sections] 165 statuses = [x['status'] for x in self.step.script_observer.sections]
151 166
152 self.assertEquals(statuses, [builder.EXCEPTION, builder.SUCCESS]) 167 self.assertEquals(statuses, [builder.EXCEPTION, builder.SUCCESS])
153 self.assertEquals(self.step.script_observer.annotate_status, 168 self.assertEquals(self.step.script_observer.annotate_status,
154 builder.EXCEPTION) 169 builder.EXCEPTION)
155 170
156 def testStepLink(self): 171 def testStepLink(self):
157 self.handleOutputLine('@@@STEP_LINK@label@http://localhost/@@@') 172 self.handleOutputLine('@@@STEP_LINK@label@http://localhost/@@@')
158 testurls = [('label', 'http://localhost/')] 173 testurls = [('label', 'http://localhost/')]
174 testurl_hash = {'label': 'http://localhost/'}
159 175
160 annotatedLinks = [x['links'] for x in self.step.script_observer.sections] 176 annotatedLinks = [x['links'] for x in self.step.script_observer.sections]
161 stepLinks = [x['step'].urls for x in self.step.script_observer.sections] 177 stepLinks = [x['step'].getURLs() for x in
178 self.step.script_observer.sections]
162 179
163 self.assertEquals(annotatedLinks, [testurls]) 180 self.assertEquals(annotatedLinks, [testurls])
164 self.assertEquals(stepLinks, [testurls]) 181 self.assertEquals(stepLinks, [testurl_hash])
165 182
166 def testStepWarning(self): 183 def testStepWarning(self):
167 self.handleOutputLine('@@@STEP_WARNINGS@@@') 184 self.handleOutputLine('@@@STEP_WARNINGS@@@')
168 self.handleOutputLine('@@@BUILD_STEP step@@@') 185 self.handleOutputLine('@@@BUILD_STEP step@@@')
169 186
170 statuses = [x['status'] for x in self.step.script_observer.sections] 187 statuses = [x['status'] for x in self.step.script_observer.sections]
171 188
172 self.assertEquals(statuses, [builder.WARNINGS, builder.SUCCESS]) 189 self.assertEquals(statuses, [builder.WARNINGS, builder.SUCCESS])
173 self.assertEquals(self.step.script_observer.annotate_status, 190 self.assertEquals(self.step.script_observer.annotate_status,
174 builder.WARNINGS) 191 builder.WARNINGS)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 self.handleOutputLine('@@@STEP_LOG_LINE@test_log@this is line one@@@') 265 self.handleOutputLine('@@@STEP_LOG_LINE@test_log@this is line one@@@')
249 self.handleOutputLine('@@@STEP_LOG_LINE@test_log@this is line two@@@') 266 self.handleOutputLine('@@@STEP_LOG_LINE@test_log@this is line two@@@')
250 self.handleOutputLine('@@@STEP_LOG_END@test_log@@@') 267 self.handleOutputLine('@@@STEP_LOG_END@test_log@@@')
251 268
252 logs = self.step_status.getLogs() 269 logs = self.step_status.getLogs()
253 self.assertEquals(len(logs), 2) 270 self.assertEquals(len(logs), 2)
254 self.assertEquals(logs[1].getName(), 'test_log') 271 self.assertEquals(logs[1].getName(), 'test_log')
255 self.assertEquals(self.step_status.getLog('test_log').text, 272 self.assertEquals(self.step_status.getLog('test_log').text,
256 'this is line one\nthis is line two') 273 'this is line one\nthis is line two')
257 274
275 def testForNoPreambleAfter1Step(self):
276 self.handleOutputLine('this line is part of the preamble')
277 self.step.commandComplete(self.command)
278 logs = self.step_status.getLogs()
279 # buildbot will append 'stdio' for the first non-annotated section
280 # but it won't show up in self.step_status.getLogs()
281 self.assertEquals(len(logs), 0)
282
283 def testForPreambleAfter2Steps(self):
284 self.handleOutputLine('this line is part of the preamble')
285 self.handleOutputLine('@@@BUILD_STEP step2@@@')
286 self.step.commandComplete(self.command)
287 logs = self.step_status.getLogs()
288 # annotator adds a stdio for each buildstep added
289 self.assertEquals([x.getName() for x in logs], ['preamble', 'stdio'])
290
291 def testForPreambleAfter3Steps(self):
292 self.handleOutputLine('this line is part of the preamble')
293 self.handleOutputLine('@@@BUILD_STEP step2@@@')
294 self.handleOutputLine('@@@BUILD_STEP step3@@@')
295 self.step.commandComplete(self.command)
296 logs = self.step_status.getLogs()
297 self.assertEquals([x.getName() for x in logs], ['preamble', 'stdio',
298 'stdio'])
258 299
259 if __name__ == '__main__': 300 if __name__ == '__main__':
260 unittest.main() 301 unittest.main()
OLDNEW
« no previous file with comments | « scripts/master/chromium_step.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698