Commit 04704f7b authored by zork@chromium.org's avatar zork@chromium.org

Readd missing unittests for owners

TEST=Run tests/owners_unittest.py


Review URL: https://chromiumcodereview.appspot.com/10384099

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@137041 0039d316-1c4b-4281-b951-d872f2087c98
parent 420d3b8f
...@@ -178,20 +178,20 @@ class Database(object): ...@@ -178,20 +178,20 @@ class Database(object):
current_owners = set() current_owners = set()
dirname = current_dir dirname = current_dir
while dirname in self.owners_for: while dirname in self.owners_for:
for owner in self.owners_for[dirname]: current_owners |= self.owners_for[dirname]
current_owners.add(owner)
if self._stop_looking(dirname): if self._stop_looking(dirname):
break break
prev_parent = dirname
dirname = self.os_path.dirname(dirname) dirname = self.os_path.dirname(dirname)
if prev_parent == dirname:
break
# Map each directory to a list of its owners. # Map each directory to a list of its owners.
dir_owners[current_dir] = current_owners dir_owners[current_dir] = current_owners
# Add the directory to the list of each owner. # Add the directory to the list of each owner.
for owner in current_owners: for owner in current_owners:
if not owner in owned_dirs: owned_dirs.setdefault(owner, set()).add(current_dir)
owned_dirs[owner] = set()
owned_dirs[owner].add(current_dir)
final_owners = set() final_owners = set()
while dirs: while dirs:
...@@ -205,6 +205,7 @@ class Database(object): ...@@ -205,6 +205,7 @@ class Database(object):
owner_count[owner] = count owner_count[owner] = count
if count >= max_count: if count >= max_count:
max_owner = owner max_owner = owner
max_count = count
# If no more directories have OWNERS, we're done. # If no more directories have OWNERS, we're done.
if not max_owner: if not max_owner:
...@@ -215,7 +216,6 @@ class Database(object): ...@@ -215,7 +216,6 @@ class Database(object):
# Remove all directories owned by the current owner from the remaining # Remove all directories owned by the current owner from the remaining
# list. # list.
for dirname in owned_dirs[max_owner]: for dirname in owned_dirs[max_owner]:
if dirname in dirs: dirs.discard(dirname)
dirs.remove(dirname)
return final_owners return final_owners
...@@ -49,6 +49,7 @@ def test_repo(): ...@@ -49,6 +49,7 @@ def test_repo():
'/content/baz/froboz.h': '', '/content/baz/froboz.h': '',
'/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE,
noparent=True), noparent=True),
'/content/views/pie.h': '',
}) })
...@@ -157,6 +158,30 @@ class OwnersDatabaseTest(unittest.TestCase): ...@@ -157,6 +158,30 @@ class OwnersDatabaseTest(unittest.TestCase):
def test_reviewers_for__wildcard_dir(self): def test_reviewers_for__wildcard_dir(self):
self.assert_reviewers_for(['DEPS'], [owners.EVERYONE]) self.assert_reviewers_for(['DEPS'], [owners.EVERYONE])
def test_reviewers_for__one_owner(self):
self.assert_reviewers_for([
'/chrome/gpu/gpu_channel.h',
'/content/baz/froboz.h',
'/chrome/renderer/gpu/gpu_channel_host.h'], [brett])
def test_reviewers_for__two_owners(self):
self.assert_reviewers_for([
'/chrome/gpu/gpu_channel.h',
'/content/content.gyp',
'/content/baz/froboz.h',
'/content/views/pie.h'
], [john, brett])
def test_reviewers_for__all_files(self):
self.assert_reviewers_for([
'/chrome/gpu/gpu_channel.h',
'/chrome/renderer/gpu/gpu_channel_host.h',
'/chrome/renderer/safe_browsing/scorer.h',
'/content/content.gyp',
'/content/bar/foo.cc',
'/content/baz/froboz.h',
'/content/views/pie.h'], [john, brett])
def assert_syntax_error(self, owners_file_contents): def assert_syntax_error(self, owners_file_contents):
db = self.db() db = self.db()
self.files['/foo/OWNERS'] = owners_file_contents self.files['/foo/OWNERS'] = owners_file_contents
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment