Commit 5d224d98 authored by Alexei Svitkine's avatar Alexei Svitkine Committed by Commit Bot

Fix test to work in checkouts not named 'chromium'.

Updates expand_owners_unittest.py to work even if the
checkout does not begin with a 'chromium' dir.

Note: This does not fix the issue that makes this test
fail on bots yet and so doesn't re-add it to the list of
tests ran by metrics_python_tests.py. This is a slightly
different issue, where on bots, there isn't even a 'src'
directory, which trips up other assumptions in the test.

Bug: 1126653
Change-Id: I0f345f3efa3a54b4f7ba08106fd6d08ffbc5345b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505573
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Auto-Submit: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarCaitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#821875}
parent 8d296394
...@@ -142,10 +142,10 @@ def _GetOwnersFilePath(path): ...@@ -142,10 +142,10 @@ def _GetOwnersFilePath(path):
return os.path.abspath( return os.path.abspath(
os.path.join(*(_DIR_ABOVE_TOOLS + path_without_src.split(os.sep)))) os.path.join(*(_DIR_ABOVE_TOOLS + path_without_src.split(os.sep))))
else:
raise Error('The given path {} is not well-formatted.' raise Error(
'Well-formatted paths begin with "src/" and end with "OWNERS"' 'The given path {} is not well-formatted. Well-formatted paths begin '
.format(path)) 'with "src/" and end with "OWNERS"'.format(path))
def _ExtractEmailAddressesFromOWNERS(path, depth=0): def _ExtractEmailAddressesFromOWNERS(path, depth=0):
......
...@@ -13,6 +13,19 @@ import xml.dom.minidom ...@@ -13,6 +13,19 @@ import xml.dom.minidom
_DEFAULT_COMPONENT = '# COMPONENT: Default>Component' _DEFAULT_COMPONENT = '# COMPONENT: Default>Component'
def _DirnameN(path, n):
"""Calls os.path.dirname() on the argument n times."""
path = os.path.abspath(path)
for _ in range(n):
path = os.path.dirname(path)
return path
assert __file__.endswith('tools/metrics/histograms/expand_owners_unittest.py')
_PATH_TO_CHROMIUM_DIR = _DirnameN(__file__, 5)
def _GetFileDirective(path): def _GetFileDirective(path):
"""Returns a file directive line. """Returns a file directive line.
...@@ -31,9 +44,12 @@ def _GetSrcRelativePath(path): ...@@ -31,9 +44,12 @@ def _GetSrcRelativePath(path):
Args: Args:
path: An absolute path, e.g. '/some/directory/chromium/src/tools/OWNERS'. path: An absolute path, e.g. '/some/directory/chromium/src/tools/OWNERS'.
Returns:
A src-relative path, e.g.'src/tools/OWNERS'.
""" """
# TODO(crbug/1126653): This fails if chromium is not in the path. assert path.startswith(_PATH_TO_CHROMIUM_DIR)
return path.split('chromium/')[1] return path[len(_PATH_TO_CHROMIUM_DIR) + 1:]
def _MakeOwnersFile(filename, directory): def _MakeOwnersFile(filename, directory):
......
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