add new indexing test with dynamic indexing of integer vector
[piglit.git] / framework / compat.py
blob114ca364203951c0a0925ec6ec65410fcef27b55
1 # Copyright (c) 2016 Intel Corporation
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
21 """A small library that contains libraries equivalent to six
23 This function is pending upstreaming in six.
25 """
27 from __future__ import (
28 absolute_import, division, print_function, unicode_literals
31 import six
33 def python_2_bool_compatible(class_):
34 """A decorator to fix __bool__/__nonzero__ name changes."""
35 if six.PY2:
36 try:
37 class_.__nonzero__ = class_.__bool__
38 except AttributeError:
39 raise ValueError(
40 "@python_2_bool_compatible cannot be applied to {} because "
41 "it doesn't define __bool__().".format(class_.__name__))
42 return class_
45 # Some version of six don't have this function
46 try:
47 from six import python_2_unicode_compatible
48 except ImportError:
49 def python_2_unicode_compatible(class_):
50 """A decorator to fix __str/__bytes__/__unicode__ name changes."""
51 if six.PY2:
52 failed = False
53 try:
54 class_.__unicode__ = class_.__str__
55 except AttributeError:
56 failed = True
58 try:
59 class_.__str__ = class_.__bytes__
60 except AttributeError:
61 if failed:
62 raise ValueError(
63 "@python_2_unicode_compatible cannot be applied to {} "
64 "because it doesn't define __str__() "
65 "or __bytes__().".format(class_.__name__))
66 return class_
69 try:
70 from six import viewvalues
71 except ImportError:
72 if six.PY2:
73 viewvalues = lambda d: d.viewvalues()
74 elif six.PY3:
75 viewvalues = lambda d: d.values()