Commit c4a5618a authored by Dylan Baker's avatar Dylan Baker

python: function with six version 1.5.2

CMake actually marks that we require six 1.4.0, however, I can't find
any packages anywhere for 1.4.0, and the lowest version I've seen
requested is 1.5.2.

This fixes requirements for working with six 1.5.2, and sets tox to use
1.5.2 (and a suitable version of mock). Primarily there are a few things
we're using that are not available: six.moves.getcwd, six.viewvalues,
six.python_2_unicode_compatible.
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
Tested-by: Brian Paul's avatarBrian Paul <brianp@vmware.com>
parent b7a65af7
......@@ -206,7 +206,7 @@ set(Python_ADDITIONAL_VERSIONS
find_package(PythonInterp REQUIRED)
find_package(PythonNumpy 1.6.2 REQUIRED)
find_package(PythonMako 0.8.0 REQUIRED)
find_package(PythonSix 1.4.0 REQUIRED)
find_package(PythonSix 1.5.2 REQUIRED)
# Default to compiling with debug information (`gcc -g`):
if(NOT CMAKE_BUILD_TYPE)
......
......@@ -51,7 +51,7 @@ import contextlib
import six
from six.moves import cStringIO as StringIO
from framework import exceptions
from framework import exceptions, compat
from framework.core import PIGLIT_CONFIG
__all__ = [
......@@ -62,7 +62,7 @@ __all__ = [
]
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class UnsupportedCompressor(exceptions.PiglitInternalError):
def __init__(self, method, *args, **kwargs):
super(UnsupportedCompressor, self).__init__(*args, **kwargs)
......
......@@ -35,7 +35,7 @@ except ImportError:
import six
from framework import status, results, exceptions
from framework import status, results, exceptions, compat
from .abstract import FileBackend, write_compressed
from .register import Registry
from . import compression
......@@ -582,7 +582,7 @@ def _update_seven_to_eight(result):
This value is used for both TestResult.time and TestrunResult.time_elapsed.
"""
for test in six.viewvalues(result.tests):
for test in compat.viewvalues(result.tests):
test.time = results.TimeAttribute(end=test.time)
result.time_elapsed = results.TimeAttribute(end=result.time_elapsed)
......
......@@ -18,7 +18,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""A small library that adds a single compatability decorator for python 2/3.
"""A small library that contains libraries equivalent to six
This function is pending upstreaming in six.
......@@ -30,7 +30,6 @@ from __future__ import (
import six
def python_2_bool_compatible(class_):
"""A decorator to fix __bool__/__nonzero__ name changes."""
if six.PY2:
......@@ -41,3 +40,36 @@ def python_2_bool_compatible(class_):
"@python_2_bool_compatible cannot be applied to {} because "
"it doesn't define __bool__().".format(class_.__name__))
return class_
# Some version of six don't have this function
try:
from six import python_2_unicode_compatible
except ImportError:
def python_2_unicode_compatible(class_):
"""A decorator to fix __str/__bytes__/__unicode__ name changes."""
if six.PY2:
failed = False
try:
class_.__unicode__ = class_.__str__
except AttributeError:
failed = True
try:
class_.__str__ = class_.__bytes__
except AttributeError:
if failed:
raise ValueError(
"@python_2_unicode_compatible cannot be applied to {} "
"because it doesn't define __str__() "
"or __bytes__().".format(class_.__name__))
return class_
try:
from six import viewvalues
except ImportError:
if six.PY2:
viewvalues = lambda d: d.viewvalues()
elif six.PY3:
viewvalues = lambda d: d.values()
......@@ -24,7 +24,7 @@ from __future__ import print_function, absolute_import, division
import sys
import functools
import six
from framework import compat
__all__ = [
'PiglitInternalError',
......@@ -34,6 +34,7 @@ __all__ = [
]
def handler(func):
"""Decorator function for handling errors in an entry point.
......@@ -54,7 +55,7 @@ def handler(func):
return _inner
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class PiglitException(Exception):
"""Class for non-error exceptions.
......@@ -67,7 +68,7 @@ class PiglitException(Exception):
'\n{}'.format(super(PiglitException, self).__str__()))
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class PiglitInternalError(Exception):
"""Class for errors in piglit.
......
......@@ -62,7 +62,7 @@ from __future__ import (
import six
from framework import exceptions
from framework import exceptions, compat
__all__ = ['NOTRUN',
'PASS',
......@@ -97,7 +97,7 @@ def status_lookup(status):
raise StatusException(status)
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class StatusException(exceptions.PiglitInternalError):
""" Raise this exception when a string is passed to status_lookup that
doesn't exists
......@@ -116,7 +116,7 @@ class StatusException(exceptions.PiglitInternalError):
return u'Unknown status "{}"'.format(self.__status)
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class Status(object):
""" A simple class for representing the output values of tests.
......
......@@ -9,11 +9,11 @@ deps =
mako
nose
coverage
six
six==1.5.2
accel: simplejson
accel: lxml
py27-accel,py{33,34,35}: psutil
py27-{accel,noaccel}: mock
py27-{accel,noaccel}: mock==1.0.1
py27-accel: backports.lzma
py27-accel: subprocess32
generator: numpy
......
......@@ -30,7 +30,16 @@ import shutil
import textwrap
import nose.tools as nt
from six.moves import getcwd
import six
try:
from six.moves import getcwd
except ImportError:
# pylint: disable=no-member
if six.PY2:
getcwd = os.getcwdu
elif six.PY3:
getcwd = os.getcwd
# pylint: enable=no-member
from framework import core, exceptions
from . import utils
......
......@@ -28,7 +28,16 @@ from __future__ import (
import os
import nose.tools as nt
from six.moves import getcwd
import six
try:
from six.moves import getcwd
except ImportError:
# pylint: disable=no-member
if six.PY2:
getcwd = os.getcwdu
elif six.PY3:
getcwd = os.getcwd
# pylint: enable=no-member
from framework.summary import html_
from . import utils
......
......@@ -45,9 +45,17 @@ except ImportError:
import json
from nose.plugins.skip import SkipTest
import six
from six.moves import getcwdb
try:
from six.moves import getcwd
except ImportError:
# pylint: disable=no-member
if six.PY2:
getcwd = os.getcwdu
elif six.PY3:
getcwd = os.getcwd
# pylint: enable=no-member
from framework import test, backends, core, results
from framework import test, backends, core, results, compat
__all__ = [
'tempfile',
......@@ -93,7 +101,7 @@ JSON_DATA = {
_SAVED_COMPRESSION = os.environ.get('PIGLIT_COMPRESSION')
@six.python_2_unicode_compatible
@compat.python_2_unicode_compatible
class TestFailure(AssertionError):
"""An exception to be raised when a test fails.
......@@ -349,7 +357,7 @@ def test_in_tempdir(func):
returns to the original directory after the test completes.
"""
original_dir = getcwdb()
original_dir = getcwd()
@functools.wraps(func)
def wrapper(*args, **kwargs):
......
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