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

Side by Side Diff: tests/owners_unittest.py

Issue 6612011: add tests for owners database module in depot_tools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: make raise_not_found a file-level fn Created 9 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
« no previous file with comments | « tests/filesystem_mock.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
10 import owners
11 from tests import filesystem_mock
12
13
14 def test_repo():
15 return filesystem_mock.MockFileSystem(files={
16 '/DEPS' : '',
17 '/OWNERS':
18 ('# OWNERS'
19 '*\n'),
20 '/base/vlog.h':
21 '// vlog.h\n',
22 '/chrome/OWNERS':
23 ('ben@example.com\n'
24 'brettw@example.com\n'),
25 '/chrome/gpu/OWNERS':
26 ('kbr@example.com\n'),
27 '/chrome/gpu/gpu_channel.h':
28 '// gpu_channel.h\n',
29 '/chrome/renderer/OWNERS':
30 ('pkasting@example.com\n'),
31 '/chrome/renderer/gpu/gpu_channel_host.h':
32 '// gpu_channel_host.h\n',
33 '/chrome/renderer/safe_browsing/scorer.h':
34 '// scorer.h\n',
35 '/content/OWNERS':
36 ('set noparent\n'
37 'jam@example.com\n'
38 'darin@example.com\n'),
39 '/content/content.gyp':
40 '# content.gyp\n',
41 })
42
43
44 ben = 'ben@example.com'
45 brett = 'brettw@example.com'
46 darin = 'darin@example.com'
47 jam = 'jam@example.com'
48 kbr = 'kbr@example.com'
49 pkasting = 'pkasting@example.com'
50
51
52 class OwnersDatabaseTest(unittest.TestCase):
53 def setUp(self):
54 self.repo = test_repo()
55 self.files = self.repo.files
56 self.root = '/'
57
58 # pylint: disable=W0108
59 self.fopen = self.repo.open_for_reading
60
61 def db(self, root=None, fopen=None, os_path=None):
62 root = root or self.root
63 fopen = fopen or self.fopen
64 os_path = os_path or self.repo
65 return owners.Database(root, fopen, os_path)
66
67 def assertReviewersFor(self, files, expected_reviewers):
68 db = self.db()
69 self.assertEquals(db.ReviewersFor(set(files)), set(expected_reviewers))
70
71 def assertCoveredBy(self, files, reviewers):
72 db = self.db()
73 self.assertTrue(db.FilesAreCoveredBy(set(files), set(reviewers)))
74
75 def assertNotCoveredBy(self, files, reviewers, unreviewed_files):
76 db = self.db()
77 self.assertEquals(db.FilesNotCoveredBy(set(files), set(reviewers)),
78 set(unreviewed_files))
79
80 def test_constructor(self):
81 self.assertNotEquals(self.db(), None)
82
83 def test_owners_for(self):
84 self.assertReviewersFor(['DEPS'], [owners.ANYONE])
85 self.assertReviewersFor(['content/content.gyp'], [jam, darin])
86 self.assertReviewersFor(['chrome/gpu/gpu_channel.h'], [kbr])
87
88 def test_covered_by(self):
89 self.assertCoveredBy(['DEPS'], [jam])
90 self.assertCoveredBy(['DEPS'], [darin])
91 self.assertCoveredBy(['content/content.gyp'], [jam])
92 self.assertCoveredBy(['chrome/gpu/OWNERS'], [kbr])
93 self.assertCoveredBy(['chrome/gpu/OWNERS'], [ben])
94
95 def test_not_covered_by(self):
96 self.assertNotCoveredBy(['DEPS'], [], ['DEPS'])
97 self.assertNotCoveredBy(['content/content.gyp'], [ben],
98 ['content/content.gyp'])
99 self.assertNotCoveredBy(
100 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'],
101 [pkasting], ['chrome/gpu/gpu_channel.h'])
102 self.assertNotCoveredBy(
103 ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'],
104 [ben], [])
105
106 def test_comments_in_owners_file(self):
107 # pylint: disable=W0212
108 db = self.db()
109 # Tests that this doesn't raise an error.
110 db._ReadOwnersFile('OWNERS', 'DEPS')
111
112 def test_syntax_error_in_owners_file(self):
113 # pylint: disable=W0212
114 db = self.db()
115 self.files['/foo/OWNERS'] = '{}\n'
116 self.files['/foo/DEPS'] = '# DEPS\n'
117 self.assertRaises(owners.SyntaxErrorInOwnersFile, db._ReadOwnersFile,
118 '/foo/OWNERS', '/foo/DEPS')
119
120 self.files['/bar/OWNERS'] = 'set myparentislinus\n'
121 self.files['/bar/DEPS'] = '# DEPS\n'
122 self.assertRaises(owners.SyntaxErrorInOwnersFile, db._ReadOwnersFile,
123 '/bar/OWNERS', '/bar/DEPS')
124
125 def test_owners_propagates_down(self):
126 self.assertCoveredBy(['/chrome/renderer/gpu/gpu_channel_host.h'],
127 [pkasting])
128
129 def test_set_noparent(self):
130 self.assertNotCoveredBy(['/content/content.gyp'], [pkasting],
131 ['/content/content.gyp'])
132
133
134 if __name__ == '__main__':
135 unittest.main()
OLDNEW
« no previous file with comments | « tests/filesystem_mock.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698