Diff
Modified: trunk/Tools/ChangeLog (90049 => 90050)
--- trunk/Tools/ChangeLog 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/ChangeLog 2011-06-29 21:48:00 UTC (rev 90050)
@@ -9,6 +9,28 @@
Reviewed by Adam Barth.
+ Make port/config.py mockable for easier unit testing
+ https://bugs.webkit.org/show_bug.cgi?id=63661
+
+ Right now config.py leaks real system paths for
+ webkit_base_dir due to using __file__. This patch
+ adds a filsystem.py wrapper around __file__ so that
+ we don't have to jump through hoops in webkit_unittest.py
+ to avoid leaking local paths to the unit test results.
+
+ There are probably many more places where we should now
+ use filesystem.path_for_module, but starting with just this one.
+
+ * Scripts/webkitpy/common/system/filesystem.py:
+ * Scripts/webkitpy/common/system/filesystem_mock.py:
+ * Scripts/webkitpy/layout_tests/port/config.py:
+ * Scripts/webkitpy/layout_tests/port/webkit_unittest.py:
+ * Scripts/webkitpy/tool/commands/rebaselineserver_unittest.py:
+
+2011-06-29 Eric Seidel <[email protected]>
+
+ Reviewed by Adam Barth.
+
Remove duplicate methods in filesystem.py
https://bugs.webkit.org/show_bug.cgi?id=63658
Modified: trunk/Tools/Scripts/webkitpy/common/system/filesystem.py (90049 => 90050)
--- trunk/Tools/Scripts/webkitpy/common/system/filesystem.py 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/Scripts/webkitpy/common/system/filesystem.py 2011-06-29 21:48:00 UTC (rev 90050)
@@ -36,6 +36,7 @@
import glob
import os
import shutil
+import sys
import tempfile
import time
@@ -57,6 +58,11 @@
def abspath(self, path):
return os.path.abspath(path)
+ def path_to_module(self, module_name):
+ """A wrapper for all calls to __file__ to allow easy unit testing."""
+ # FIXME: This is the only use of sys in this file. It's possible this function should move elsewhere.
+ return sys.modules[module_name].__file__ # __file__ is always an absolute path.
+
def expanduser(self, path):
return os.path.expanduser(path)
Modified: trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py (90049 => 90050)
--- trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py 2011-06-29 21:48:00 UTC (rev 90050)
@@ -79,6 +79,9 @@
return home_directory
return home_directory + self.sep + parts[1]
+ def path_to_module(self, module_name):
+ return "/mock/Tools/Scripts/webkitpy/%s" % module_name
+
def chdir(self, path):
path = self.normpath(path)
if not self.isdir(path):
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/config.py (90049 => 90050)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/config.py 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/config.py 2011-06-29 21:48:00 UTC (rev 90050)
@@ -118,8 +118,8 @@
#
# This code will also work if there is no SCM system at all.
if not self._webkit_base_dir:
- abspath = self._filesystem.abspath(__file__)
- self._webkit_base_dir = abspath[0:abspath.find('Tools') - 1]
+ config_module_path = self._filesystem.path_to_module(self.__module__)
+ self._webkit_base_dir = abspath[0:config_module_path.find('Tools') - 1]
return self._webkit_base_dir
def script_path(self, script_name):
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py (90049 => 90050)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py 2011-06-29 21:48:00 UTC (rev 90050)
@@ -27,7 +27,7 @@
import unittest
-from webkitpy.common.system import filesystem_mock
+from webkitpy.common.system.filesystem_mock import MockFileSystem
from webkitpy.common.system.outputcapture import OutputCapture
from webkitpy.layout_tests.port.webkit import WebKitPort
@@ -43,12 +43,10 @@
**kwargs):
self.symbol_list = symbol_list
self.feature_list = feature_list
- self.expectations_file = expectations_file
- self.skips_file = skips_file
executive = executive or MockExecutive(should_log=False)
- filesystem = filesystem or filesystem_mock.MockFileSystem()
+ filesystem = filesystem or MockFileSystem()
user = user or MockUser()
- WebKitPort.__init__(self, executive=executive, filesystem=filesystem, user=MockUser(), **kwargs)
+ WebKitPort.__init__(self, port_name="testwebkitport", executive=executive, filesystem=filesystem, user=MockUser(), **kwargs)
def _runtime_feature_list(self):
return self.feature_list
@@ -62,17 +60,7 @@
def _tests_for_disabled_features(self):
return ["accessibility", ]
- def path_to_test_expectations_file(self):
- if self.expectations_file:
- return self.expectations_file
- return WebKitPort.path_to_test_expectations_file(self)
- def _skipped_file_paths(self):
- if self.skips_file:
- return [self.skips_file]
- return []
-
-
class WebKitPortTest(port_testcase.PortTestCase):
def port_maker(self, platform):
return WebKitPort
@@ -105,12 +93,11 @@
# Check that we read both the expectations file and anything in a
# Skipped file, and that we include the feature and platform checks.
files = {
- '/tmp/test_expectations.txt': 'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL\n',
- '/tmp/Skipped': 'fast/html/keygen.html',
+ '/mock/LayoutTests/platform/testwebkitport/test_expectations.txt': 'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL\n',
+ '/mock/LayoutTests/platform/testwebkitport/Skipped': 'fast/html/keygen.html',
}
- mock_fs = filesystem_mock.MockFileSystem(files)
- port = TestWebKitPort(expectations_file='/tmp/test_expectations.txt',
- skips_file='/tmp/Skipped', filesystem=mock_fs)
+ mock_fs = MockFileSystem(files)
+ port = TestWebKitPort(filesystem=mock_fs)
self.assertEqual(port.test_expectations(),
"""BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL
BUG_SKIPPED SKIP : fast/html/keygen.html = FAIL
Modified: trunk/Tools/Scripts/webkitpy/tool/commands/rebaselineserver_unittest.py (90049 => 90050)
--- trunk/Tools/Scripts/webkitpy/tool/commands/rebaselineserver_unittest.py 2011-06-29 21:41:41 UTC (rev 90049)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/rebaselineserver_unittest.py 2011-06-29 21:48:00 UTC (rev 90050)
@@ -274,13 +274,13 @@
expected_baselines={'base': {'.txt': True}})
def _assertBaselines(self, test_files, test_name, expected_baselines):
- actual_baselines = rebaselineserver._get_test_baselines(
- test_name, get_test_config(test_files))
+ actual_baselines = rebaselineserver._get_test_baselines(test_name, get_test_config(test_files))
self.assertEqual(expected_baselines, actual_baselines)
def get_test_config(test_files=[], result_files=[]):
- layout_tests_directory = base.Port().layout_tests_dir()
+ # We could grab this from port.layout_tests_dir(), but instantiating a fully mocked port is a pain.
+ layout_tests_directory = "/mock/LayoutTests"
results_directory = '/WebKitBuild/Debug/layout-test-results'
mock_filesystem = filesystem_mock.MockFileSystem()
for file in test_files: