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 """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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/bar/foo.cc': '', |
48 '/content/baz/OWNERS': owners_file(brett), | 48 '/content/baz/OWNERS': owners_file(brett), |
49 '/content/baz/froboz.h': '', | 49 '/content/baz/froboz.h': '', |
50 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, | 50 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, |
51 noparent=True), | 51 noparent=True), |
| 52 '/content/views/pie.h': '', |
52 }) | 53 }) |
53 | 54 |
54 | 55 |
55 class OwnersDatabaseTest(unittest.TestCase): | 56 class OwnersDatabaseTest(unittest.TestCase): |
56 def setUp(self): | 57 def setUp(self): |
57 self.repo = test_repo() | 58 self.repo = test_repo() |
58 self.files = self.repo.files | 59 self.files = self.repo.files |
59 self.root = '/' | 60 self.root = '/' |
60 self.fopen = self.repo.open_for_reading | 61 self.fopen = self.repo.open_for_reading |
61 | 62 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 self.assertRaises(AssertionError, db.reviewers_for, | 151 self.assertRaises(AssertionError, db.reviewers_for, |
151 (f for f in ['x', 'y'])) | 152 (f for f in ['x', 'y'])) |
152 | 153 |
153 # Check that the files are under the root. | 154 # Check that the files are under the root. |
154 db.root = '/checkout' | 155 db.root = '/checkout' |
155 self.assertRaises(AssertionError, db.reviewers_for, ['/OWNERS']) | 156 self.assertRaises(AssertionError, db.reviewers_for, ['/OWNERS']) |
156 | 157 |
157 def test_reviewers_for__wildcard_dir(self): | 158 def test_reviewers_for__wildcard_dir(self): |
158 self.assert_reviewers_for(['DEPS'], [owners.EVERYONE]) | 159 self.assert_reviewers_for(['DEPS'], [owners.EVERYONE]) |
159 | 160 |
| 161 def test_reviewers_for__one_owner(self): |
| 162 self.assert_reviewers_for([ |
| 163 '/chrome/gpu/gpu_channel.h', |
| 164 '/content/baz/froboz.h', |
| 165 '/chrome/renderer/gpu/gpu_channel_host.h'], [brett]) |
| 166 |
| 167 def test_reviewers_for__two_owners(self): |
| 168 self.assert_reviewers_for([ |
| 169 '/chrome/gpu/gpu_channel.h', |
| 170 '/content/content.gyp', |
| 171 '/content/baz/froboz.h', |
| 172 '/content/views/pie.h' |
| 173 ], [john, brett]) |
| 174 |
| 175 def test_reviewers_for__all_files(self): |
| 176 self.assert_reviewers_for([ |
| 177 '/chrome/gpu/gpu_channel.h', |
| 178 '/chrome/renderer/gpu/gpu_channel_host.h', |
| 179 '/chrome/renderer/safe_browsing/scorer.h', |
| 180 '/content/content.gyp', |
| 181 '/content/bar/foo.cc', |
| 182 '/content/baz/froboz.h', |
| 183 '/content/views/pie.h'], [john, brett]) |
| 184 |
160 def assert_syntax_error(self, owners_file_contents): | 185 def assert_syntax_error(self, owners_file_contents): |
161 db = self.db() | 186 db = self.db() |
162 self.files['/foo/OWNERS'] = owners_file_contents | 187 self.files['/foo/OWNERS'] = owners_file_contents |
163 self.files['/foo/DEPS'] = '' | 188 self.files['/foo/DEPS'] = '' |
164 try: | 189 try: |
165 db.reviewers_for(['/foo/DEPS']) | 190 db.reviewers_for(['/foo/DEPS']) |
166 self.fail() # pragma: no cover | 191 self.fail() # pragma: no cover |
167 except owners.SyntaxErrorInOwnersFile, e: | 192 except owners.SyntaxErrorInOwnersFile, e: |
168 self.assertTrue(str(e).startswith('/foo/OWNERS:1')) | 193 self.assertTrue(str(e).startswith('/foo/OWNERS:1')) |
169 | 194 |
170 def test_syntax_error__unknown_token(self): | 195 def test_syntax_error__unknown_token(self): |
171 self.assert_syntax_error('{}\n') | 196 self.assert_syntax_error('{}\n') |
172 | 197 |
173 def test_syntax_error__unknown_set(self): | 198 def test_syntax_error__unknown_set(self): |
174 self.assert_syntax_error('set myfatherisbillgates\n') | 199 self.assert_syntax_error('set myfatherisbillgates\n') |
175 | 200 |
176 def test_syntax_error__bad_email(self): | 201 def test_syntax_error__bad_email(self): |
177 self.assert_syntax_error('ben\n') | 202 self.assert_syntax_error('ben\n') |
178 | 203 |
179 | 204 |
180 if __name__ == '__main__': | 205 if __name__ == '__main__': |
181 unittest.main() | 206 unittest.main() |
OLD | NEW |