| Index: tests/owners_unittest.py
|
| diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py
|
| index 0cc6d72979b50e62d19a0251fe9edfad1a40681d..f0e9c40b5fe55395440ec6448a8dc7c642be1092 100755
|
| --- a/tests/owners_unittest.py
|
| +++ b/tests/owners_unittest.py
|
| @@ -5,6 +5,7 @@
|
|
|
| """Unit tests for owners.py."""
|
|
|
| +import itertools
|
| import os
|
| import sys
|
| import unittest
|
| @@ -17,13 +18,14 @@ import owners
|
|
|
| ben = 'ben@example.com'
|
| brett = 'brett@example.com'
|
| +dana = 'dana@example.com'
|
| darin = 'darin@example.com'
|
| +elena = 'elena@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 = ''
|
| if kwargs.get('comment'):
|
| @@ -39,9 +41,11 @@ def owners_file(*email_addresses, **kwargs):
|
| def test_repo():
|
| return filesystem_mock.MockFileSystem(files={
|
| '/DEPS' : '',
|
| - '/OWNERS': owners_file(owners.EVERYONE),
|
| + '/OWNERS': owners_file(dana),
|
| '/base/vlog.h': '',
|
| '/chrome/OWNERS': owners_file(ben, brett),
|
| + '/chrome/chrome.mojom': '',
|
| + '/chrome/locked.mojom': '',
|
| '/chrome/browser/OWNERS': owners_file(brett),
|
| '/chrome/browser/defaults.h': '',
|
| '/chrome/gpu/OWNERS': owners_file(ken),
|
| @@ -49,9 +53,11 @@ def test_repo():
|
| '/chrome/renderer/OWNERS': owners_file(peter),
|
| '/chrome/renderer/gpu/gpu_channel_host.h': '',
|
| '/chrome/renderer/safe_browsing/scorer.h': '',
|
| + '/chrome/renderer/safe_browsing/scorer.mojom': '',
|
| '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True),
|
| '/content/content.gyp': '',
|
| '/content/bar/foo.cc': '',
|
| + '/content/bar/armchair.mojom': '',
|
| '/content/baz/OWNERS': owners_file(brett),
|
| '/content/baz/froboz.h': '',
|
| '/content/baz/ugly.cc': '',
|
| @@ -106,8 +112,10 @@ class OwnersDatabaseTest(_BaseTestCase):
|
|
|
| def assert_files_not_covered_by(self, files, reviewers, unreviewed_files):
|
| db = self.db()
|
| - self.assertEquals(db.files_not_covered_by(set(files), set(reviewers)),
|
| - set(unreviewed_files))
|
| + result = db.files_not_covered_by(set(files), set(reviewers))
|
| + expected = set(unreviewed_files)
|
| + if result != expected:
|
| + raise AssertionError('files_not_covered_by(%s, %s)\n returned: %s\n expected: %s' % (list(set(files)), list(set(reviewers)), list(result), list(expected)))
|
|
|
| def test_files_not_covered_by__owners_propagates_down(self):
|
| self.assert_files_not_covered_by(
|
| @@ -126,7 +134,10 @@ class OwnersDatabaseTest(_BaseTestCase):
|
| def test_files_not_covered_by__no_reviewer(self):
|
| self.assert_files_not_covered_by(
|
| ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'],
|
| - [], ['content/content.gyp'])
|
| + [], ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'])
|
| + self.assert_files_not_covered_by(
|
| + ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h', 'content/views/pie.h'],
|
| + [], ['content/content.gyp', 'chrome/renderer/gpu/gpu_channel_host.h'])
|
|
|
| def test_files_not_covered_by__combines_directories(self):
|
| self.assert_files_not_covered_by(['content/content.gyp',
|
| @@ -137,6 +148,7 @@ class OwnersDatabaseTest(_BaseTestCase):
|
| 'content/bar/foo.cc'])
|
|
|
| def test_files_not_covered_by__multiple_directories(self):
|
| + self.files['/OWNERS'] = owners_file(owners.EVERYONE)
|
| self.assert_files_not_covered_by(
|
| ['content/content.gyp', # Not covered
|
| 'content/bar/foo.cc', # Not covered (combines in)
|
| @@ -243,6 +255,34 @@ class OwnersDatabaseTest(_BaseTestCase):
|
| self.assertRaises(owners.SyntaxErrorInOwnersFile,
|
| self.db().files_not_covered_by, ['DEPS'], [brett])
|
|
|
| + def test_per_file_glob_transitive(self):
|
| + # per-file *.ext rules apply to matching files
|
| + # in subdirectories, but not across 'set noparent'.
|
| + self.files['/chrome/OWNERS'] = owners_file(ben, brett,
|
| + lines=['per-file *.mojom=tom@example.com',
|
| + 'per-file locked.mojom=set noparent'])
|
| + self.files['/OWNERS'] = owners_file(dana,
|
| + lines=['per-file *.mojom=elena@example.com'])
|
| + # For each file, who we expect to be able to approve it.
|
| + permissions = {
|
| + 'chrome/chrome.mojom': [dana, tom, elena],
|
| + 'chrome/locked.mojom': [tom],
|
| + 'chrome/renderer/safe_browsing/scorer.mojom': [dana, tom, elena],
|
| + 'chrome/renderer/safe_browsing/scorer.h': [dana, ben],
|
| + 'content/bar/armchair.mojom': [darin],
|
| + }
|
| +
|
| + reviewers = set(sum(permissions.values(), []))
|
| + files = permissions.keys()
|
| + for reviewer in reviewers:
|
| + owned_files = set(
|
| + f for (f, acl) in permissions.iteritems() if reviewer in acl)
|
| + for num_files in range(1, len(files)+1):
|
| + for touched_files in itertools.combinations(files, num_files):
|
| + expected_missing_coverage = set(touched_files) - owned_files
|
| + self.assert_files_not_covered_by(touched_files, [reviewer],
|
| + expected_missing_coverage)
|
| +
|
| def test_file_include_absolute_path(self):
|
| self.assert_files_not_covered_by(['content/qux/foo.cc'], [brett], [])
|
| self.assert_files_not_covered_by(['content/qux/bar.cc'], [peter], [])
|
| @@ -353,6 +393,7 @@ class ReviewersForTest(_BaseTestCase):
|
| self.assertRaises(AssertionError, db.reviewers_for, ['/OWNERS'], None)
|
|
|
| def test_reviewers_for__wildcard_dir(self):
|
| + self.files['/OWNERS'] = owners_file(owners.EVERYONE)
|
| self.assert_reviewers_for(['DEPS'], [['<anyone>']])
|
| self.assert_reviewers_for(['DEPS', 'chrome/gpu/gpu_channel.h'], [[ken]])
|
|
|
|
|