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

Unified 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, 10 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 | « tests/filesystem_mock.py ('k') | no next file » | 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
new file mode 100755
index 0000000000000000000000000000000000000000..874eb4a6acb98ba2eba5af7d72c93b8eda9885b1
--- /dev/null
+++ b/tests/owners_unittest.py
@@ -0,0 +1,135 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for owners.py."""
+
+import unittest
+
+import owners
+from tests import filesystem_mock
+
+
+def test_repo():
+ return filesystem_mock.MockFileSystem(files={
+ '/DEPS' : '',
+ '/OWNERS':
+ ('# OWNERS'
+ '*\n'),
+ '/base/vlog.h':
+ '// vlog.h\n',
+ '/chrome/OWNERS':
+ ('ben@example.com\n'
+ 'brettw@example.com\n'),
+ '/chrome/gpu/OWNERS':
+ ('kbr@example.com\n'),
+ '/chrome/gpu/gpu_channel.h':
+ '// gpu_channel.h\n',
+ '/chrome/renderer/OWNERS':
+ ('pkasting@example.com\n'),
+ '/chrome/renderer/gpu/gpu_channel_host.h':
+ '// gpu_channel_host.h\n',
+ '/chrome/renderer/safe_browsing/scorer.h':
+ '// scorer.h\n',
+ '/content/OWNERS':
+ ('set noparent\n'
+ 'jam@example.com\n'
+ 'darin@example.com\n'),
+ '/content/content.gyp':
+ '# content.gyp\n',
+ })
+
+
+ben = 'ben@example.com'
+brett = 'brettw@example.com'
+darin = 'darin@example.com'
+jam = 'jam@example.com'
+kbr = 'kbr@example.com'
+pkasting = 'pkasting@example.com'
+
+
+class OwnersDatabaseTest(unittest.TestCase):
+ def setUp(self):
+ self.repo = test_repo()
+ self.files = self.repo.files
+ self.root = '/'
+
+ # pylint: disable=W0108
+ self.fopen = self.repo.open_for_reading
+
+ def db(self, root=None, fopen=None, os_path=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)
+
+ def assertReviewersFor(self, files, expected_reviewers):
+ db = self.db()
+ self.assertEquals(db.ReviewersFor(set(files)), set(expected_reviewers))
+
+ def assertCoveredBy(self, files, reviewers):
+ db = self.db()
+ self.assertTrue(db.FilesAreCoveredBy(set(files), set(reviewers)))
+
+ def assertNotCoveredBy(self, files, reviewers, unreviewed_files):
+ db = self.db()
+ self.assertEquals(db.FilesNotCoveredBy(set(files), set(reviewers)),
+ set(unreviewed_files))
+
+ def test_constructor(self):
+ self.assertNotEquals(self.db(), None)
+
+ def test_owners_for(self):
+ self.assertReviewersFor(['DEPS'], [owners.ANYONE])
+ self.assertReviewersFor(['content/content.gyp'], [jam, darin])
+ self.assertReviewersFor(['chrome/gpu/gpu_channel.h'], [kbr])
+
+ def test_covered_by(self):
+ self.assertCoveredBy(['DEPS'], [jam])
+ self.assertCoveredBy(['DEPS'], [darin])
+ self.assertCoveredBy(['content/content.gyp'], [jam])
+ self.assertCoveredBy(['chrome/gpu/OWNERS'], [kbr])
+ self.assertCoveredBy(['chrome/gpu/OWNERS'], [ben])
+
+ def test_not_covered_by(self):
+ self.assertNotCoveredBy(['DEPS'], [], ['DEPS'])
+ self.assertNotCoveredBy(['content/content.gyp'], [ben],
+ ['content/content.gyp'])
+ self.assertNotCoveredBy(
+ ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'],
+ [pkasting], ['chrome/gpu/gpu_channel.h'])
+ self.assertNotCoveredBy(
+ ['chrome/gpu/gpu_channel.h', 'chrome/renderer/gpu/gpu_channel_host.h'],
+ [ben], [])
+
+ def test_comments_in_owners_file(self):
+ # pylint: disable=W0212
+ db = self.db()
+ # Tests that this doesn't raise an error.
+ db._ReadOwnersFile('OWNERS', 'DEPS')
+
+ def test_syntax_error_in_owners_file(self):
+ # pylint: disable=W0212
+ db = self.db()
+ self.files['/foo/OWNERS'] = '{}\n'
+ self.files['/foo/DEPS'] = '# DEPS\n'
+ self.assertRaises(owners.SyntaxErrorInOwnersFile, db._ReadOwnersFile,
+ '/foo/OWNERS', '/foo/DEPS')
+
+ self.files['/bar/OWNERS'] = 'set myparentislinus\n'
+ self.files['/bar/DEPS'] = '# DEPS\n'
+ self.assertRaises(owners.SyntaxErrorInOwnersFile, db._ReadOwnersFile,
+ '/bar/OWNERS', '/bar/DEPS')
+
+ def test_owners_propagates_down(self):
+ self.assertCoveredBy(['/chrome/renderer/gpu/gpu_channel_host.h'],
+ [pkasting])
+
+ def test_set_noparent(self):
+ self.assertNotCoveredBy(['/content/content.gyp'], [pkasting],
+ ['/content/content.gyp'])
+
+
+if __name__ == '__main__':
+ unittest.main()
« 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