Diff
Modified: trunk/Tools/ChangeLog (90977 => 90978)
--- trunk/Tools/ChangeLog 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/ChangeLog 2011-07-14 05:05:10 UTC (rev 90978)
@@ -1,5 +1,34 @@
2011-07-13 Eric Seidel <[email protected]>
+ Move webkitpy off of loose mocks
+ https://bugs.webkit.org/show_bug.cgi?id=64508
+
+ Reviewed by Adam Barth.
+
+ Using Mock has caused us more pain than help.
+ It's possible that there was a cleaner way to use it
+ (maybe Mock(class) instead of inheriting from it?).
+ But for now, I've removed all uses of Mock from mocktool.py.
+
+ I also moved run_command into the only 3 files which call it
+ instead of leaving the deprecated method in executive.py.
+
+ I changed various direct calls to os.* to use filesystem instead.
+
+ * Scripts/webkitpy/common/checkout/checkout.py:
+ * Scripts/webkitpy/common/checkout/checkout_unittest.py:
+ * Scripts/webkitpy/common/checkout/scm/git.py:
+ * Scripts/webkitpy/common/checkout/scm/scm.py:
+ * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+ * Scripts/webkitpy/common/checkout/scm/svn.py:
+ * Scripts/webkitpy/common/system/executive.py:
+ * Scripts/webkitpy/common/system/executive_unittest.py:
+ * Scripts/webkitpy/tool/mocktool.py:
+ * Scripts/webkitpy/tool/steps/cleanworkingdirectory_unittest.py:
+ * Scripts/webkitpy/tool/steps/ensurelocalcommitifneeded.py:
+
+2011-07-13 Eric Seidel <[email protected]>
+
NRWT doesn't store the svn revision in full_results.json on chromium-win
https://bugs.webkit.org/show_bug.cgi?id=64492
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -26,7 +26,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os
import StringIO
from webkitpy.common.config import urls
@@ -35,7 +34,7 @@
from webkitpy.common.checkout.scm import CommitMessage
from webkitpy.common.checkout.deps import DEPS
from webkitpy.common.memoized import memoized
-from webkitpy.common.system.executive import run_command, ScriptError
+from webkitpy.common.system.executive import ScriptError
from webkitpy.common.system.deprecated_logging import log
@@ -43,11 +42,14 @@
# FIXME: Move a bunch of ChangeLog-specific processing from SCM to this object.
# NOTE: All paths returned from this class should be absolute.
class Checkout(object):
- def __init__(self, scm):
+ def __init__(self, scm, executive=None, filesystem=None):
self._scm = scm
+ # FIXME: We shouldn't be grabbing at private members on scm.
+ self._executive = executive or self._scm._executive
+ self._filesystem = filesystem or self._scm._filesystem
def is_path_to_changelog(self, path):
- return os.path.basename(path) == "ChangeLog"
+ return self._filesystem.basename(path) == "ChangeLog"
def _latest_entry_for_changelog_at_revision(self, changelog_path, revision):
changelog_contents = self._scm.contents_at_revision(changelog_path, revision)
@@ -111,8 +113,7 @@
# expect absolute paths, so this method returns absolute paths.
if not changed_files:
changed_files = self._scm.changed_files(git_commit)
- absolute_paths = [os.path.join(self._scm.checkout_root, path) for path in changed_files]
- return [path for path in absolute_paths if predicate(path)]
+ return filter(predicate, map(self._scm.absolute_path, changed_files))
def modified_changelogs(self, git_commit, changed_files=None):
return self._modified_files_matching_predicate(git_commit, self.is_path_to_changelog, changed_files=changed_files)
@@ -147,7 +148,7 @@
pass # We might not have ChangeLogs.
def chromium_deps(self):
- return DEPS(os.path.join(self._scm.checkout_root, "Source", "WebKit", "chromium", "DEPS"))
+ return DEPS(self._scm.absolute_path("Source", "WebKit", "chromium", "DEPS"))
def apply_patch(self, patch, force=False):
# It's possible that the patch was not made from the root directory.
@@ -158,7 +159,7 @@
args += ['--reviewer', patch.reviewer().full_name]
if force:
args.append('--force')
- self._scm._executive.run_command(args, input=patch.contents())
+ self._executive.run_command(args, input=patch.contents())
def apply_reverse_diff(self, revision):
self._scm.apply_reverse_diff(revision)
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/checkout_unittest.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/checkout_unittest.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/checkout_unittest.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -38,6 +38,8 @@
from .changelog import ChangeLogEntry
from .scm import detect_scm_system, CommitMessage
from webkitpy.common.system.executive import Executive, ScriptError
+from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.tool.mocktool import MockSCM, MockExecutive
from webkitpy.thirdparty.mock import Mock
@@ -129,7 +131,7 @@
real_scm = detect_scm_system(self.old_cwd)
- mock_scm = Mock()
+ mock_scm = MockSCM()
mock_scm.run = mock_run
mock_scm.script_path = real_scm.script_path
@@ -140,8 +142,10 @@
class CheckoutTest(unittest.TestCase):
+ def _make_checkout(self):
+ return Checkout(scm=MockSCM(), filesystem=MockFileSystem(), executive=MockExecutive())
+
def test_latest_entry_for_changelog_at_revision(self):
- scm = Mock()
def mock_contents_at_revision(changelog_path, revision):
self.assertEqual(changelog_path, "foo")
self.assertEqual(revision, "bar")
@@ -150,8 +154,8 @@
# The ChangeLog utf-8 decoding should ignore invalid codepoints.
invalid_utf8 = "\255"
return _changelog1.encode("utf-8") + invalid_utf8
- scm.contents_at_revision = mock_contents_at_revision
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.contents_at_revision = mock_contents_at_revision
entry = checkout._latest_entry_for_changelog_at_revision("foo", "bar")
self.assertEqual(entry.contents(), _changelog1entry1)
@@ -160,9 +164,8 @@
# from revisions, resulting in a ScriptError exception. Test that we
# recover from those and still return the other ChangeLog entries.
def test_changelog_entries_for_revision(self):
- scm = Mock()
- scm.changed_files_for_revision = lambda revision: ['foo/ChangeLog', 'bar/ChangeLog']
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.changed_files_for_revision = lambda revision: ['foo/ChangeLog', 'bar/ChangeLog']
def mock_latest_entry_for_changelog_at_revision(path, revision):
if path == "foo/ChangeLog":
@@ -177,10 +180,9 @@
self.assertEqual(entries[0], 'foo')
def test_commit_info_for_revision(self):
- scm = Mock()
- scm.changed_files_for_revision = lambda revision: ['path/to/file', 'another/file']
- scm.committer_email_for_revision = lambda revision, changed_files=None: "[email protected]"
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.changed_files_for_revision = lambda revision: ['path/to/file', 'another/file']
+ checkout._scm.committer_email_for_revision = lambda revision, changed_files=None: "[email protected]"
checkout.changelog_entries_for_revision = lambda revision, changed_files=None: [ChangeLogEntry(_changelog1entry1)]
commitinfo = checkout.commit_info_for_revision(4)
self.assertEqual(commitinfo.bug_id(), 36629)
@@ -205,23 +207,20 @@
self.assertEqual(checkout.commit_info_for_revision(1), None)
def test_bug_id_for_revision(self):
- scm = Mock()
- scm.committer_email_for_revision = lambda revision: "[email protected]"
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.committer_email_for_revision = lambda revision: "[email protected]"
checkout.changelog_entries_for_revision = lambda revision, changed_files=None: [ChangeLogEntry(_changelog1entry1)]
self.assertEqual(checkout.bug_id_for_revision(4), 36629)
def test_bug_id_for_this_commit(self):
- scm = Mock()
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
checkout.commit_message_for_this_commit = lambda git_commit, changed_files=None: CommitMessage(ChangeLogEntry(_changelog1entry1).contents().splitlines())
self.assertEqual(checkout.bug_id_for_this_commit(git_commit=None), 36629)
def test_modified_changelogs(self):
- scm = Mock()
- scm.checkout_root = "/foo/bar"
- scm.changed_files = lambda git_commit: ["file1", "ChangeLog", "relative/path/ChangeLog"]
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.checkout_root = "/foo/bar"
+ checkout._scm.changed_files = lambda git_commit: ["file1", "ChangeLog", "relative/path/ChangeLog"]
expected_changlogs = ["/foo/bar/ChangeLog", "/foo/bar/relative/path/ChangeLog"]
self.assertEqual(checkout.modified_changelogs(git_commit=None), expected_changlogs)
@@ -236,11 +235,10 @@
return [3]
return [4, 8]
- scm = Mock()
- scm.checkout_root = "/foo/bar"
- scm.changed_files = lambda git_commit: ["file1", "file2", "relative/path/ChangeLog"]
- scm.revisions_changing_file = mock_revisions_changing_file
- checkout = Checkout(scm)
+ checkout = self._make_checkout()
+ checkout._scm.checkout_root = "/foo/bar"
+ checkout._scm.changed_files = lambda git_commit: ["file1", "file2", "relative/path/ChangeLog"]
+ checkout._scm.revisions_changing_file = mock_revisions_changing_file
checkout.changelog_entries_for_revision = mock_changelog_entries_for_revision
reviewers = checkout.suggested_reviewers(git_commit=None)
reviewer_names = [reviewer.full_name for reviewer in reviewers]
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -32,13 +32,20 @@
from webkitpy.common.memoized import memoized
from webkitpy.common.system.deprecated_logging import log
-from webkitpy.common.system.executive import Executive, run_command, ScriptError
+from webkitpy.common.system.executive import Executive, ScriptError
+from webkitpy.common.system import ospath
from .commitmessage import CommitMessage
from .scm import AuthenticationError, SCM, commit_error_handler
from .svn import SVN, SVNRepository
+def run_command(*args, **kwargs):
+ # FIXME: This should not be a global static.
+ # New code should use Executive.run_command directly instead
+ return Executive().run_command(*args, **kwargs)
+
+
class AmbiguousCommitError(Exception):
def __init__(self, num_local_commits, working_directory_is_clean):
self.num_local_commits = num_local_commits
@@ -95,14 +102,13 @@
def find_checkout_root(cls, path):
# "git rev-parse --show-cdup" would be another way to get to the root
(checkout_root, dot_git) = os.path.split(run_command(['git', 'rev-parse', '--git-dir'], cwd=(path or "./")))
- # If we were using 2.6 # checkout_root = os.path.relpath(checkout_root, path)
if not os.path.isabs(checkout_root): # Sometimes git returns relative paths
checkout_root = os.path.join(path, checkout_root)
return checkout_root
@classmethod
def to_object_name(cls, filepath):
- root_end_with_slash = os.path.join(cls.find_checkout_root(os.path.dirname(filepath)), '')
+ root_end_with_slash = self._filesystem.join(cls.find_checkout_root(self._filesystem.dirname(filepath)), '')
return filepath.replace(root_end_with_slash, '')
@classmethod
@@ -125,7 +131,7 @@
return self.run(['git', 'log', '--pretty=oneline', 'HEAD...' + self.remote_branch_ref()], cwd=self.checkout_root).splitlines()
def rebase_in_progress(self):
- return os.path.exists(os.path.join(self.checkout_root, '.git/rebase-apply'))
+ return self._filesystem.exists(self.absolute_path('.git', 'rebase-apply'))
def working_directory_is_clean(self):
return self.run(['git', 'diff', 'HEAD', '--name-only'], cwd=self.checkout_root) == ""
@@ -334,7 +340,8 @@
# We might be in a directory that's present in this branch but not in the
# trunk. Move up to the top of the tree so that git commands that expect a
# valid CWD won't fail after we check out the merge branch.
- os.chdir(self.checkout_root)
+ # FIXME: We should never be using chdir! We can instead pass cwd= to run_command/self.run!
+ self._filesystem.chdir(self.checkout_root)
# Stuff our change into the merge branch.
# We wrap in a try...finally block so if anything goes wrong, we clean up the branches.
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -30,14 +30,11 @@
# Python module for interacting with an SCM system (like SVN or Git)
import logging
-import os
import re
-import sys
-import shutil
from webkitpy.common.system.deprecated_logging import error, log
from webkitpy.common.system.executive import Executive, ScriptError
-from webkitpy.common.system import ospath
+from webkitpy.common.system.filesystem import FileSystem
class CheckoutNeedsUpdate(ScriptError):
@@ -61,11 +58,12 @@
# SCM methods are expected to return paths relative to self.checkout_root.
class SCM:
- def __init__(self, cwd, executive=None):
+ def __init__(self, cwd, executive=None, filesystem=None):
self.cwd = cwd
self.checkout_root = self.find_checkout_root(self.cwd)
self.dryrun = False
self._executive = executive or Executive()
+ self._filesystem = filesystem or FileSystem()
# A wrapper used by subclasses to create processes.
def run(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True, decode_output=True):
@@ -81,21 +79,21 @@
# SCM always returns repository relative path, but sometimes we need
# absolute paths to pass to rm, etc.
def absolute_path(self, repository_relative_path):
- return os.path.join(self.checkout_root, repository_relative_path)
+ return self._filesystem.join(self.checkout_root, repository_relative_path)
# FIXME: This belongs in Checkout, not SCM.
def scripts_directory(self):
- return os.path.join(self.checkout_root, "Tools", "Scripts")
+ return self._filesystem.join(self.checkout_root, "Tools", "Scripts")
# FIXME: This belongs in Checkout, not SCM.
def script_path(self, script_name):
- return os.path.join(self.scripts_directory(), script_name)
+ return self._filesystem.join(self.scripts_directory(), script_name)
def ensure_clean_working_directory(self, force_clean):
if self.working_directory_is_clean():
return
if not force_clean:
- # FIXME: Shouldn't this use cwd=self.checkout_root?
+ # FIXME: Shouldn't this use cwd=self.checkout_root? (Git definitely would want that, unclear if SVN would.)
print self.run(self.status_command(), error_handler=Executive.ignore_error)
raise ScriptError(message="Working directory has modifications, pass --force-clean or --no-clean to continue.")
log("Cleaning working directory")
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -49,7 +49,7 @@
from webkitpy.common.checkout.checkout import Checkout
from webkitpy.common.config.committers import Committer # FIXME: This should not be needed
from webkitpy.common.net.bugzilla import Attachment # FIXME: This should not be needed
-from webkitpy.common.system.executive import Executive, run_command, ScriptError
+from webkitpy.common.system.executive import Executive, ScriptError
from webkitpy.common.system.outputcapture import OutputCapture
from webkitpy.tool.mocktool import MockExecutive
@@ -79,6 +79,13 @@
# Eventually we will want to write tests which work for both scms. (like update_webkit, changed_files, etc.)
# Perhaps through some SCMTest base-class which both SVNTest and GitTest inherit from.
+
+def run_command(*args, **kwargs):
+ # FIXME: This should not be a global static.
+ # New code should use Executive.run_command directly instead
+ return Executive().run_command(*args, **kwargs)
+
+
# FIXME: This should be unified into one of the executive.py commands!
# Callers could use run_and_throw_if_fail(args, cwd=cwd, quiet=True)
def run_silent(args, cwd=None):
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -35,7 +35,7 @@
from webkitpy.common.memoized import memoized
from webkitpy.common.system.deprecated_logging import log
-from webkitpy.common.system.executive import Executive, run_command, ScriptError
+from webkitpy.common.system.executive import Executive, ScriptError
from webkitpy.common.system import ospath
from .scm import AuthenticationError, SCM, commit_error_handler
@@ -92,8 +92,8 @@
@classmethod
def value_from_svn_info(cls, path, field_name):
svn_info_args = ['svn', 'info', path]
- # FIXME: This should use an Executive.
- info_output = run_command(svn_info_args).rstrip()
+ # FIXME: This method should use a passed in executive or be made an instance method and use self._executive.
+ info_output = Executive().run_command(svn_info_args).rstrip()
match = re.search("^%s: (?P<value>.+)$" % field_name, info_output, re.MULTILINE)
if not match:
raise ScriptError(script_args=svn_info_args, message='svn info did not contain a %s.' % field_name)
Modified: trunk/Tools/Scripts/webkitpy/common/system/executive.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/system/executive.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/system/executive.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -96,12 +96,6 @@
return os.path.basename(command_path)
-def run_command(*args, **kwargs):
- # FIXME: This should not be a global static.
- # New code should use Executive.run_command directly instead
- return Executive().run_command(*args, **kwargs)
-
-
class Executive(object):
PIPE = subprocess.PIPE
STDOUT = subprocess.STDOUT
Modified: trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -33,7 +33,7 @@
import sys
import unittest
-from webkitpy.common.system.executive import Executive, run_command, ScriptError
+from webkitpy.common.system.executive import Executive, ScriptError
from webkitpy.common.system.filesystem_mock import MockFileSystem
from webkitpy.test import cat, echo
@@ -95,7 +95,7 @@
def test_run_command_with_bad_command(self):
def run_bad_command():
- run_command(["foo_bar_command_blah"], error_handler=Executive.ignore_error, return_exit_code=True)
+ Executive().run_command(["foo_bar_command_blah"], error_handler=Executive.ignore_error, return_exit_code=True)
self.failUnlessRaises(OSError, run_bad_command)
def test_run_command_args_type(self):
Modified: trunk/Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -359,6 +359,7 @@
# *) 2 files in /tmp for the text diffs for the two ports
# *) 2 files in /tmp for the image diffs for the two ports
# *) 1 file in /tmp for the rebaseline results html file
+ # FIXME: These numbers depend on MockSCM.exists() returning True for all files.
self.assertEqual(res, 0)
self.assertEqual(len(filesystem.written_files), 38)
Modified: trunk/Tools/Scripts/webkitpy/tool/mocktool.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/tool/mocktool.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/tool/mocktool.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -27,6 +27,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
+import StringIO
import threading
from webkitpy.common.config.committers import CommitterList, Reviewer
@@ -36,7 +37,6 @@
from webkitpy.common.system.deprecated_logging import log
from webkitpy.common.system.executive import ScriptError
from webkitpy.common.system.filesystem_mock import MockFileSystem
-from webkitpy.thirdparty.mock import Mock
def _id_to_object_dictionary(*objects):
@@ -207,11 +207,9 @@
}
-# FIXME: This should not inherit from Mock
-class MockBugzillaQueries(Mock):
+class MockBugzillaQueries(object):
def __init__(self, bugzilla):
- Mock.__init__(self)
self._bugzilla = bugzilla
def _all_bugs(self):
@@ -248,14 +246,14 @@
def fetch_bugs_matching_search(self, search_string, author_email=None):
return [self._bugzilla.fetch_bug(78), self._bugzilla.fetch_bug(77)]
+
_mock_reviewer = Reviewer("Foo Bar", "[email protected]")
# FIXME: Bugzilla is the wrong Mock-point. Once we have a BugzillaNetwork
# class we should mock that instead.
# Most of this class is just copy/paste from Bugzilla.
-# FIXME: This should not inherit from Mock
-class MockBugzilla(Mock):
+class MockBugzilla(object):
bug_server_url = "http://example.com"
@@ -270,7 +268,6 @@
_patch7)
def __init__(self):
- Mock.__init__(self)
self.queries = MockBugzillaQueries(self)
self.committers = CommitterList(reviewers=[_mock_reviewer])
self._override_patch = None
@@ -377,7 +374,22 @@
log(comment_text)
log("-- End comment --")
+ def add_cc_to_bug(self, bug_id, ccs):
+ pass
+ def obsolete_attachment(self, attachment_id, message=None):
+ pass
+
+ def reopen_bug(self, bug_id, message):
+ pass
+
+ def close_bug_as_fixed(self, bug_id, message):
+ pass
+
+ def clear_attachment_flags(self, attachment_id, message):
+ pass
+
+
class MockBuilder(object):
def __init__(self, name):
self._name = name
@@ -463,34 +475,68 @@
return MockFailureMap(self)
-# FIXME: This should not inherit from Mock
-class MockSCM(Mock):
+class MockSCM(object):
fake_checkout_root = os.path.realpath("/tmp") # realpath is needed to allow for Mac OS X's /private/tmp
- def __init__(self, filesystem=None):
- Mock.__init__(self)
+ def __init__(self, filesystem=None, executive=None):
# FIXME: We should probably use real checkout-root detection logic here.
# os.getcwd() can't work here because other parts of the code assume that "checkout_root"
# will actually be the root. Since getcwd() is wrong, use a globally fake root for now.
self.checkout_root = self.fake_checkout_root
self.added_paths = set()
- self._filesystem = filesystem
+ self._filesystem = filesystem or MockFileSystem()
+ self._executive = executive or MockExecutive()
def add(self, destination_path, return_exit_code=False):
self.added_paths.add(destination_path)
if return_exit_code:
return 0
+ def ensure_clean_working_directory(self, force_clean):
+ pass
+
+ def supports_local_commits(self):
+ return True
+
+ def ensure_no_local_commits(self, force_clean):
+ pass
+
+ def exists(self, path):
+ # TestRealMain.test_real_main (and several other rebaseline tests) are sensitive to this return value.
+ # We should make those tests more robust, but for now we just return True always (since no test needs otherwise).
+ return True
+
+ def absolute_path(self, *comps):
+ return self._filesystem.join(self.checkout_root, *comps)
+
def changed_files(self, git_commit=None):
return ["MockFile1"]
+ def changed_files_for_revision(self, revision):
+ return ["MockFile1"]
+
+ def head_svn_revision(self):
+ return 1234
+
def create_patch(self, git_commit, changed_files=None):
return "Patch1"
def commit_ids_from_commitish_arguments(self, args):
return ["Commitish1", "Commitish2"]
+ def committer_email_for_revision(self, revision):
+ return "[email protected]"
+
+ def commit_locally_with_message(self, message):
+ pass
+
+ def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
+ pass
+
+ def merge_base(self, git_commit):
+ return None
+
def commit_message_for_local_commit(self, commit_id):
if commit_id == "Commitish1":
return CommitMessage("CommitMessage1\n" \
@@ -504,8 +550,7 @@
return path + '-diff'
def diff_for_revision(self, revision):
- return "DiffForRevision%s\n" \
- "http://bugs.webkit.org/show_bug.cgi?id=12345" % revision
+ return "DiffForRevision%s\nhttp://bugs.webkit.org/show_bug.cgi?id=12345" % revision
def show_head(self, path):
return path
@@ -528,6 +573,10 @@
log("MOCK: MockDEPS.write_variable(%s, %s)" % (name, value))
+class MockCommitMessage(object):
+ def message(self):
+ return "This is a fake commit message that is at least 50 characters."
+
class MockCheckout(object):
_committer_list = CommitterList()
@@ -564,9 +613,7 @@
return []
def commit_message_for_this_commit(self, git_commit, changed_files=None):
- commit_message = Mock()
- commit_message.message = lambda:"This is a fake commit message that is at least 50 characters."
- return commit_message
+ return MockCommitMessage()
def chromium_deps(self):
return MockDEPS()
@@ -666,9 +713,8 @@
return "http://dummy_url"
-# FIXME: This should not inherit from Mock
# FIXME: Unify with common.system.executive_mock.MockExecutive.
-class MockExecutive(Mock):
+class MockExecutive(object):
def __init__(self, should_log=False, should_throw=False):
self._should_log = should_log
self._should_throw = should_throw
@@ -706,7 +752,7 @@
self.__dict__[key] = value
-class MockPort(Mock):
+class MockPort(object):
def name(self):
return "MockPort"
@@ -719,7 +765,28 @@
def update_webkit_command(self):
return ["mock-update-webkit"]
+ def build_webkit_command(self, build_style=None):
+ return ["mock-build-webkit"]
+ def run_bindings_tests_command(self):
+ return ["mock-run-bindings-tests"]
+
+ def prepare_changelog_command(self):
+ return ['mock-prepare-ChangeLog']
+
+ def run_python_unittests_command(self):
+ return ['mock-test-webkitpy']
+
+ def run_perl_unittests_command(self):
+ return ['mock-test-webkitperl']
+
+ def run_javascriptcore_tests_command(self):
+ return ['mock-run-javacriptcore-tests']
+
+ def run_webkit_tests_command(self):
+ return ['mock-run-webkit-tests']
+
+
class MockTestPort1(object):
def skips_layout_test(self, test_name):
@@ -764,11 +831,13 @@
self.buildbot = MockBuildBot()
self.executive = MockExecutive(should_log=log_executive)
self.web = MockWeb()
- self.filesystem = MockFileSystem()
self.workspace = MockWorkspace()
self._irc = None
self.user = MockUser()
self._scm = MockSCM()
+ # Various pieces of code (wrongly) call filesystem.chdir(checkout_root).
+ # Making the checkout_root exist in the mock filesystem makes that chdir not raise.
+ self.filesystem = MockFileSystem(dirs=set([self._scm.checkout_root]))
self._port = MockPort()
self._checkout = MockCheckout()
self.status_server = MockStatusServer()
@@ -809,4 +878,4 @@
self.params[key] = value
def submit(self):
- return Mock(file)
+ return StringIO.StringIO()
Modified: trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -47,10 +47,6 @@
def run(self, state):
if not self._options.clean:
return
- # FIXME: This chdir should not be necessary and can be removed as
- # soon as ensure_no_local_commits and ensure_clean_working_directory
- # are known to set the CWD to checkout_root when calling run_command.
- os.chdir(self._tool.scm().checkout_root)
if not self._allow_local_commits:
self._tool.scm().ensure_no_local_commits(self._options.force_clean)
self._tool.scm().ensure_clean_working_directory(force_clean=self._options.force_clean)
Modified: trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory_unittest.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory_unittest.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/cleanworkingdirectory_unittest.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -36,6 +36,8 @@
class CleanWorkingDirectoryTest(unittest.TestCase):
def test_run(self):
tool = MockTool()
+ tool._scm = Mock()
+ tool._scm.checkout_root = '/mock'
step = CleanWorkingDirectory(tool, MockOptions(clean=True, force_clean=False))
step.run({})
self.assertEqual(tool._scm.ensure_no_local_commits.call_count, 1)
@@ -43,6 +45,7 @@
def test_no_clean(self):
tool = MockTool()
+ tool._scm = Mock()
step = CleanWorkingDirectory(tool, MockOptions(clean=False))
step.run({})
self.assertEqual(tool._scm.ensure_no_local_commits.call_count, 0)
Modified: trunk/Tools/Scripts/webkitpy/tool/steps/ensurelocalcommitifneeded.py (90977 => 90978)
--- trunk/Tools/Scripts/webkitpy/tool/steps/ensurelocalcommitifneeded.py 2011-07-14 04:13:19 UTC (rev 90977)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/ensurelocalcommitifneeded.py 2011-07-14 05:05:10 UTC (rev 90978)
@@ -40,4 +40,4 @@
def run(self, state):
if self._options.local_commit and not self._tool.scm().supports_local_commits():
- error("--local-commit passed, but %s does not support local commits" % self._tool.scm.display_name())
+ error("--local-commit passed, but %s does not support local commits" % self._tool.scm().display_name())