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
+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.
import optparse
+import webkitpy.common.system.logutils as logutils
import webkitpy.layout_tests.deduplicate_tests as deduplicate_tests
def run(options):
+ logutils.configure_logging()
if options.verbose:
format = ("* %(test)s\n"
"\tredundantly on %(platform)s and %(fallback)s\n"
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)
import os.path
import re
import stat
+import sys
import subprocess
import tempfile
import unittest
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.
# 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):
import webkitpy.layout_tests.port.factory as port_factory
_log = logutils.get_logger(__file__)
-logutils.configure_logging()
_BASE_PLATFORM = 'base'
import deduplicate_tests
import os
import unittest
+import webkitpy.common.checkout.scm as scm
class MockExecutive(object):
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 = (
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 ''
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
self._platform,
False,
False)
- self._scm = detect_scm_system(os.getcwd())
+ self._scm = scm.default_scm()
def run(self, backup):
"""Run rebaseline process."""
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()
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
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):