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

Side by Side Diff: tests/owners_finder_test.py

Issue 12712002: An interactive tool to help find owners covering current change list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix style Created 7 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 | Annotate | Revision Log
« owners.py ('K') | « owners_finder.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
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for owners_finder.py."""
7
8 import os
9 import sys
10 import unittest
11
12
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14
15 from testing_support import filesystem_mock
16
17 import owners_finder
18 import owners
19
20
21 ben = 'ben@example.com'
22 brett = 'brett@example.com'
23 darin = 'darin@example.com'
24 john = 'john@example.com'
25 ken = 'ken@example.com'
26 peter = 'peter@example.com'
27 tom = 'tom@example.com'
28
29
30 def owners_file(*email_addresses, **kwargs):
31 s = ''
32 if kwargs.get('comment'):
33 s += '# %s\n' % kwargs.get('comment')
34 if kwargs.get('noparent'):
35 s += 'set noparent\n'
36 s += '\n'.join(kwargs.get('lines', [])) + '\n'
37 return s + '\n'.join(email_addresses) + '\n'
38
39
40 def test_repo():
41 return filesystem_mock.MockFileSystem(files={
42 '/DEPS': '',
43 '/OWNERS': owners_file(ken, peter, tom),
44 '/base/vlog.h': '',
45 '/chrome/OWNERS': owners_file(ben, brett),
46 '/chrome/browser/OWNERS': owners_file(brett),
47 '/chrome/browser/defaults.h': '',
48 '/chrome/gpu/OWNERS': owners_file(ken),
49 '/chrome/gpu/gpu_channel.h': '',
50 '/chrome/renderer/OWNERS': owners_file(peter),
51 '/chrome/renderer/gpu/gpu_channel_host.h': '',
52 '/chrome/renderer/safe_browsing/scorer.h': '',
53 '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True),
54 '/content/content.gyp': '',
55 '/content/bar/foo.cc': '',
56 '/content/baz/OWNERS': owners_file(brett),
57 '/content/baz/froboz.h': '',
58 '/content/baz/ugly.cc': '',
59 '/content/baz/ugly.h': '',
60 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE,
61 noparent=True),
62 '/content/views/pie.h': '',
63 })
64
65
66 class OutputInterceptedOwnersFinder(owners_finder.OwnersFinder):
67 def __init__(self, files, local_root,
68 fopen, os_path, glob,
69 disable_color=False):
70 super(OutputInterceptedOwnersFinder, self).__init__(
71 files, local_root, fopen, os_path, glob, disable_color=disable_color)
72 self.output = []
73 self.indentation_stack = []
74
75 def resetText(self):
76 self.output = []
77 self.indentation_stack = []
78
79 def indent(self):
80 self.indentation_stack.append(self.output)
81 self.output = []
82
83 def unindent(self):
84 block = self.output
85 self.output = self.indentation_stack.pop()
86 self.output.append(block)
87
88 def writeln(self, text=''):
89 self.output.append(text)
90
91
92 class _BaseTestCase(unittest.TestCase):
93 default_files = [
94 'base/vlog.h',
95 'chrome/browser/defaults.h',
96 'chrome/gpu/gpu_channel.h',
97 'chrome/renderer/gpu/gpu_channel_host.h',
98 'chrome/renderer/safe_browsing/scorer.h',
99 'content/content.gyp',
100 'content/bar/foo.cc',
101 'content/baz/ugly.cc',
102 'content/baz/ugly.h',
103 'content/views/pie.h'
104 ]
105
106 def setUp(self):
107 self.repo = test_repo()
108 self.root = '/'
109 self.fopen = self.repo.open_for_reading
110 self.glob = self.repo.glob
111
112 def ownersFinder(self, files):
113 finder = OutputInterceptedOwnersFinder(files, self.root,
114 fopen=self.fopen,
115 os_path=self.repo,
116 glob=self.glob,
117 disable_color=True)
118 return finder
119
120 def defaultFinder(self):
121 return self.ownersFinder(self.default_files)
122
123
124 class OwnersFinderTests(_BaseTestCase):
125 def test_constructor(self):
126 self.assertNotEquals(self.defaultFinder(), None)
127
128 def test_reset(self):
129 finder = self.defaultFinder()
130 i = 0
131 while i < 2:
132 i += 1
133 self.assertEqual(finder.owners_queue,
134 [brett, peter, ken, tom, john, darin, ben])
135 self.assertEqual(finder.unreviewed_files, {
136 'base/vlog.h',
137 'chrome/browser/defaults.h',
138 'chrome/gpu/gpu_channel.h',
139 'chrome/renderer/gpu/gpu_channel_host.h',
140 'chrome/renderer/safe_browsing/scorer.h',
141 'content/content.gyp',
142 'content/bar/foo.cc',
143 'content/baz/ugly.cc',
144 'content/baz/ugly.h'
145 })
146 self.assertEqual(finder.selected_owners, set())
147 self.assertEqual(finder.deselected_owners, set())
148 self.assertEqual(finder.reviewed_by, {})
149 self.assertEqual(finder.output, [])
150
151 finder.select_owner(john)
152 finder.reset()
153 finder.resetText()
154
155 def test_select(self):
156 finder = self.defaultFinder()
157 finder.select_owner(john)
158 self.assertEqual(finder.owners_queue, [brett, peter, ken, tom, ben])
159 self.assertEqual(finder.selected_owners, {john})
160 self.assertEqual(finder.deselected_owners, {darin})
161 self.assertEqual(finder.reviewed_by, {'content/bar/foo.cc': john,
162 'content/baz/ugly.cc': john,
163 'content/baz/ugly.h': john,
164 'content/content.gyp': john})
165 self.assertEqual(finder.output,
166 ['Selected: ' + john, 'Deselected: ' + darin])
167
168 finder = self.defaultFinder()
169 finder.select_owner(darin)
170 self.assertEqual(finder.owners_queue, [brett, peter, ken, tom, ben])
171 self.assertEqual(finder.selected_owners, {darin})
172 self.assertEqual(finder.deselected_owners, {john})
173 self.assertEqual(finder.reviewed_by, {'content/bar/foo.cc': darin,
174 'content/baz/ugly.cc': darin,
175 'content/baz/ugly.h': darin,
176 'content/content.gyp': darin})
177 self.assertEqual(finder.output,
178 ['Selected: ' + darin, 'Deselected: ' + john])
179
180 finder = self.defaultFinder()
181 finder.select_owner(brett)
182 self.assertEqual(finder.owners_queue, [peter, ken, tom, john, darin])
183 self.assertEqual(finder.selected_owners, {brett})
184 self.assertEqual(finder.deselected_owners, {ben})
185 self.assertEqual(finder.reviewed_by,
186 {'chrome/browser/defaults.h': brett,
187 'chrome/gpu/gpu_channel.h': brett,
188 'chrome/renderer/gpu/gpu_channel_host.h': brett,
189 'chrome/renderer/safe_browsing/scorer.h': brett,
190 'content/baz/ugly.cc': brett,
191 'content/baz/ugly.h': brett})
192 self.assertEqual(finder.output,
193 ['Selected: ' + brett, 'Deselected: ' + ben])
194
195 def test_deselect(self):
196 finder = self.defaultFinder()
197 finder.deselect_owner(john)
198 self.assertEqual(finder.owners_queue, [brett, peter, ken, tom, ben])
199 self.assertEqual(finder.selected_owners, {darin})
200 self.assertEqual(finder.deselected_owners, {john})
201 self.assertEqual(finder.reviewed_by, {'content/bar/foo.cc': darin,
202 'content/baz/ugly.cc': darin,
203 'content/baz/ugly.h': darin,
204 'content/content.gyp': darin})
205 self.assertEqual(finder.output,
206 ['Deselected: ' + john, 'Selected: ' + darin])
207
208 def test_print_file_info(self):
209 finder = self.defaultFinder()
210 finder.print_file_info('chrome/browser/defaults.h')
211 self.assertEqual(finder.output, ['chrome/browser/defaults.h [5]'])
212 finder.resetText()
213
214 finder.print_file_info('chrome/renderer/gpu/gpu_channel_host.h')
215 self.assertEqual(finder.output,
216 ['chrome/renderer/gpu/gpu_channel_host.h [5]'])
217
218 def test_print_file_info_detailed(self):
219 finder = self.defaultFinder()
220 finder.print_file_info_detailed('chrome/browser/defaults.h')
221 self.assertEqual(finder.output,
222 ['chrome/browser/defaults.h',
223 [ben, brett, ken, peter, tom]])
224 finder.resetText()
225
226 finder.print_file_info_detailed('chrome/renderer/gpu/gpu_channel_host.h')
227 self.assertEqual(finder.output,
228 ['chrome/renderer/gpu/gpu_channel_host.h',
229 [ben, brett, ken, peter, tom]])
230
231 def test_print_comments(self):
232 finder = self.defaultFinder()
233 finder.print_comments(darin)
234 self.assertEqual(finder.output,
235 [darin + ' is commented as:', ['foo (at content)']])
236
237
238 if __name__ == '__main__':
239 unittest.main()
OLDNEW
« owners.py ('K') | « owners_finder.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698