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

Side by Side Diff: tests/owners_unittest.py

Issue 9621012: Show a list of directories missing OWNER reviewers on upload, and show directories rather than file… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Uncommented owners unit test Created 8 years, 9 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 """Unit tests for owners.py.""" 6 """Unit tests for owners.py."""
7 7
8 import os 8 import os
9 import sys 9 import sys
10 import unittest 10 import unittest
(...skipping 26 matching lines...) Expand all
37 '/OWNERS': owners_file(owners.EVERYONE), 37 '/OWNERS': owners_file(owners.EVERYONE),
38 '/base/vlog.h': '', 38 '/base/vlog.h': '',
39 '/chrome/OWNERS': owners_file(ben, brett), 39 '/chrome/OWNERS': owners_file(ben, brett),
40 '/chrome/gpu/OWNERS': owners_file(ken), 40 '/chrome/gpu/OWNERS': owners_file(ken),
41 '/chrome/gpu/gpu_channel.h': '', 41 '/chrome/gpu/gpu_channel.h': '',
42 '/chrome/renderer/OWNERS': owners_file(peter), 42 '/chrome/renderer/OWNERS': owners_file(peter),
43 '/chrome/renderer/gpu/gpu_channel_host.h': '', 43 '/chrome/renderer/gpu/gpu_channel_host.h': '',
44 '/chrome/renderer/safe_browsing/scorer.h': '', 44 '/chrome/renderer/safe_browsing/scorer.h': '',
45 '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True), 45 '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True),
46 '/content/content.gyp': '', 46 '/content/content.gyp': '',
47 '/content/bar/foo.cc': '',
47 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, 48 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE,
48 noparent=True), 49 noparent=True),
49 }) 50 })
50 51
51 52
52 class OwnersDatabaseTest(unittest.TestCase): 53 class OwnersDatabaseTest(unittest.TestCase):
53 def setUp(self): 54 def setUp(self):
54 self.repo = test_repo() 55 self.repo = test_repo()
55 self.files = self.repo.files 56 self.files = self.repo.files
56 self.root = '/' 57 self.root = '/'
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 # Check that the files are under the root. 122 # Check that the files are under the root.
122 db.root = '/checkout' 123 db.root = '/checkout'
123 self.assertRaises(AssertionError, db.files_not_covered_by, ['/OWNERS'], 124 self.assertRaises(AssertionError, db.files_not_covered_by, ['/OWNERS'],
124 []) 125 [])
125 db.root = '/' 126 db.root = '/'
126 127
127 # Check invalid email address. 128 # Check invalid email address.
128 self.assertRaises(AssertionError, db.files_not_covered_by, ['OWNERS'], 129 self.assertRaises(AssertionError, db.files_not_covered_by, ['OWNERS'],
129 ['foo']) 130 ['foo'])
130 131
132 def assert_dirs_not_covered_by(self, files, reviewers, unreviewed_dirs):
133 db = self.db()
134 self.assertEquals(
135 db.directories_not_covered_by(set(files), set(reviewers)),
136 set(unreviewed_dirs))
137
138 def test_dirs_not_covered_by__need_at_least_one_reviewer(self):
139 self.assert_dirs_not_covered_by(['DEPS'], [], [''])
140
141 def test_dirs_not_covered_by__owners_propagates_down(self):
142 self.assert_dirs_not_covered_by(
143 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'],
144 [ben], [])
145
146 def test_dirs_not_covered_by__partial_covering(self):
147 self.assert_dirs_not_covered_by(
148 ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'],
149 [peter], ['content'])
150
151 def test_dirs_not_covered_by__set_noparent_works(self):
152 self.assert_dirs_not_covered_by(['content/content.gyp'], [ben],
153 ['content'])
154
155 def test_dirs_not_covered_by__combines_directories(self):
156 self.assert_dirs_not_covered_by(['content/content.gyp',
157 'content/bar/foo.cc',
158 'chrome/renderer/gpu/gpu_channel_host.h'],
159 [peter],
160 ['content'])
161
162 def test_dirs_not_covered_by__multiple_directories(self):
163 self.assert_dirs_not_covered_by(['content/content.gyp',
164 'content/bar/foo.cc',
165 'chrome/renderer/gpu/gpu_channel_host.h'],
166 [ken],
167 ['content'])
168
131 169
132 def assert_reviewers_for(self, files, expected_reviewers): 170 def assert_reviewers_for(self, files, expected_reviewers):
133 db = self.db() 171 db = self.db()
134 self.assertEquals(db.reviewers_for(set(files)), set(expected_reviewers)) 172 self.assertEquals(db.reviewers_for(set(files)), set(expected_reviewers))
135 173
136 def test_reviewers_for__basic_functionality(self): 174 def test_reviewers_for__basic_functionality(self):
137 self.assert_reviewers_for(['chrome/gpu/gpu_channel.h'], 175 self.assert_reviewers_for(['chrome/gpu/gpu_channel.h'],
138 [ken, ben, brett, owners.EVERYONE]) 176 [ken, ben, brett, owners.EVERYONE])
139 177
140 def test_reviewers_for__set_noparent_works(self): 178 def test_reviewers_for__set_noparent_works(self):
(...skipping 30 matching lines...) Expand all
171 209
172 def test_syntax_error__unknown_set(self): 210 def test_syntax_error__unknown_set(self):
173 self.assert_syntax_error('set myfatherisbillgates\n') 211 self.assert_syntax_error('set myfatherisbillgates\n')
174 212
175 def test_syntax_error__bad_email(self): 213 def test_syntax_error__bad_email(self):
176 self.assert_syntax_error('ben\n') 214 self.assert_syntax_error('ben\n')
177 215
178 216
179 if __name__ == '__main__': 217 if __name__ == '__main__':
180 unittest.main() 218 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698