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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 '/content/views/pie.h': '', | 66 '/content/views/pie.h': '', |
67 }) | 67 }) |
68 | 68 |
69 | 69 |
70 class _BaseTestCase(unittest.TestCase): | 70 class _BaseTestCase(unittest.TestCase): |
71 def setUp(self): | 71 def setUp(self): |
72 self.repo = test_repo() | 72 self.repo = test_repo() |
73 self.files = self.repo.files | 73 self.files = self.repo.files |
74 self.root = '/' | 74 self.root = '/' |
75 self.fopen = self.repo.open_for_reading | 75 self.fopen = self.repo.open_for_reading |
76 self.glob = self.repo.glob | |
77 | 76 |
78 def db(self, root=None, fopen=None, os_path=None, glob=None): | 77 def db(self, root=None, fopen=None, os_path=None): |
79 root = root or self.root | 78 root = root or self.root |
80 fopen = fopen or self.fopen | 79 fopen = fopen or self.fopen |
81 os_path = os_path or self.repo | 80 os_path = os_path or self.repo |
82 glob = glob or self.glob | 81 return owners.Database(root, fopen, os_path) |
83 return owners.Database(root, fopen, os_path, glob) | |
84 | 82 |
85 | 83 |
86 class OwnersDatabaseTest(_BaseTestCase): | 84 class OwnersDatabaseTest(_BaseTestCase): |
87 def test_constructor(self): | 85 def test_constructor(self): |
88 self.assertNotEquals(self.db(), None) | 86 self.assertNotEquals(self.db(), None) |
89 | 87 |
90 def test_files_not_covered_by__valid_inputs(self): | 88 def test_files_not_covered_by__valid_inputs(self): |
91 db = self.db() | 89 db = self.db() |
92 | 90 |
93 # Check that we're passed in a sequence that isn't a string. | 91 # Check that we're passed in a sequence that isn't a string. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ['content/content.gyp', # Not covered | 141 ['content/content.gyp', # Not covered |
144 'content/bar/foo.cc', # Not covered (combines in) | 142 'content/bar/foo.cc', # Not covered (combines in) |
145 'content/baz/froboz.h', # Not covered | 143 'content/baz/froboz.h', # Not covered |
146 'chrome/gpu/gpu_channel.h', # Owned by ken | 144 'chrome/gpu/gpu_channel.h', # Owned by ken |
147 'chrome/renderer/gpu/gpu_channel_host.h' # Owned by * via parent | 145 'chrome/renderer/gpu/gpu_channel_host.h' # Owned by * via parent |
148 ], | 146 ], |
149 [ken], | 147 [ken], |
150 ['content/content.gyp', 'content/bar/foo.cc', 'content/baz/froboz.h']) | 148 ['content/content.gyp', 'content/bar/foo.cc', 'content/baz/froboz.h']) |
151 | 149 |
152 def test_per_file(self): | 150 def test_per_file(self): |
153 # brett isn't allowed to approve ugly.cc | |
154 self.files['/content/baz/OWNERS'] = owners_file(brett, | 151 self.files['/content/baz/OWNERS'] = owners_file(brett, |
155 lines=['per-file ugly.*=tom@example.com']) | 152 lines=['per-file ugly.*=tom@example.com']) |
| 153 |
| 154 # peter isn't allowed to approve ugly.cc |
| 155 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
| 156 [peter], |
| 157 ['content/baz/ugly.cc']) |
| 158 |
| 159 # brett is allowed to approve ugly.cc |
156 self.assert_files_not_covered_by(['content/baz/ugly.cc'], | 160 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
157 [brett], | 161 [brett], |
158 []) | 162 []) |
159 | 163 |
160 # tom is allowed to approve ugly.cc, but not froboz.h | 164 # tom is allowed to approve ugly.cc, but not froboz.h |
161 self.assert_files_not_covered_by(['content/baz/ugly.cc'], | 165 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
162 [tom], | 166 [tom], |
163 []) | 167 []) |
164 self.assert_files_not_covered_by(['content/baz/froboz.h'], | 168 self.assert_files_not_covered_by(['content/baz/froboz.h'], |
165 [tom], | 169 [tom], |
166 ['content/baz/froboz.h']) | 170 ['content/baz/froboz.h']) |
167 | 171 |
168 def test_per_file_with_spaces(self): | 172 def test_per_file_with_spaces(self): |
169 # This is the same as test_per_file(), except that we include spaces | 173 # This is the same as test_per_file(), except that we include spaces |
170 # on the per-file line. brett isn't allowed to approve ugly.cc; | 174 # on the per-file line. |
171 # tom is allowed to approve ugly.cc, but not froboz.h | 175 # tom is allowed to approve ugly.cc, but not froboz.h |
172 self.files['/content/baz/OWNERS'] = owners_file(brett, | 176 self.files['/content/baz/OWNERS'] = owners_file(brett, |
173 lines=['per-file ugly.* = tom@example.com']) | 177 lines=['per-file ugly.* = tom@example.com']) |
| 178 |
| 179 # peter isn't allowed to approve ugly.cc |
| 180 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
| 181 [peter], |
| 182 ['content/baz/ugly.cc']) |
| 183 |
| 184 # brett is allowed to approve ugly.cc |
174 self.assert_files_not_covered_by(['content/baz/ugly.cc'], | 185 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
175 [brett], | 186 [brett], |
176 []) | 187 []) |
177 | 188 |
| 189 # tom is allowed to approve ugly.cc, but not froboz.h |
178 self.assert_files_not_covered_by(['content/baz/ugly.cc'], | 190 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
179 [tom], | 191 [tom], |
180 []) | 192 []) |
181 self.assert_files_not_covered_by(['content/baz/froboz.h'], | 193 self.assert_files_not_covered_by(['content/baz/froboz.h'], |
182 [tom], | 194 [tom], |
183 ['content/baz/froboz.h']) | 195 ['content/baz/froboz.h']) |
184 | 196 |
| 197 def test_per_file_with_nonexistent_file(self): |
| 198 self.files['/content/baz/OWNERS'] = owners_file(brett, |
| 199 lines=['per-file ugly.*=tom@example.com']) |
| 200 |
| 201 # peter isn't allowed to approve ugly.nonexistent.cc, but brett and tom are. |
| 202 self.assert_files_not_covered_by(['content/baz/ugly.nonexistent.cc'], |
| 203 [peter], |
| 204 ['content/baz/ugly.nonexistent.cc']) |
| 205 self.assert_files_not_covered_by(['content/baz/ugly.nonexistent.cc'], |
| 206 [brett], |
| 207 []) |
| 208 self.assert_files_not_covered_by(['content/baz/ugly.nonexistent.cc'], |
| 209 [tom], |
| 210 []) |
| 211 |
185 def test_per_file__set_noparent(self): | 212 def test_per_file__set_noparent(self): |
186 self.files['/content/baz/OWNERS'] = owners_file(brett, | 213 self.files['/content/baz/OWNERS'] = owners_file(brett, |
187 lines=['per-file ugly.*=tom@example.com', | 214 lines=['per-file ugly.*=tom@example.com', |
188 'per-file ugly.*=set noparent']) | 215 'per-file ugly.*=set noparent']) |
189 | 216 |
190 # brett isn't allowed to approve ugly.cc | 217 # brett isn't allowed to approve ugly.cc |
191 self.assert_files_not_covered_by(['content/baz/ugly.cc'], | 218 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
192 [brett], | 219 [brett], |
193 ['content/baz/ugly.cc']) | 220 ['content/baz/ugly.cc']) |
194 | 221 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 ('chrome/browser', 2)], | 512 ('chrome/browser', 2)], |
486 ken: [('chrome/gpu', 1)], | 513 ken: [('chrome/gpu', 1)], |
487 peter: [('chrome/renderer', 1)], | 514 peter: [('chrome/renderer', 1)], |
488 brett: [('chrome/browser', 1)]}, | 515 brett: [('chrome/browser', 1)]}, |
489 ['chrome/gpu', 'chrome/renderer', | 516 ['chrome/gpu', 'chrome/renderer', |
490 'chrome/browser'], | 517 'chrome/browser'], |
491 ben) | 518 ben) |
492 | 519 |
493 if __name__ == '__main__': | 520 if __name__ == '__main__': |
494 unittest.main() | 521 unittest.main() |
OLD | NEW |