2010-08-17 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Aug 2010 23:11:25 +0000 (23:11 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Aug 2010 23:11:25 +0000 (23:11 +0000)
        Reviewed by Eric Seidel.

        fix test-webkitpy, add easy way to find a checkout root

        test-webkitpy currently doesn't work right if run from someplace other
        than the checkout root, and it spews a bunch of debug logging because
        the deduplicate_tests tests contaminates the test environment.

        This patch cleans up the deduplicate_tests unit tests, and creates
        two new methods in scm.py: find_checkout_root() and default_scm(),
        both of which use a single algorithm for guessing what checkout root
        to use if you aren't explicitly told one from a path.

        https://bugs.webkit.org/show_bug.cgi?id=44001

        * Scripts/deduplicate-tests:
        * Scripts/webkitpy/common/checkout/scm.py:
        * Scripts/webkitpy/common/checkout/scm_unittest.py:
        * Scripts/webkitpy/layout_tests/deduplicate_tests.py:
        * Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:
        * Scripts/webkitpy/layout_tests/port/test.py:
        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests.py:
        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
        * Scripts/webkitpy/tool/main.py:

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

WebKitTools/ChangeLog
WebKitTools/Scripts/deduplicate-tests
WebKitTools/Scripts/webkitpy/common/checkout/scm.py
WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py
WebKitTools/Scripts/webkitpy/layout_tests/deduplicate_tests.py
WebKitTools/Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py
WebKitTools/Scripts/webkitpy/layout_tests/port/test.py
WebKitTools/Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests.py
WebKitTools/Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py
WebKitTools/Scripts/webkitpy/tool/main.py

index 4a30149ee2047322a74fd7e3dca9775f6f315506..0bc80e5b33e20e67f5e92ff6084251513d2bb562 100644 (file)
@@ -1,3 +1,30 @@
+2010-08-17  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        fix test-webkitpy, add easy way to find a checkout root
+
+        test-webkitpy currently doesn't work right if run from someplace other
+        than the checkout root, and it spews a bunch of debug logging because
+        the deduplicate_tests tests contaminates the test environment.
+
+        This patch cleans up the deduplicate_tests unit tests, and creates
+        two new methods in scm.py: find_checkout_root() and default_scm(),
+        both of which use a single algorithm for guessing what checkout root
+        to use if you aren't explicitly told one from a path.
+
+        https://bugs.webkit.org/show_bug.cgi?id=44001
+
+        * Scripts/deduplicate-tests:
+        * Scripts/webkitpy/common/checkout/scm.py:
+        * Scripts/webkitpy/common/checkout/scm_unittest.py:
+        * Scripts/webkitpy/layout_tests/deduplicate_tests.py:
+        * Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:
+        * Scripts/webkitpy/layout_tests/port/test.py:
+        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests.py:
+        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
+        * Scripts/webkitpy/tool/main.py:
+
 2010-08-17  Victor Wang  <victorw@chromium.org>
 
         Reviewed by Ojan Vafai.
index 11ba7c21d678845d640e4f91585abc67aeb44003..f0afe13458b638a4da23ac125a54da3df9f63d10 100644 (file)
@@ -36,6 +36,7 @@ This command dumps out all such files.  You can use it like this:
 
 
 import optparse
+import webkitpy.common.system.logutils as logutils
 import webkitpy.layout_tests.deduplicate_tests as deduplicate_tests
 
 
@@ -62,6 +63,7 @@ def parse_args():
 
 
 def run(options):
+    logutils.configure_logging()
     if options.verbose:
         format = ("* %(test)s\n"
                   "\tredundantly on %(platform)s and %(fallback)s\n"
index 569558a8f9907e08ce1f0d0216fa4a0f69ce4769..5a6c48c0f5b37034aff2a07d82c880bfefc77d5a 100644 (file)
@@ -38,6 +38,40 @@ from webkitpy.common.system.executive import Executive, run_command, ScriptError
 from webkitpy.common.system.deprecated_logging import error, log
 
 
+def find_checkout_root():
+    """Returns the current checkout root (as determined by default_scm().
+
+    Returns the absolute path to the top of the WebKit checkout, or None
+    if it cannot be determined.
+
+    """
+    scm_system = default_scm()
+    if scm_system:
+        return scm_system.checkout_root
+    return None
+
+
+def default_scm():
+    """Return the default SCM object as determined by the CWD and running code.
+
+    Returns the default SCM object for the current working directory; if the
+    CWD is not in a checkout, then we attempt to figure out if the SCM module
+    itself is part of a checkout, and return that one. If neither is part of
+    a checkout, None is returned.
+
+    """
+    cwd = os.getcwd()
+    scm_system = detect_scm_system(cwd)
+    if not scm_system:
+        script_directory = os.path.abspath(sys.path[0])
+        scm_system = detect_scm_system(script_directory)
+        if scm_system:
+            log("The current directory (%s) is not a WebKit checkout, using %s" % (cwd, scm_system.checkout_root))
+        else:
+            error("FATAL: Failed to determine the SCM system for either %s or %s" % (cwd, script_directory))
+    return scm_system
+
+
 def detect_scm_system(path):
     absolute_path = os.path.abspath(path)
 
index 852f838e5a9f16fd26e21b71e37bfa613d3daeab..87d5539b584ce0378b1b82fdc334b12c70a7dc9c 100644 (file)
@@ -36,6 +36,7 @@ import os
 import os.path
 import re
 import stat
+import sys
 import subprocess
 import tempfile
 import unittest
@@ -44,10 +45,11 @@ import shutil
 
 from datetime import date
 from webkitpy.common.checkout.api import Checkout
-from webkitpy.common.checkout.scm import detect_scm_system, SCM, SVN, CheckoutNeedsUpdate, commit_error_handler, AuthenticationError, AmbiguousCommitError
+from webkitpy.common.checkout.scm import detect_scm_system, SCM, SVN, CheckoutNeedsUpdate, commit_error_handler, AuthenticationError, AmbiguousCommitError, find_checkout_root, default_scm
 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.outputcapture import OutputCapture
 
 # 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.
@@ -174,6 +176,57 @@ class SVNTestRepository:
         # Change back to a valid directory so that later calls to os.getcwd() do not fail.
         os.chdir(detect_scm_system(os.path.dirname(__file__)).checkout_root)
 
+
+class StandaloneFunctionsTest(unittest.TestCase):
+    """This class tests any standalone/top-level functions in the package."""
+    def setUp(self):
+        self.orig_cwd = os.path.abspath(os.getcwd())
+        self.orig_abspath = os.path.abspath
+
+        # We capture but ignore the output from stderr to reduce unwanted
+        # logging.
+        self.output = OutputCapture()
+        self.output.capture_output()
+
+    def tearDown(self):
+        os.chdir(self.orig_cwd)
+        os.path.abspath = self.orig_abspath
+        self.output.restore_output()
+
+    def test_find_checkout_root(self):
+        # Test from inside the tree.
+        os.chdir(sys.path[0])
+        dir = find_checkout_root()
+        self.assertNotEqual(dir, None)
+        self.assertTrue(os.path.exists(dir))
+
+        # Test from outside the tree.
+        os.chdir(os.path.expanduser("~"))
+        dir = find_checkout_root()
+        self.assertNotEqual(dir, None)
+        self.assertTrue(os.path.exists(dir))
+
+        # Mock out abspath() to test being not in a checkout at all.
+        os.path.abspath = lambda x: "/"
+        self.assertRaises(SystemExit, find_checkout_root)
+        os.path.abspath = self.orig_abspath
+
+    def test_default_scm(self):
+        # Test from inside the tree.
+        os.chdir(sys.path[0])
+        scm = default_scm()
+        self.assertNotEqual(scm, None)
+
+        # Test from outside the tree.
+        os.chdir(os.path.expanduser("~"))
+        dir = find_checkout_root()
+        self.assertNotEqual(dir, None)
+
+        # Mock out abspath() to test being not in a checkout at all.
+        os.path.abspath = lambda x: "/"
+        self.assertRaises(SystemExit, default_scm)
+        os.path.abspath = self.orig_abspath
+
 # For testing the SCM baseclass directly.
 class SCMClassTests(unittest.TestCase):
     def setUp(self):
index 7a9cdae047e3fa9fa586ae33afb3e85ab6432dda..bb63f5e66930f890d739456d42a833507e4a4681 100644 (file)
@@ -41,7 +41,6 @@ import webkitpy.common.system.logutils as logutils
 import webkitpy.layout_tests.port.factory as port_factory
 
 _log = logutils.get_logger(__file__)
-logutils.configure_logging()
 
 _BASE_PLATFORM = 'base'
 
index 878331a77f4488de8af2d5a8bfa3e9d41b9da84f..66dda32a0786bedf043dd4dd08429ab19fbd0284 100644 (file)
@@ -27,6 +27,7 @@
 import deduplicate_tests
 import os
 import unittest
+import webkitpy.common.checkout.scm as scm
 
 
 class MockExecutive(object):
@@ -51,6 +52,13 @@ class ListDuplicatesTest(unittest.TestCase):
         MockExecutive.last_run_command = []
         MockExecutive.response = ''
         deduplicate_tests.executive = MockExecutive
+        self._original_cwd = os.getcwd()
+        checkout_root = scm.find_checkout_root()
+        self.assertNotEqual(checkout_root, None)
+        os.chdir(checkout_root)
+
+    def tearDown(self):
+        os.chdir(self._original_cwd)
 
     def test_parse_git_output(self):
         git_output = (
index 6eef54e967091ca64a187fcefa6bb5c36c447063..9c9ab0ae235532f5a79a45eda7060abdc03ac74c 100644 (file)
@@ -124,6 +124,9 @@ class TestPort(base.Port):
     def test_platform_names(self):
         return self.test_base_platform_names()
 
+    def test_platform_name_to_name(self, test_platform_name):
+        return test_platform_name
+
     def version():
         return ''
 
index fa4df9b66809caa226e442e9ca170e5b16f5cc44..92f103258246268e54cfa0251777e6db4f04039e 100644 (file)
@@ -59,7 +59,6 @@ import webbrowser
 import zipfile
 
 from webkitpy.common.system.executive import run_command, ScriptError
-from webkitpy.common.checkout.scm import detect_scm_system
 import webkitpy.common.checkout.scm as scm
 
 import port
@@ -240,7 +239,7 @@ class Rebaseliner(object):
                                                self._platform,
                                                False,
                                                False)
-        self._scm = detect_scm_system(os.getcwd())
+        self._scm = scm.default_scm()
 
     def run(self, backup):
         """Run rebaseline process."""
index fa03238a5509d10dfec05246fbcc170963e4539e..121b64eade35c7b7f6843f2c224982d1cec72314 100644 (file)
@@ -84,5 +84,19 @@ class TestGetHostPortObject(unittest.TestCase):
         port.get = old_get
 
 
+class TestRebaseliner(unittest.TestCase):
+
+    def test_noop(self):
+        # this method tests that was can at least instantiate an object, even
+        # if there is nothing to do.
+        options = MockOptions()
+        host_port_obj = port.get('test', options)
+        target_options = options
+        target_port_obj = port.get('test', target_options)
+        platform = 'test'
+        rebaseliner = rebaseline_chromium_webkit_tests.Rebaseliner(
+            host_port_obj, target_port_obj, platform, options)
+        self.assertNotEqual(rebaseliner, None)
+
 if __name__ == '__main__':
     unittest.main()
index 1f431454e8dfe6290a8be58bafcc8bd962b2ea82..0dd50172f890f61d08144f7646c166b903725336 100755 (executable)
@@ -33,7 +33,7 @@ import os
 import threading
 
 from webkitpy.common.checkout.api import Checkout
-from webkitpy.common.checkout.scm import detect_scm_system
+from webkitpy.common.checkout.scm import default_scm
 from webkitpy.common.net.bugzilla import Bugzilla
 from webkitpy.common.net.buildbot import BuildBot
 from webkitpy.common.net.rietveld import Rietveld
@@ -79,18 +79,8 @@ class WebKitPatch(MultiCommandTool):
 
     def scm(self):
         # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands).
-        original_cwd = os.path.abspath(".")
         if not self._scm:
-            self._scm = detect_scm_system(original_cwd)
-
-        if not self._scm:
-            script_directory = os.path.abspath(sys.path[0])
-            self._scm = detect_scm_system(script_directory)
-            if self._scm:
-                log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, self._scm.checkout_root))
-            else:
-                error("FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, script_directory))
-
+            self._scm = default_scm()
         return self._scm
 
     def checkout(self):