Commit 477e780e authored by cjerdonek@webkit.org's avatar cjerdonek@webkit.org
Browse files

The test-webkitpy script now warns the user if the script is

being run using a Python version different from the minimum
version the webkitpy package was meant to support.

Reviewed by Adam Barth.

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

Warning developers if their Python version is too low will help
them understand why test-webkitpy is failing.  Secondly, warning
developers if their Python version is higher than the minimum will
help them understand that their changes may not be okay for the
minimum supported version, even if test-webkitpy is passing.

* Scripts/test-webkitpy:
  - Moved the "from ..._unittest import *" lines to the new
    file Scripts/webkitpy/unittests.py.  This will allow the
    version-check warning to be displayed even if an error occurs
    while interpreting (i.e. importing) the unit test code.
  - Added configure_logging() to configur logging for test-webkitpy.
  - Added an init() method to configure logging and check the
    current Python version.

* Scripts/webkitpy/init/unittests.py: Added.
  - Added a file to import all unit test modules in the
    webkitpy.init package.

* Scripts/webkitpy/init/versioning.py: Added.
  - Added a _MINIMUM_SUPPORTED_PYTHON_VERSION variable and set
    it equal to 2.5.
  - Added a compare_version() method to compare the current Python
    version against a target version.
  - Added a check_version() method to check the current Python
    version against the current minimum supported version, and to
    log a warning message if the check fails.

* Scripts/webkitpy/init/versioning_unittest.py: Added.
  - Added unit tests for the functions in versioning.py.

* Scripts/webkitpy/style/unittests.py:
  - Fixed/updated a code comment.

* Scripts/webkitpy/unittests.py: Added.
  - Moved the "from ..._unittest import *" lines from test-webkitpy.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55970 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c0032ce1
2010-03-13 Chris Jerdonek <cjerdonek@webkit.org>
Reviewed by Adam Barth.
The test-webkitpy script now warns the user if the script is
being run using a Python version different from the minimum
version the webkitpy package was meant to support.
https://bugs.webkit.org/show_bug.cgi?id=35788
Warning developers if their Python version is too low will help
them understand why test-webkitpy is failing. Secondly, warning
developers if their Python version is higher than the minimum will
help them understand that their changes may not be okay for the
minimum supported version, even if test-webkitpy is passing.
* Scripts/test-webkitpy:
- Moved the "from ..._unittest import *" lines to the new
file Scripts/webkitpy/unittests.py. This will allow the
version-check warning to be displayed even if an error occurs
while interpreting (i.e. importing) the unit test code.
- Added configure_logging() to configur logging for test-webkitpy.
- Added an init() method to configure logging and check the
current Python version.
* Scripts/webkitpy/init/unittests.py: Added.
- Added a file to import all unit test modules in the
webkitpy.init package.
* Scripts/webkitpy/init/versioning.py: Added.
- Added a _MINIMUM_SUPPORTED_PYTHON_VERSION variable and set
it equal to 2.5.
- Added a compare_version() method to compare the current Python
version against a target version.
- Added a check_version() method to check the current Python
version against the current minimum supported version, and to
log a warning message if the check fails.
* Scripts/webkitpy/init/versioning_unittest.py: Added.
- Added unit tests for the functions in versioning.py.
* Scripts/webkitpy/style/unittests.py:
- Fixed/updated a code comment.
* Scripts/webkitpy/unittests.py: Added.
- Moved the "from ..._unittest import *" lines from test-webkitpy.
2010-03-13 Chris Jerdonek <cjerdonek@webkit.org>
 
