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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 fopen = fopen or self.fopen | 73 fopen = fopen or self.fopen |
74 os_path = os_path or self.repo | 74 os_path = os_path or self.repo |
75 glob = glob or self.glob | 75 glob = glob or self.glob |
76 return owners.Database(root, fopen, os_path, glob) | 76 return owners.Database(root, fopen, os_path, glob) |
77 | 77 |
78 | 78 |
79 class OwnersDatabaseTest(_BaseTestCase): | 79 class OwnersDatabaseTest(_BaseTestCase): |
80 def test_constructor(self): | 80 def test_constructor(self): |
81 self.assertNotEquals(self.db(), None) | 81 self.assertNotEquals(self.db(), None) |
82 | 82 |
83 def test_dirs_not_covered_by__valid_inputs(self): | 83 def test_files_not_covered_by__valid_inputs(self): |
84 db = self.db() | 84 db = self.db() |
85 | 85 |
86 # Check that we're passed in a sequence that isn't a string. | 86 # Check that we're passed in a sequence that isn't a string. |
87 self.assertRaises(AssertionError, db.directories_not_covered_by, 'foo', []) | 87 self.assertRaises(AssertionError, db.files_not_covered_by, 'foo', []) |
88 if hasattr(owners.collections, 'Iterable'): | 88 if hasattr(owners.collections, 'Iterable'): |
89 self.assertRaises(AssertionError, db.directories_not_covered_by, | 89 self.assertRaises(AssertionError, db.files_not_covered_by, |
90 (f for f in ['x', 'y']), []) | 90 (f for f in ['x', 'y']), []) |
91 | 91 |
92 # Check that the files are under the root. | 92 # Check that the files are under the root. |
93 db.root = '/checkout' | 93 db.root = '/checkout' |
94 self.assertRaises(AssertionError, db.directories_not_covered_by, | 94 self.assertRaises(AssertionError, db.files_not_covered_by, |
95 ['/OWNERS'], []) | 95 ['/OWNERS'], []) |
96 db.root = '/' | 96 db.root = '/' |
97 | 97 |
98 # Check invalid email address. | 98 # Check invalid email address. |
99 self.assertRaises(AssertionError, db.directories_not_covered_by, | 99 self.assertRaises(AssertionError, db.files_not_covered_by, |
100 ['OWNERS'], ['foo']) | 100 ['OWNERS'], ['foo']) |
101 | 101 |
102 def assert_dirs_not_covered_by(self, files, reviewers, unreviewed_dirs): | 102 def assert_files_not_covered_by(self, files, reviewers, unreviewed_files): |
103 db = self.db() | 103 db = self.db() |
104 self.assertEquals( | 104 self.assertEquals(db.files_not_covered_by(set(files), set(reviewers)), |
105 db.directories_not_covered_by(set(files), set(reviewers)), | 105 set(unreviewed_files)) |
106 set(unreviewed_dirs)) | |
107 | 106 |
108 def test_dirs_not_covered_by__owners_propagates_down(self): | 107 def test_files_not_covered_by__owners_propagates_down(self): |
109 self.assert_dirs_not_covered_by( | 108 self.assert_files_not_covered_by( |
110 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'], | 109 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'], |
111 [ben], []) | 110 [ben], []) |
112 | 111 |
113 def test_dirs_not_covered_by__partial_covering(self): | 112 def test_files_not_covered_by__partial_covering(self): |
114 self.assert_dirs_not_covered_by( | 113 self.assert_files_not_covered_by( |
115 ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'], | 114 ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'], |
116 [peter], ['content']) | 115 [peter], ['content/content.gyp']) |
117 | 116 |
118 def test_dirs_not_covered_by__set_noparent_works(self): | 117 def test_files_not_covered_by__set_noparent_works(self): |
119 self.assert_dirs_not_covered_by(['content/content.gyp'], [ben], | 118 self.assert_files_not_covered_by(['content/content.gyp'], [ben], |
120 ['content']) | 119 ['content/content.gyp']) |
121 | 120 |
122 def test_dirs_not_covered_by__no_reviewer(self): | 121 def test_files_not_covered_by__no_reviewer(self): |
123 self.assert_dirs_not_covered_by( | 122 self.assert_files_not_covered_by( |
124 ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'], | 123 ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'], |
125 [], ['content']) | 124 [], ['content/content.gyp']) |
126 | 125 |
127 def test_dirs_not_covered_by__combines_directories(self): | 126 def test_files_not_covered_by__combines_directories(self): |
128 self.assert_dirs_not_covered_by(['content/content.gyp', | 127 self.assert_files_not_covered_by(['content/content.gyp', |
129 'content/bar/foo.cc', | 128 'content/bar/foo.cc', |
130 'chrome/renderer/gpu/gpu_channel_host.h'], | 129 'chrome/renderer/gpu/gpu_channel_host.h'], |
131 [peter], | 130 [peter], |
132 ['content']) | 131 ['content/content.gyp', |
| 132 'content/bar/foo.cc']) |
133 | 133 |
134 def test_dirs_not_covered_by__multiple_directories(self): | 134 def test_files_not_covered_by__multiple_directories(self): |
135 self.assert_dirs_not_covered_by( | 135 self.assert_files_not_covered_by( |
136 ['content/content.gyp', # Not covered | 136 ['content/content.gyp', # Not covered |
137 'content/bar/foo.cc', # Not covered (combines in) | 137 'content/bar/foo.cc', # Not covered (combines in) |
138 'content/baz/froboz.h', # Not covered | 138 'content/baz/froboz.h', # Not covered |
139 'chrome/gpu/gpu_channel.h', # Owned by ken | 139 'chrome/gpu/gpu_channel.h', # Owned by ken |
140 'chrome/renderer/gpu/gpu_channel_host.h' # Owned by * via parent | 140 'chrome/renderer/gpu/gpu_channel_host.h' # Owned by * via parent |
141 ], | 141 ], |
142 [ken], | 142 [ken], |
143 ['content', 'content/baz']) | 143 ['content/content.gyp', 'content/bar/foo.cc', 'content/baz/froboz.h']) |
144 | 144 |
145 def test_per_file(self): | 145 def test_per_file(self): |
146 # brett isn't allowed to approve ugly.cc | 146 # brett isn't allowed to approve ugly.cc |
147 self.files['/content/baz/OWNERS'] = owners_file(brett, | 147 self.files['/content/baz/OWNERS'] = owners_file(brett, |
148 lines=['per-file ugly.*=tom@example.com']) | 148 lines=['per-file ugly.*=tom@example.com']) |
149 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 149 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
150 [brett], | 150 [brett], |
151 []) | 151 []) |
152 | 152 |
153 # tom is allowed to approve ugly.cc, but not froboz.h | 153 # tom is allowed to approve ugly.cc, but not froboz.h |
154 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 154 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
155 [tom], | 155 [tom], |
156 []) | 156 []) |
157 self.assert_dirs_not_covered_by(['content/baz/froboz.h'], | 157 self.assert_files_not_covered_by(['content/baz/froboz.h'], |
158 [tom], | 158 [tom], |
159 ['content/baz']) | 159 ['content/baz/froboz.h']) |
160 | 160 |
161 def test_per_file_with_spaces(self): | 161 def test_per_file_with_spaces(self): |
162 # This is the same as test_per_file(), except that we include spaces | 162 # This is the same as test_per_file(), except that we include spaces |
163 # on the per-file line. brett isn't allowed to approve ugly.cc; | 163 # on the per-file line. brett isn't allowed to approve ugly.cc; |
164 # tom is allowed to approve ugly.cc, but not froboz.h | 164 # tom is allowed to approve ugly.cc, but not froboz.h |
165 self.files['/content/baz/OWNERS'] = owners_file(brett, | 165 self.files['/content/baz/OWNERS'] = owners_file(brett, |
166 lines=['per-file ugly.* = tom@example.com']) | 166 lines=['per-file ugly.* = tom@example.com']) |
167 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 167 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
168 [brett], | 168 [brett], |
169 []) | 169 []) |
170 | 170 |
171 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 171 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
172 [tom], | 172 [tom], |
173 []) | 173 []) |
174 self.assert_dirs_not_covered_by(['content/baz/froboz.h'], | 174 self.assert_files_not_covered_by(['content/baz/froboz.h'], |
175 [tom], | 175 [tom], |
176 ['content/baz']) | 176 ['content/baz/froboz.h']) |
177 | 177 |
178 def test_per_file__set_noparent(self): | 178 def test_per_file__set_noparent(self): |
179 self.files['/content/baz/OWNERS'] = owners_file(brett, | 179 self.files['/content/baz/OWNERS'] = owners_file(brett, |
180 lines=['per-file ugly.*=tom@example.com', | 180 lines=['per-file ugly.*=tom@example.com', |
181 'per-file ugly.*=set noparent']) | 181 'per-file ugly.*=set noparent']) |
182 | 182 |
183 # brett isn't allowed to approve ugly.cc | 183 # brett isn't allowed to approve ugly.cc |
184 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 184 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
185 [brett], | 185 [brett], |
186 ['content/baz/ugly.cc']) | 186 ['content/baz/ugly.cc']) |
187 | 187 |
188 # tom is allowed to approve ugly.cc, but not froboz.h | 188 # tom is allowed to approve ugly.cc, but not froboz.h |
189 self.assert_dirs_not_covered_by(['content/baz/ugly.cc'], | 189 self.assert_files_not_covered_by(['content/baz/ugly.cc'], |
190 [tom], | 190 [tom], |
191 []) | 191 []) |
192 | 192 |
193 self.assert_dirs_not_covered_by(['content/baz/froboz.h'], | 193 self.assert_files_not_covered_by(['content/baz/froboz.h'], |
194 [tom], | 194 [tom], |
195 ['content/baz']) | 195 ['content/baz/froboz.h']) |
196 | 196 |
197 def test_per_file_wildcard(self): | 197 def test_per_file_wildcard(self): |
198 self.files['/OWNERS'] = 'per-file DEPS=*\n' | 198 self.files['/OWNERS'] = 'per-file DEPS=*\n' |
199 self.assert_dirs_not_covered_by(['DEPS'], [brett], []) | 199 self.assert_files_not_covered_by(['DEPS'], [brett], []) |
200 | 200 |
201 def test_mock_relpath(self): | 201 def test_mock_relpath(self): |
202 # This test ensures the mock relpath has the arguments in the right | 202 # This test ensures the mock relpath has the arguments in the right |
203 # order; this should probably live someplace else. | 203 # order; this should probably live someplace else. |
204 self.assertEquals(self.repo.relpath('foo/bar.c', 'foo/'), 'bar.c') | 204 self.assertEquals(self.repo.relpath('foo/bar.c', 'foo/'), 'bar.c') |
205 self.assertEquals(self.repo.relpath('/bar.c', '/'), 'bar.c') | 205 self.assertEquals(self.repo.relpath('/bar.c', '/'), 'bar.c') |
206 | 206 |
207 def test_per_file_glob_across_dirs_not_allowed(self): | 207 def test_per_file_glob_across_dirs_not_allowed(self): |
208 self.files['/OWNERS'] = 'per-file content/*=john@example.org\n' | 208 self.files['/OWNERS'] = 'per-file content/*=john@example.org\n' |
209 self.assertRaises(owners.SyntaxErrorInOwnersFile, | 209 self.assertRaises(owners.SyntaxErrorInOwnersFile, |
210 self.db().directories_not_covered_by, ['DEPS'], [brett]) | 210 self.db().files_not_covered_by, ['DEPS'], [brett]) |
211 | 211 |
212 def assert_syntax_error(self, owners_file_contents): | 212 def assert_syntax_error(self, owners_file_contents): |
213 db = self.db() | 213 db = self.db() |
214 self.files['/foo/OWNERS'] = owners_file_contents | 214 self.files['/foo/OWNERS'] = owners_file_contents |
215 self.files['/foo/DEPS'] = '' | 215 self.files['/foo/DEPS'] = '' |
216 try: | 216 try: |
217 db.reviewers_for(['foo/DEPS']) | 217 db.reviewers_for(['foo/DEPS']) |
218 self.fail() # pragma: no cover | 218 self.fail() # pragma: no cover |
219 except owners.SyntaxErrorInOwnersFile, e: | 219 except owners.SyntaxErrorInOwnersFile, e: |
220 self.assertTrue(str(e).startswith('/foo/OWNERS:1')) | 220 self.assertTrue(str(e).startswith('/foo/OWNERS:1')) |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ('chrome/browser', 2)], | 386 ('chrome/browser', 2)], |
387 ken: [('chrome/gpu', 1)], | 387 ken: [('chrome/gpu', 1)], |
388 peter: [('chrome/renderer', 1)], | 388 peter: [('chrome/renderer', 1)], |
389 brett: [('chrome/browser', 1)]}, | 389 brett: [('chrome/browser', 1)]}, |
390 ['chrome/gpu', 'chrome/renderer', | 390 ['chrome/gpu', 'chrome/renderer', |
391 'chrome/browser'], | 391 'chrome/browser'], |
392 ben) | 392 ben) |
393 | 393 |
394 if __name__ == '__main__': | 394 if __name__ == '__main__': |
395 unittest.main() | 395 unittest.main() |
OLD | NEW |