Commit 8d7c003b authored by Quinten Yearsley's avatar Quinten Yearsley Committed by Commit Bot

Expand the unit tests for PathFinder in webkitpy

Bug: 710535
Change-Id: I6ce8350af1f1bad0ef1577b67b927381f1c4842f
Reviewed-on: https://chromium-review.googlesource.com/575031Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487482}
parent 97fd4164
......@@ -75,32 +75,33 @@ def get_webkitpy_thirdparty_dir():
class PathFinder(object):
def __init__(self, filesystem):
def __init__(self, filesystem, sys_path=None, env_path=None):
self._filesystem = filesystem
self._dirsep = filesystem.sep
self._sys_path = sys.path
self._env_path = os.environ['PATH'].split(os.pathsep)
self._sys_path = sys_path or sys.path
self._env_path = env_path or os.environ['PATH'].split(os.pathsep)
@memoized
def _webkit_base(self):
"""Returns the absolute path to the top of the WebKit tree.
def chromium_base(self):
return self._filesystem.dirname(self._filesystem.dirname(self._webkit_base()))
Raises an AssertionError if the top dir can't be determined.
"""
# TODO(qyearsley): This code somewhat duplicates the code in
# git.find_checkout_root().
module_path = self._filesystem.abspath(self._filesystem.path_to_module(self.__module__))
def layout_tests_dir(self):
return self._path_from_webkit_base('LayoutTests')
def perf_tests_dir(self):
return self._path_from_webkit_base('PerformanceTests')
@memoized
def _webkit_base(self):
"""Returns the absolute path to the top of the Blink directory."""
module_path = self._filesystem.path_to_module(self.__module__)
tools_index = module_path.rfind('Tools')
assert tools_index != -1, 'could not find location of this checkout from %s' % module_path
return self._filesystem.normpath(module_path[0:tools_index - 1])
@memoized
def chromium_base(self):
return self._filesystem.dirname(self._filesystem.dirname(self._webkit_base()))
# Do not expose this function in order to make the code robust against
# directory structure changes.
def _path_from_webkit_base(self, *comps):
# This function is marked as protected in order to make the code
# more robust against directory structure changes.
return self._filesystem.join(self._webkit_base(), *comps)
def path_from_chromium_base(self, *comps):
......@@ -112,21 +113,16 @@ class PathFinder(object):
def path_from_tools_scripts(self, *comps):
return self._filesystem.join(self._filesystem.join(self._webkit_base(), 'Tools', 'Scripts'), *comps)
def layout_tests_dir(self):
return self._path_from_webkit_base('LayoutTests')
def path_from_layout_tests(self, *comps):
return self._filesystem.join(self.layout_tests_dir(), *comps)
def perf_tests_dir(self):
return self._path_from_webkit_base('PerformanceTests')
def layout_test_name(self, file_path):
"""Returns a layout test name, given the path from the repo root.
Note: this appears to not work on Windows; see crbug.com/658795.
Also, this function duplicates functionality that's in
Port.relative_test_filename.
TODO(qyearsley): De-duplicate this and Port.relative_test_filename,
and ensure that it works properly with Windows paths.
......@@ -145,8 +141,11 @@ class PathFinder(object):
@memoized
def depot_tools_base(self):
# This basically duplicates src/build/find_depot_tools.py without the side effects
# (adding the directory to sys.path and importing breakpad).
"""Returns the path to depot_tools, or None if not found.
This basically duplicates src/build/find_depot_tools.py without the
side effects of adding the directory to sys.path or importing breakpad.
"""
return (self._check_paths_for_depot_tools(self._sys_path) or
self._check_paths_for_depot_tools(self._env_path) or
self._check_upward_for_depot_tools())
......@@ -158,6 +157,8 @@ class PathFinder(object):
return None
def _check_upward_for_depot_tools(self):
# TODO(qyearsley): Remove this, since on Chromium developer machines
# we generally assume that depot_tools is in PATH.
fs = self._filesystem
prev_dir = ''
current_dir = fs.dirname(self._webkit_base())
......
......@@ -10,30 +10,63 @@ from webkitpy.common.system.filesystem_mock import MockFileSystem
class TestPathFinder(unittest.TestCase):
# TODO(qyearsley): Add tests for other methods in PathFinder.
# Including tests for cases when the separator character is backslash.
def test_chromium_base(self):
finder = PathFinder(MockFileSystem())
self.assertEqual(finder.chromium_base(), '/mock-checkout')
def test_layout_test_name(self):
def test_path_from_chromium_base(self):
finder = PathFinder(MockFileSystem())
self.assertEqual(
finder.layout_test_name('third_party/WebKit/LayoutTests/test/name.html'),
'test/name.html')
finder.path_from_chromium_base('foo', 'bar.baz'),
'/mock-checkout/foo/bar.baz')
def test_layout_test_name_not_in_layout_tests_dir(self):
def test_layout_tests_dir(self):
finder = PathFinder(MockFileSystem())
self.assertIsNone(finder.layout_test_name('some/other/path/file.html'))
self.assertEqual(
finder.layout_tests_dir(),
'/mock-checkout/third_party/WebKit/LayoutTests')
# pylint: disable=protected-access
def test_webkit_base(self):
def test_layout_tests_dir_with_backslash_sep(self):
filesystem = MockFileSystem()
filesystem.sep = '\\'
filesystem.path_to_module = lambda _: (
'C:\\mock-checkout\\third_party\\WebKit\\Tools\\Scripts\\webkitpy\\foo.py')
finder = PathFinder(filesystem)
self.assertEqual(
finder.layout_tests_dir(),
'C:\\mock-checkout\\third_party\\WebKit\\LayoutTests')
def test_perf_tests_dir(self):
finder = PathFinder(MockFileSystem())
self.assertEqual(finder._webkit_base(), '/mock-checkout/third_party/WebKit')
self.assertEqual(
finder.perf_tests_dir(),
'/mock-checkout/third_party/WebKit/PerformanceTests')
def test_chromium_base(self):
def test_path_from_layout_tests(self):
finder = PathFinder(MockFileSystem())
self.assertEqual(finder.chromium_base(), '/mock-checkout')
self.assertEqual(
finder.path_from_layout_tests('external', 'wpt'),
'/mock-checkout/third_party/WebKit/LayoutTests/external/wpt')
def test_path_from_chromium_base(self):
def test_layout_test_name(self):
finder = PathFinder(MockFileSystem())
self.assertEqual(
finder.path_from_chromium_base('foo', 'bar.baz'),
'/mock-checkout/foo/bar.baz')
finder.layout_test_name('third_party/WebKit/LayoutTests/test/name.html'),
'test/name.html')
def test_layout_test_name_not_in_layout_tests_dir(self):
finder = PathFinder(MockFileSystem())
self.assertIsNone(
finder.layout_test_name('some/other/path/file.html'))
def test_depot_tools_base_not_found(self):
finder = PathFinder(MockFileSystem(), sys_path=['/foo'], env_path=['/bar'])
self.assertIsNone(finder.depot_tools_base())
def test_depot_tools_base_in_sys_path(self):
finder = PathFinder(MockFileSystem(), sys_path=['/foo/bar/depot_tools'], env_path=['/bar'])
self.assertEqual(finder.depot_tools_base(), '/foo/bar/depot_tools')
def test_depot_tools_base_in_env_path(self):
finder = PathFinder(MockFileSystem(), sys_path=['/foo'], env_path=['/baz/bin/depot_tools'])
self.assertEqual(finder.depot_tools_base(), '/baz/bin/depot_tools')
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