Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Unit tests for owners.py.""" | |
| 7 | |
| 8 import unittest | |
| 9 import filesystem_mock | |
| 10 | |
| 11 import owners | |
| 12 | |
| 13 | |
| 14 def test_repo(): | |
| 15 return filesystem_mock.MockFileSystem(files={ | |
| 16 '/DEPS' : | |
| 17 '# DEPS\n', | |
| 18 '/OWNERS': | |
| 19 ('# OWNERS' | |
| 20 '*\n'), | |
| 21 '/base/vlog.h': | |
| 22 '// vlog.h\n', | |
| 23 '/chrome/OWNERS': | |
| 24 ('ben@chromium.org\n' | |
| 25 'brettw@chromium.org\n'), | |
| 26 '/chrome/gpu/OWNERS': | |
| 27 ('kbr@chromium.org\n'), | |
| 28 '/chrome/gpu/gpu_channel.h': | |
| 29 '// gpu_channel.h\n', | |
| 30 '/chrome/renderer/OWNERS': | |
| 31 ('pkasting@chromium.org\n'), | |
| 32 '/chrome/renderer/gpu/gpu_channel_host.h': | |
| 33 '// gpu_channel_host.h\n', | |
| 34 '/chrome/renderer/safe_browsing/scorer.h': | |
| 35 '// scorer.h\n', | |
| 36 '/content/OWNERS': | |
| 37 ('set noparent\n' | |
| 38 'jam@chromium.org\n' | |
| 39 'darin@chromium.org\n'), | |
| 40 '/content/content.gyp': | |
| 41 '# content.gyp\n', | |
| 42 }) | |
| 43 | |
| 44 | |
| 45 ben = 'ben@chromium.org' | |
|
M-A Ruel
2011/03/03 16:20:46
Use example.com
| |
| 46 brett = 'brettw@chromium.org' | |
| 47 darin = 'darin@chromium.org' | |
| 48 jam = 'jam@chromium.org' | |
| 49 kbr = 'kbr@chromium.org' | |
| 50 pkasting = 'pkasting@chromium.org' | |
| 51 | |
| 52 | |
| 53 class OwnersDatabaseTest(unittest.TestCase): | |
| 54 def setUp(self): | |
| 55 self.repo = test_repo() | |
| 56 self.files = self.repo.files | |
| 57 self.root = '/' | |
| 58 | |
| 59 # pylint: disable=W0108 | |
| 60 self.fopen = lambda path: self.repo.open_for_reading(path) | |
| 61 | |
| 62 def db(self, root=None, fopen=None, os_path=None): | |
| 63 root = root or self.root | |
| 64 fopen = fopen or self.fopen | |
| 65 os_path = os_path or self.repo | |
| 66 return owners.Database(root, fopen, os_path) | |
| 67 | |
| 68 def assertReviewersFor(self, files, expected_reviewers): | |
| 69 db = self.db() | |
| 70 self.assertEquals(db.ReviewersFor(set(files)), set(expected_reviewers)) | |
| 71 | |
| 72 def assertCoveredBy(self, files, reviewers): | |
| 73 db = self.db() | |
| 74 self.assertTrue(db.FilesAreCoveredBy(set(files), set(reviewers))) | |
| 75 | |
| 76 def assertNotCoveredBy(self, files, reviewers, unreviewed_files): | |
| 77 db = self.db() | |
| 78 self.assertEquals(db.FilesNotCoveredBy(set(files), set(reviewers)), | |
| 79 set(unreviewed_files)) | |
| 80 | |
| 81 def test_constructor(self): | |
| 82 self.assertNotEquals(self.db(), None) | |
| 83 | |
| 84 def test_owners_for(self): | |
| 85 self.assertReviewersFor(['DEPS'], [owners.ANYONE]) | |
| 86 self.assertReviewersFor(['content/content.gyp'], [jam, darin]) | |
| 87 self.assertReviewersFor(['chrome/gpu/gpu_channel.h'], [kbr]) | |
| 88 | |
| 89 def test_covered_by(self): | |
| 90 self.assertCoveredBy(['DEPS'], [jam]) | |
| 91 self.assertCoveredBy(['DEPS'], [darin]) | |
| 92 self.assertCoveredBy(['content/content.gyp'], [jam]) | |
| 93 self.assertCoveredBy(['chrome/gpu/OWNERS'], [kbr]) | |
| 94 self.assertCoveredBy(['chrome/gpu/OWNERS'], [ben]) | |
| 95 | |
| 96 def test_not_covered_by(self): | |
| 97 self.assertNotCoveredBy(['DEPS'], [], ['DEPS']) | |
| 98 self.assertNotCoveredBy(['content/content.gyp'], [ben], | |
| 99 ['content/content.gyp']) | |
| 100 self.assertNotCoveredBy( | |
| 101 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'], | |
| 102 [pkasting], ['chrome/gpu/gpu_channel.h']) | |
| 103 self.assertNotCoveredBy( | |
| 104 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'], | |
| 105 [ben], []) | |
| 106 | |
| 107 def test_comments_in_owners_file(self): | |
| 108 # pylint: disable=W0212 | |
| 109 db = self.db() | |
| 110 # Tests that this doesn't raise an error. | |
| 111 db._ReadOwnersFile('OWNERS', 'DEPS') | |
| 112 | |
| 113 def test_syntax_error_in_owners_file(self): | |
| 114 # pylint: disable=W0212 | |
| 115 db = self.db() | |
| 116 self.files['/foo/OWNERS'] = '{}\n' | |
| 117 self.files['/foo/DEPS'] = '# DEPS\n' | |
| 118 self.assertRaises(owners.SyntaxError, db._ReadOwnersFile, | |
| 119 '/foo/OWNERS', '/foo/DEPS') | |
| 120 | |
| 121 self.files['/bar/OWNERS'] = 'set myparentislinus\n' | |
| 122 self.files['/bar/DEPS'] = '# DEPS\n' | |
| 123 self.assertRaises(owners.SyntaxError, db._ReadOwnersFile, | |
| 124 '/bar/OWNERS', '/bar/DEPS') | |
| 125 | |
| 126 def test_owners_propagates_down(self): | |
| 127 self.assertCoveredBy(['/chrome/renderer/gpu/gpu_channel_host.h'], | |
| 128 [pkasting]) | |
| 129 | |
| 130 def test_set_noparent(self): | |
| 131 self.assertNotCoveredBy(['/content/content.gyp'], [pkasting], | |
| 132 ['/content/content.gyp']) | |
| 133 | |
| 134 | |
| 135 if __name__ == '__main__': | |
| 136 unittest.main() | |
| OLD | NEW |