-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathskip.py
145 lines (101 loc) · 4.22 KB
/
skip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import functools
import pkg_resources
import re
import sys
def skip_or_run_test_tarantool(func, REQUIRED_TNT_VERSION, msg):
"""Decorator to skip or run tests depending on the tarantool
version.
Also, it can be used with the 'setUp' method for skipping
the whole test suite.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if func.__name__ == 'setUp':
func(self, *args, **kwargs)
if not hasattr(self, 'tnt_version'):
srv = None
if hasattr(self, 'servers'):
srv = self.servers[0]
if hasattr(self, 'srv'):
srv = self.srv
assert srv is not None
self.__class__.tnt_version = re.match(
r'[\d.]+', srv.admin('box.info.version')[0]
).group()
tnt_version = pkg_resources.parse_version(self.tnt_version)
support_version = pkg_resources.parse_version(REQUIRED_TNT_VERSION)
if tnt_version < support_version:
self.skipTest('Tarantool %s %s' % (self.tnt_version, msg))
if func.__name__ != 'setUp':
func(self, *args, **kwargs)
return wrapper
def skip_or_run_test_pcall_require(func, REQUIRED_TNT_MODULE, msg):
"""Decorator to skip or run tests depending on tarantool
module requre success or fail.
Also, it can be used with the 'setUp' method for skipping
the whole test suite.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if func.__name__ == 'setUp':
func(self, *args, **kwargs)
srv = None
if hasattr(self, 'servers'):
srv = self.servers[0]
if hasattr(self, 'srv'):
srv = self.srv
assert srv is not None
resp = srv.admin("pcall(require, '%s')" % REQUIRED_TNT_MODULE)
if not resp[0]:
self.skipTest('Tarantool %s' % (msg, ))
if func.__name__ != 'setUp':
func(self, *args, **kwargs)
return wrapper
def skip_or_run_test_python(func, REQUIRED_PYTHON_VERSION, msg):
"""Decorator to skip or run tests depending on the Python version.
Also, it can be used with the 'setUp' method for skipping
the whole test suite.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if func.__name__ == 'setUp':
func(self, *args, **kwargs)
ver = sys.version_info
python_version_str = '%d.%d' % (ver.major, ver.minor)
python_version = pkg_resources.parse_version(python_version_str)
support_version = pkg_resources.parse_version(REQUIRED_PYTHON_VERSION)
if python_version < support_version:
self.skipTest('Python %s connector %s' % (python_version, msg))
if func.__name__ != 'setUp':
func(self, *args, **kwargs)
return wrapper
def skip_or_run_sql_test(func):
"""Decorator to skip or run SQL-related tests depending on the
tarantool version.
Tarantool supports SQL-related stuff only since 2.0.0 version.
So this decorator should wrap every SQL-related test to skip it if
the tarantool version < 2.0.0 is used for testing.
"""
return skip_or_run_test_tarantool(func, '2.0.0', 'does not support SQL')
def skip_or_run_varbinary_test(func):
"""Decorator to skip or run VARBINARY-related tests depending on
the tarantool version.
Tarantool supports VARBINARY type only since 2.2.1 version.
See https://github.com/tarantool/tarantool/issues/4201
"""
return skip_or_run_test_tarantool(func, '2.2.1',
'does not support VARBINARY type')
def skip_or_run_conn_pool_test(func):
"""Decorator to skip or run ConnectionPool tests depending on
the Python version.
"""
return skip_or_run_test_python(func, '3.7',
'does not support ConnectionPool')
def skip_or_run_decimal_test(func):
"""Decorator to skip or run decimal-related tests depending on
the tarantool version.
Tarantool supports decimal type only since 2.2.1 version.
See https://github.com/tarantool/tarantool/issues/692
"""
return skip_or_run_test_pcall_require(func, 'decimal',
'does not support decimal type')