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

Unified Diff: tests/owners_unittest.py

Issue 11114005: implement per-file OWNERS support (Closed) Base URL: https://git.chromium.org/chromium/tools/depot_tools.git@master
Patch Set: update w/ more review feedback Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing_support/filesystem_mock.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/owners_unittest.py
diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py
index 0e32ae0441966ca7b33ce17edfa9c46b5c55f541..40f56c15d014969b7c33bf1f5fd49eb9921f7359 100755
--- a/tests/owners_unittest.py
+++ b/tests/owners_unittest.py
@@ -21,6 +21,8 @@ darin = 'darin@example.com'
john = 'john@example.com'
ken = 'ken@example.com'
peter = 'peter@example.com'
+tom = 'tom@example.com'
+
def owners_file(*email_addresses, **kwargs):
s = ''
@@ -28,6 +30,7 @@ def owners_file(*email_addresses, **kwargs):
s += '# %s\n' % kwargs.get('comment')
if kwargs.get('noparent'):
s += 'set noparent\n'
+ s += '\n'.join(kwargs.get('lines', [])) + '\n'
return s + '\n'.join(email_addresses) + '\n'
@@ -47,6 +50,8 @@ def test_repo():
'/content/bar/foo.cc': '',
'/content/baz/OWNERS': owners_file(brett),
'/content/baz/froboz.h': '',
+ '/content/baz/ugly.cc': '',
+ '/content/baz/ugly.h': '',
'/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE,
noparent=True),
'/content/views/pie.h': '',
@@ -59,12 +64,14 @@ class OwnersDatabaseTest(unittest.TestCase):
self.files = self.repo.files
self.root = '/'
self.fopen = self.repo.open_for_reading
+ self.glob = self.repo.glob
- def db(self, root=None, fopen=None, os_path=None):
+ def db(self, root=None, fopen=None, os_path=None, glob=None):
root = root or self.root
fopen = fopen or self.fopen
os_path = os_path or self.repo
- return owners.Database(root, fopen, os_path)
+ glob = glob or self.glob
+ return owners.Database(root, fopen, os_path, glob)
def test_constructor(self):
self.assertNotEquals(self.db(), None)
@@ -131,6 +138,42 @@ class OwnersDatabaseTest(unittest.TestCase):
[ken],
['content', 'content/baz'])
+ def test_per_file(self):
+ # brett isn't allowed to approve ugly.cc
+ self.files['/content/baz/OWNERS'] = owners_file(brett,
+ lines=['per-file ugly.*=tom@example.com'])
+ self.assert_dirs_not_covered_by(['content/baz/ugly.cc'],
+ [brett],
+ [])
+
+ # tom is allowed to approve ugly.cc, but not froboz.h
+ self.assert_dirs_not_covered_by(['content/baz/ugly.cc'],
+ [tom],
+ [])
+ self.assert_dirs_not_covered_by(['content/baz/froboz.h'],
+ [tom],
+ ['content/baz'])
+
+ def test_per_file__set_noparent(self):
+ self.files['/content/baz/OWNERS'] = owners_file(brett,
+ lines=['per-file ugly.*=tom@example.com',
+ 'per-file ugly.*=set noparent'])
+
+ # brett isn't allowed to approve ugly.cc
+ self.assert_dirs_not_covered_by(['content/baz/ugly.cc'],
+ [brett],
+ ['content/baz/ugly.cc'])
+
+ # tom is allowed to approve ugly.cc, but not froboz.h
+ self.assert_dirs_not_covered_by(['content/baz/ugly.cc'],
+ [tom],
+ [])
+
+ self.assert_dirs_not_covered_by(['content/baz/froboz.h'],
+ [tom],
+ ['content/baz'])
+
+
def assert_reviewers_for(self, files, expected_reviewers):
db = self.db()
self.assertEquals(db.reviewers_for(set(files)), set(expected_reviewers))
« no previous file with comments | « testing_support/filesystem_mock.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698