Fixing webkitpy's SCM unit tests.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2013 03:20:29 +0000 (03:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2013 03:20:29 +0000 (03:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106429

Patch by Tim 'mithro' Ansell <mithro@mithis.com> on 2013-01-17
Reviewed by Eric Seidel.

* Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
(SCMDetectorTest.test_detect_scm_system):
* Scripts/webkitpy/common/checkout/scm/git.py:
(Git.in_working_directory):
(Git.read_git_config):
(Git._assert_can_squash):
(Git.remote_branch_ref):
* Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
(GitSVNTest.test_commit_with_message_multiple_local_commits_always_squash):
(GitTestWithMock):
(GitTestWithMock.make_scm):
(GitTestWithMock.test_create_patch):
* Scripts/webkitpy/common/system/outputcapture.py:
(OutputCapture.assert_outputs):
(OutputCaptureTestCaseBase):
* Scripts/webkitpy/test/printer.py:
(Printer.configure):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140089 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/scm/detection_unittest.py
Tools/Scripts/webkitpy/common/checkout/scm/git.py
Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py
Tools/Scripts/webkitpy/common/checkout/scm/svn.py
Tools/Scripts/webkitpy/common/system/outputcapture.py
Tools/Scripts/webkitpy/test/printer.py

index d477c2a..4f8b656 100644 (file)
@@ -1,3 +1,28 @@
+2013-01-17  Tim 'mithro' Ansell  <mithro@mithis.com>
+
+        Fixing webkitpy's SCM unit tests.
+        https://bugs.webkit.org/show_bug.cgi?id=106429
+
+        Reviewed by Eric Seidel.
+
+        * Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
+        (SCMDetectorTest.test_detect_scm_system):
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git.in_working_directory):
+        (Git.read_git_config):
+        (Git._assert_can_squash):
+        (Git.remote_branch_ref):
+        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+        (GitSVNTest.test_commit_with_message_multiple_local_commits_always_squash):
+        (GitTestWithMock):
+        (GitTestWithMock.make_scm):
+        (GitTestWithMock.test_create_patch):
+        * Scripts/webkitpy/common/system/outputcapture.py:
+        (OutputCapture.assert_outputs):
+        (OutputCaptureTestCaseBase):
+        * Scripts/webkitpy/test/printer.py:
+        (Printer.configure):
+
 2013-01-17  Julie Parent  <jparent@chromium.org>
 
         Flakiness dashboard assumes there must be ToT tests
index 1d74848..3a15466 100644 (file)
@@ -28,7 +28,7 @@
 # (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 unittest
+import unittest2 as unittest
 
 from .detection import SCMDetector
 from webkitpy.common.system.filesystem_mock import MockFileSystem
@@ -42,7 +42,10 @@ class SCMDetectorTest(unittest.TestCase):
         executive = MockExecutive(should_log=True)
         detector = SCMDetector(filesystem, executive)
 
-        expected_logs = "MOCK run_command: ['svn', 'info'], cwd=/\nMOCK run_command: ['git', 'rev-parse', '--is-inside-work-tree'], cwd=/\n"
+        expected_logs = """\
+MOCK run_command: ['svn', 'info'], cwd=/
+MOCK run_command: ['git', 'rev-parse', '--is-inside-work-tree'], cwd=/
+"""
         scm = OutputCapture().assert_outputs(self, detector.detect_scm_system, ["/"], expected_logs=expected_logs)
         self.assertEqual(scm, None)
         # FIXME: This should make a synthetic tree and test SVN and Git detection in that tree.
index 4e18a5f..fd3597f 100644 (file)
@@ -41,12 +41,6 @@ from .svn import SVN, SVNRepository
 _log = logging.getLogger(__name__)
 
 