Reviewed by Adam Barth.
......
#!/usr/bin/env python
# Copyright (c) 2009 Google Inc. All rights reserved.
# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
......@@ -27,41 +28,54 @@
# (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 logging
import sys
import unittest
from webkitpy.bugzilla_unittest import *
from webkitpy.buildbot_unittest import *
from webkitpy.changelogs_unittest import *
from webkitpy.commands.download_unittest import *
from webkitpy.commands.early_warning_system_unittest import *
from webkitpy.commands.openbugs_unittest import OpenBugsTest
from webkitpy.commands.upload_unittest import *
from webkitpy.commands.queries_unittest import *
from webkitpy.commands.queues_unittest import *
from webkitpy.committers_unittest import *
from webkitpy.credentials_unittest import *
from webkitpy.diff_parser_unittest import *
from webkitpy.executive_unittest import *
from webkitpy.grammar_unittest import *
from webkitpy.layout_tests.port.mac_unittest import *
from webkitpy.multicommandtool_unittest import *
from webkitpy.networktransaction_unittest import *
from webkitpy.patchcollection_unittest import *
from webkitpy.queueengine_unittest import *
from webkitpy.steps.steps_unittest import *
from webkitpy.steps.closebugforlanddiff_unittest import *
from webkitpy.steps.updatechangelogswithreview_unittests import *
from webkitpy.style.unittests import * # for check-webkit-style
from webkitpy.user_unittest import *
from webkitpy.webkit_logging_unittest import *
from webkitpy.webkitport_unittest import *
import webkitpy.init.versioning as versioning
_log = logging.getLogger("test-webkitpy")
def configure_logging():
"""Configure the root logger to log info messages and above."""
handler = logging.StreamHandler(sys.stderr)
formatter = logging.Formatter("[%(levelname)s] %(name)s: %(message)s")
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(handler)
def init():
"""Execute code prior to importing from webkitpy.unittests."""
configure_logging()
versioning.check_version()
(comparison, current_version, minimum_version) = \
versioning.compare_version()
if comparison > 0:
# Then the current version is later than the minimum version.
message = ("You are testing webkitpy with a Python version (%s) "
"higher than the minimum version (%s) it was meant "
"to support." % (current_version, minimum_version))
_log.warn(message)
if __name__ == "__main__":
# FIXME: This is a hack, but I'm tired of commenting out the test.
# See https://bugs.webkit.org/show_bug.cgi?id=31818
if len(sys.argv) > 1 and sys.argv[1] == "--all":
sys.argv.remove("--all")
from webkitpy.scm_unittest import *
init()
# We import the unit test code after init() to ensure that any
# Python version warnings are displayed in case an error occurs
# while interpreting webkitpy.unittests. This also allows
# logging to be configured prior to importing -- for example to
# enable the display of autoinstall logging.log messages while
# running the unit tests.
from webkitpy.unittests import *
# Runs the unit tests.
unittest.main()
# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Runs init package unit tests."""
# This module is imported by the module that imports all webkitpy unit tests.
from versioning_unittest import *
# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Supports Python version checking."""
import logging
import sys
_log = logging.getLogger("webkitpy.init.versioning")
# The minimum Python version the webkitpy package supports.
_MINIMUM_SUPPORTED_PYTHON_VERSION = "2.5"
def compare_version(sysmodule=None, target_version=None):
"""Compare the current Python version with a target version.
Args:
sysmodule: An object with version and version_info data attributes
used to detect the current Python version. The attributes
should have the same semantics as sys.version and
sys.version_info. This parameter should only be used
for unit testing. Defaults to sys.
target_version: A string representing the Python version to compare
the current version against. The string should have
one of the following three forms: 2, 2.5, or 2.5.3.
Defaults to the minimum version that the webkitpy
package supports.
Returns:
A triple of (comparison, current_version, target_version).
comparison: An integer representing the result of comparing the
current version with the target version. A positive
number means the current version is greater than the
target, 0 means they are the same, and a negative number
means the current version is less than the target.
This method compares version information only up
to the precision of the given target version. For
example, if the target version is 2.6 and the current
version is 2.5.3, this method uses 2.5 for the purposes
of comparing with the target.
current_version: A string representing the current Python version, for
example 2.5.3.
target_version: A string representing the version that the current
version was compared against, for example 2.5.
"""
if sysmodule is None:
sysmodule = sys
if target_version is None:
target_version = _MINIMUM_SUPPORTED_PYTHON_VERSION
# The number of version parts to compare.
precision = len(target_version.split("."))
# We use sys.version_info rather than sys.version since its first
# three elements are guaranteed to be integers.
current_version_info_to_compare = sysmodule.version_info[:precision]
# Convert integers to strings.
current_version_info_to_compare = map(str, current_version_info_to_compare)
current_version_to_compare = ".".join(current_version_info_to_compare)
# Compare version strings lexicographically.
if current_version_to_compare > target_version:
comparison = 1
elif current_version_to_compare == target_version:
comparison = 0
else:
comparison = -1
# The version number portion of the current version string, for
# example "2.6.4".
current_version = sysmodule.version.split()[0]
return (comparison, current_version, target_version)
# FIXME: Add a logging level parameter to allow the version message
# to be logged at levels other than WARNING, for example CRITICAL.
def check_version(sysmodule=None, target_version=None):
"""Check the current Python version against a target version.
Logs a warning message if the current version is less than the
target version.
Args:
sysmodule: See the compare_version() docstring.
target_version: See the compare_version() docstring.
Returns:
A boolean value of whether the current version is greater than
or equal to the target version.
"""
(comparison, current_version, target_version) = \
compare_version(sysmodule, target_version)
if comparison >= 0:
# Then the current version is at least the minimum version.
return True
message = ("WebKit Python scripts do not support your current Python "
"version (%s). The minimum supported version is %s."
% (current_version, target_version))
_log.warn(message)
return False
# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Contains unit tests for versioning.py."""
import logging
import unittest
from logtesting import LogTesting
from versioning import check_version
from versioning import compare_version
class MockSys(object):
"""A mock sys module for passing to version-checking methods."""
def __init__(self, current_version):
"""Create an instance.
current_version: A version string with major, minor, and micro
version parts.
"""
version_info = current_version.split(".")
version_info = map(int, version_info)
self.version = current_version + " Version details."
self.version_info = version_info
class CompareVersionTest(unittest.TestCase):
"""Tests compare_version()."""
def _mock_sys(self, current_version):
return MockSys(current_version)
def test_default_minimum_version(self):
"""Test the configured minimum version that webkitpy supports."""
(comparison, current_version, min_version) = compare_version()
self.assertEquals(min_version, "2.5")
def compare_version(self, target_version, current_version=None):
"""Call compare_version()."""
if current_version is None:
current_version = "2.5.3"
mock_sys = self._mock_sys(current_version)
return compare_version(mock_sys, target_version)
def compare(self, target_version, current_version=None):
"""Call compare_version(), and return the comparison."""
return self.compare_version(target_version, current_version)[0]
def test_returned_current_version(self):
"""Test the current_version return value."""
current_version = self.compare_version("2.5")[1]
self.assertEquals(current_version, "2.5.3")
def test_returned_target_version(self):
"""Test the current_version return value."""
target_version = self.compare_version("2.5")[2]
self.assertEquals(target_version, "2.5")
def test_target_version_major(self):
"""Test major version for target."""
self.assertEquals(-1, self.compare("3"))
self.assertEquals(0, self.compare("2"))
self.assertEquals(1, self.compare("2", "3.0.0"))
def test_target_version_minor(self):
"""Test minor version for target."""
self.assertEquals(-1, self.compare("2.6"))
self.assertEquals(0, self.compare("2.5"))
self.assertEquals(1, self.compare("2.4"))
def test_target_version_micro(self):
"""Test minor version for target."""
self.assertEquals(-1, self.compare("2.5.4"))
self.assertEquals(0, self.compare("2.5.3"))
self.assertEquals(1, self.compare("2.5.2"))
class CheckVersionTest(unittest.TestCase):
"""Tests check_version()."""
def setUp(self):
self._log = LogTesting.setUp(self)
def tearDown(self):
self._log.tearDown()
def _check_version(self, minimum_version):
"""Call check_version()."""
mock_sys = MockSys("2.5.3")
return check_version(mock_sys, minimum_version)
def test_true_return_value(self):
"""Test the configured minimum version that webkitpy supports."""
is_current = self._check_version("2.4")
self.assertEquals(True, is_current)
self._log.assertMessages([]) # No warning was logged.
def test_false_return_value(self):
"""Test the configured minimum version that webkitpy supports."""
is_current = self._check_version("2.6")
self.assertEquals(False, is_current)
expected_message = ("WARNING: WebKit Python scripts do not support "
"your current Python version (2.5.3). "
"The minimum supported version is 2.6.\n")
self._log.assertMessages([expected_message])
......@@ -30,7 +30,7 @@
"""Runs style package unit tests."""
# This module is imported by test-webkitpy.
# This module is imported by the module that imports all webkitpy unit tests.
import sys
import unittest
......
#!/usr/bin/env python
# Copyright (c) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This module is imported by Scripts/test-webkitpy.
import sys
from webkitpy.bugzilla_unittest import *
from webkitpy.buildbot_unittest import *
from webkitpy.changelogs_unittest import *
from webkitpy.commands.download_unittest import *
from webkitpy.commands.early_warning_system_unittest import *
from webkitpy.commands.openbugs_unittest import OpenBugsTest
from webkitpy.commands.upload_unittest import *
from webkitpy.commands.queries_unittest import *
from webkitpy.commands.queues_unittest import *
from webkitpy.committers_unittest import *
from webkitpy.credentials_unittest import *
from webkitpy.diff_parser_unittest import *
from webkitpy.executive_unittest import *
from webkitpy.grammar_unittest import *
from webkitpy.init.unittests import * # for the webkitpy.init package
from webkitpy.layout_tests.port.mac_unittest import *
from webkitpy.multicommandtool_unittest import *
from webkitpy.networktransaction_unittest import *
from webkitpy.patchcollection_unittest import *
from webkitpy.queueengine_unittest import *
from webkitpy.steps.steps_unittest import *
from webkitpy.steps.closebugforlanddiff_unittest import *
from webkitpy.steps.updatechangelogswithreview_unittests import *
from webkitpy.style.unittests import * # for the webkitpy.style package
from webkitpy.user_unittest import *
from webkitpy.webkit_logging_unittest import *
from webkitpy.webkitport_unittest import *
# FIXME: This is a hack, but I'm tired of commenting out the test.
# See https://bugs.webkit.org/show_bug.cgi?id=31818
if len(sys.argv) > 1 and sys.argv[1] == "--all":
sys.argv.remove("--all")
from webkitpy.scm_unittest import *
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment