depot_tools: Make owners tests run on Python 3

Bug: 1009814
Change-Id: Ifb073dc0b54a3291f1f874866da3c0fbbeab2db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1888443
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
changes/43/1888443/3
Edward Lemur 6 years ago committed by Commit Bot
parent 9bb7b96c4d
commit 14705d8ce0

@ -77,7 +77,7 @@ GLOBAL_STATUS = '*'
def _assert_is_collection(obj):
assert not isinstance(obj, basestring)
assert not isinstance(obj, str)
# Module 'collections' has no 'Iterable' member
# pylint: disable=no-member
if hasattr(collections, 'Iterable') and hasattr(collections, 'Sized'):
@ -508,7 +508,7 @@ class Database(object):
# Now that we've used `owner` and covered all their dirs, remove them
# from consideration.
del all_possible_owners[owner]
for o, dirs in all_possible_owners.items():
for o, dirs in list(all_possible_owners.items()):
new_dirs = [(d, dist) for (d, dist) in dirs if d not in dirs_to_remove]
if not new_dirs:
del all_possible_owners[o]
@ -606,9 +606,9 @@ class Database(object):
dirs)
# Return the lowest cost owner. In the case of a tie, pick one randomly.
lowest_cost = min(total_costs_by_owner.values())
lowest_cost_owners = filter(
lambda owner: total_costs_by_owner[owner] == lowest_cost,
total_costs_by_owner)
lowest_cost_owners = [
owner for owner, cost in total_costs_by_owner.items()
if cost == lowest_cost]
return random.Random().choice(lowest_cost_owners)
def owners_rooted_at_file(self, filename):

@ -6,7 +6,12 @@ import errno
import fnmatch
import os
import re
import StringIO
import sys
if sys.version_info.major == 2:
from StringIO import StringIO
else:
from io import StringIO
def _RaiseNotFound(path):
@ -63,7 +68,7 @@ class MockFileSystem(object):
# We need to use a copy of the keys here in order to avoid switching
# to a different thread and potentially modifying the dict in
# mid-iteration.
files = self.files.keys()[:]
files = list(self.files.keys())[:]
return any(f.startswith(path) for f in files)
def join(self, *comps):
@ -75,7 +80,7 @@ class MockFileSystem(object):
return fnmatch.filter(self.files.keys(), path)
def open_for_reading(self, path):
return StringIO.StringIO(self.read_binary_file(path))
return StringIO(self.read_binary_file(path))
def normpath(self, path):
# This is not a complete implementation of normpath. Only covers what we

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env vpython3
# Copyright 2013 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.

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env vpython3
# Copyright (c) 2012 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.

Loading…
Cancel
Save