-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, has_working_directory_changes):
         Exception.__init__(self, "Found %s local commits and the working directory is %s" % (
@@ -128,12 +122,13 @@ class Git(SCM, SVNRepository):
         return filepath.replace(root_end_with_slash, '')
 
     @classmethod
-    def read_git_config(cls, key, cwd=None):
+    def read_git_config(cls, key, cwd=None, executive=None):
         # FIXME: This should probably use cwd=self.checkout_root.
         # Pass --get-all for cases where the config has multiple values
         # Pass the cwd if provided so that we can handle the case of running webkit-patch outside of the working directory.
         # FIXME: This should use an Executive.
-        return run_command([cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
+        executive = executive or Executive()
+        return executive.run_command([cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
 
     @staticmethod
     def commit_success_regexp():
@@ -184,7 +179,7 @@ class Git(SCM, SVNRepository):
 
     def _upstream_branch(self):
         current_branch = self._current_branch()
-        return self._branch_from_ref(self.read_git_config('branch.%s.merge' % current_branch, cwd=self.checkout_root).strip())
+        return self._branch_from_ref(self.read_git_config('branch.%s.merge' % current_branch, cwd=self.checkout_root, executive=self._executive).strip())
 
     def merge_base(self, git_commit):
         if git_commit:
@@ -337,7 +332,7 @@ class Git(SCM, SVNRepository):
         self._run_git(['checkout', 'HEAD'] + file_paths)
 
     def _assert_can_squash(self, has_working_directory_changes):
-        squash = Git.read_git_config('webkit-patch.commit-should-always-squash', cwd=self.checkout_root)
+        squash = self.read_git_config('webkit-patch.commit-should-always-squash', cwd=self.checkout_root, executive=self._executive)
         should_squash = squash and squash.lower() == "true"
 
         if not should_squash:
@@ -437,7 +432,7 @@ class Git(SCM, SVNRepository):
 
     def remote_branch_ref(self):
         # Use references so that we can avoid collisions, e.g. we don't want to operate on refs/heads/trunk if it exists.
-        remote_branch_refs = Git.read_git_config('svn-remote.svn.fetch', cwd=self.checkout_root)
+        remote_branch_refs = self.read_git_config('svn-remote.svn.fetch', cwd=self.checkout_root, executive=self._executive)
         if not remote_branch_refs:
             remote_master_ref = 'refs/remotes/origin/master'
             if not self._branch_ref_exists(remote_master_ref):
index 0023409..7bebc28 100644 (file)
@@ -49,6 +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, ScriptError
+from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.common.system.outputcapture import OutputCapture
 from webkitpy.common.system.executive_mock import MockExecutive
 from .git import Git, AmbiguousCommitError
@@ -1239,8 +1240,8 @@ class GitSVNTest(SCMTest):
         self.assertRaises(ScriptError, self.scm.commit_with_message, "another test commit", git_commit="HEAD^")
 
     def test_commit_with_message_multiple_local_commits_always_squash(self):
+        run_command(['git', 'config', 'webkit-patch.commit-should-always-squash', 'true'])
         self._two_local_commits()
-        self.scm._assert_can_squash = lambda working_directory_is_clean: True
         commit_text = self.scm.commit_with_message("yet another test commit")
         self.assertEqual(self.scm.svn_revision_from_commit_text(commit_text), '6')
 
@@ -1547,16 +1548,23 @@ class GitSVNTest(SCMTest):
 # We need to split off more of these SCM tests to use mocks instead of the filesystem.
 # This class is the first part of that.
 class GitTestWithMock(unittest.TestCase):
+    maxDiff = None
+
     def make_scm(self, logging_executive=False):
         # We do this should_log dance to avoid logging when Git.__init__ runs sysctl on mac to check for 64-bit support.
-        scm = Git(cwd=None, executive=MockExecutive())
+        scm = Git(cwd=".", executive=MockExecutive(), filesystem=MockFileSystem())
+        scm.read_git_config = lambda *args, **kw: "MOCKKEY:MOCKVALUE"
         scm._executive._should_log = logging_executive
         return scm
 
     def test_create_patch(self):
         scm = self.make_scm(logging_executive=True)
-        expected_stderr = "MOCK run_command: ['git', 'merge-base', u'refs/remotes/origin/master', 'HEAD'], cwd=%(checkout)s\nMOCK run_command: ['git', 'diff', '--binary', '--no-ext-diff', '--full-index', '-M', 'MOCK output of child process', '--'], cwd=%(checkout)s\nMOCK run_command: ['git', 'log', '-25'], cwd=None\n" % {'checkout': scm.checkout_root}
-        OutputCapture().assert_outputs(self, scm.create_patch, expected_stderr=expected_stderr)
+        expected_stderr = """\
+MOCK run_command: ['git', 'merge-base', 'MOCKVALUE', 'HEAD'], cwd=%(checkout)s
+MOCK run_command: ['git', 'diff', '--binary', '--no-color', '--no-ext-diff', '--full-index', '--no-renames', '', 'MOCK output of child process', '--'], cwd=%(checkout)s
+MOCK run_command: ['git', 'log', '-25', './MOCK output of child process'], cwd=%(checkout)s
+""" % {'checkout': scm.checkout_root}
+        OutputCapture().assert_outputs(self, scm.create_patch, expected_logs=expected_stderr)
 
     def test_push_local_commits_to_server_with_username_and_password(self):
         self.assertEqual(self.make_scm().push_local_commits_to_server(username='dbates@webkit.org', password='blah'), "MOCK output of child process")
index 87f717b..91e30cb 100644 (file)
 
 import logging
 import os
+import random
 import re
 import shutil
+import string
 import sys
 import tempfile
 
@@ -271,11 +273,12 @@ class SVN(SCM, SVNRepository):
         return self._run_svn(['diff', '-c', revision])
 
     def _bogus_dir_name(self):
+        rnd = ''.join(random.sample(string.ascii_letters, 5))
         if sys.platform.startswith("win"):
             parent_dir = tempfile.gettempdir()
         else:
             parent_dir = sys.path[0]  # tempdir is not secure.
-        return os.path.join(parent_dir, "temp_svn_config")
+        return os.path.join(parent_dir, "temp_svn_config_" + rnd)
 
     def _setup_bogus_dir(self, log):
         self._bogus_dir = self._bogus_dir_name()
index 26670d2..516aba2 100644 (file)
@@ -29,8 +29,8 @@
 # Class for unittest support.  Used for capturing stderr/stdout.
 
 import logging
+import unittest2 as unittest
 import sys
-import unittest
 from StringIO import StringIO
 
 
@@ -94,15 +94,22 @@ class OutputCapture(object):
         finally:
             (stdout_string, stderr_string, logs_string) = self.restore_output()
 
-        testcase.assertEqual(stdout_string, expected_stdout)
-        testcase.assertEqual(stderr_string, expected_stderr)
+        if hasattr(testcase, 'assertMultiLineEqual'):
+            testassert = testcase.assertMultiLineEqual
+        else:
+            testassert = testcase.assertEqual
+
+        testassert(stdout_string, expected_stdout)
+        testassert(stderr_string, expected_stderr)
         if expected_logs is not None:
-            testcase.assertEqual(logs_string, expected_logs)
+            testassert(logs_string, expected_logs)
         # This is a little strange, but I don't know where else to return this information.
         return return_value
 
 
 class OutputCaptureTestCaseBase(unittest.TestCase):
+    maxDiff = None
+
     def setUp(self):
         unittest.TestCase.setUp(self)
         self.output_capture = OutputCapture()
index 049058d..f4a4b06 100644 (file)
@@ -24,7 +24,6 @@
 import logging
 import StringIO
 
-from webkitpy.common.system import outputcapture
 from webkitpy.common.system.systemhost import SystemHost
 from webkitpy.layout_tests.views.metered_stream import MeteredStream
 
@@ -104,6 +103,8 @@ class Printer(object):
         handler.addFilter(testing_filter)
 
         if self.options.pass_through:
+            # FIXME: Can't import at top of file, as outputcapture needs unittest2
+            from webkitpy.common.system import outputcapture
             outputcapture.OutputCapture.stream_wrapper = _CaptureAndPassThroughStream
 
     def write_update(self, msg):