16
16
import re
17
17
18
18
from hacking import core
19
- import pycodestyle
20
19
21
20
22
21
PYTHON_CLIENTS = ['cinder' , 'glance' , 'keystone' , 'nova' , 'swift' , 'neutron' ,
40
39
41
40
42
41
@core .flake8ext
43
- def import_no_clients_in_api_and_scenario_tests (physical_line , filename ):
42
+ def import_no_clients_in_api_and_scenario_tests (logical_line , filename ):
44
43
"""Check for client imports from tempest/api & tempest/scenario tests
45
44
46
45
T102: Cannot import OpenStack python clients
47
46
"""
48
47
49
48
if "tempest/api" in filename or "tempest/scenario" in filename :
50
- res = PYTHON_CLIENT_RE .match (physical_line )
49
+ res = PYTHON_CLIENT_RE .match (logical_line )
51
50
if res :
52
- return (physical_line .find (res .group (1 )),
51
+ return (logical_line .find (res .group (1 )),
53
52
("T102: python clients import not allowed"
54
53
" in tempest/api/* or tempest/scenario/* tests" ))
55
54
56
55
57
56
@core .flake8ext
58
- def scenario_tests_need_service_tags (physical_line , filename ,
57
+ def scenario_tests_need_service_tags (logical_line , filename ,
59
58
previous_logical ):
60
59
"""Check that scenario tests have service tags
61
60
62
61
T104: Scenario tests require a services decorator
63
62
"""
64
63
65
64
if 'tempest/scenario/' in filename and '/test_' in filename :
66
- if TEST_DEFINITION .match (physical_line ):
65
+ if TEST_DEFINITION .match (logical_line ):
67
66
if not SCENARIO_DECORATOR .match (previous_logical ):
68
- return (physical_line .find ('def' ),
67
+ return (logical_line .find ('def' ),
69
68
"T104: Scenario tests require a service decorator" )
70
69
71
70
72
71
@core .flake8ext
73
- def no_setup_teardown_class_for_tests (physical_line , filename ):
72
+ def no_setup_teardown_class_for_tests (logical_line , filename , noqa ):
74
73
75
- if pycodestyle . noqa ( physical_line ) :
74
+ if noqa :
76
75
return
77
76
78
77
if 'tempest/test.py' in filename or 'tempest/lib/' in filename :
79
78
return
80
79
81
- if SETUP_TEARDOWN_CLASS_DEFINITION .match (physical_line ):
82
- return (physical_line .find ('def' ),
80
+ if SETUP_TEARDOWN_CLASS_DEFINITION .match (logical_line ):
81
+ return (logical_line .find ('def' ),
83
82
"T105: (setUp|tearDown)Class can not be used in tests" )
84
83
85
84
86
85
@core .flake8ext
87
- def service_tags_not_in_module_path (physical_line , filename ):
86
+ def service_tags_not_in_module_path (logical_line , filename ):
88
87
"""Check that a service tag isn't in the module path
89
88
90
89
A service tag should only be added if the service name isn't already in
@@ -96,14 +95,14 @@ def service_tags_not_in_module_path(physical_line, filename):
96
95
# created for services like heat which would cause false negatives for
97
96
# those tests, so just exclude the scenario tests.
98
97
if 'tempest/scenario' not in filename :
99
- matches = SCENARIO_DECORATOR .match (physical_line )
98
+ matches = SCENARIO_DECORATOR .match (logical_line )
100
99
if matches :
101
100
services = matches .group (1 ).split (',' )
102
101
for service in services :
103
102
service_name = service .strip ().strip ("'" )
104
103
modulepath = os .path .split (filename )[0 ]
105
104
if service_name in modulepath :
106
- return (physical_line .find (service_name ),
105
+ return (logical_line .find (service_name ),
107
106
"T107: service tag should not be in path" )
108
107
109
108
@@ -140,28 +139,27 @@ def no_testtools_skip_decorator(logical_line):
140
139
"decorators.skip_because from tempest.lib" )
141
140
142
141
143
- def _common_service_clients_check (logical_line , physical_line , filename ):
144
- if not re . match ( 'tempest/(lib/)?services/.*' , filename ) :
142
+ def _common_service_clients_check (logical_line , filename , noqa ):
143
+ if noqa :
145
144
return False
146
145
147
- if not METHOD .match (physical_line ):
146
+ if not re .match ('tempest/(lib/)?services/.*' , filename ):
148
147
return False
149
148
150
- if pycodestyle . noqa ( physical_line ):
149
+ if not METHOD . match ( logical_line ):
151
150
return False
152
151
153
152
return True
154
153
155
154
156
155
@core .flake8ext
157
- def get_resources_on_service_clients (physical_line , logical_line , filename ,
158
- line_number , lines ):
156
+ def get_resources_on_service_clients (logical_line , filename ,
157
+ line_number , lines , noqa ):
159
158
"""Check that service client names of GET should be consistent
160
159
161
160
T110
162
161
"""
163
- if not _common_service_clients_check (logical_line , physical_line ,
164
- filename ):
162
+ if not _common_service_clients_check (logical_line , filename , noqa ):
165
163
return
166
164
167
165
for line in lines [line_number :]:
@@ -182,14 +180,13 @@ def get_resources_on_service_clients(physical_line, logical_line, filename,
182
180
183
181
184
182
@core .flake8ext
185
- def delete_resources_on_service_clients (physical_line , logical_line , filename ,
186
- line_number , lines ):
183
+ def delete_resources_on_service_clients (logical_line , filename ,
184
+ line_number , lines , noqa ):
187
185
"""Check that service client names of DELETE should be consistent
188
186
189
187
T111
190
188
"""
191
- if not _common_service_clients_check (logical_line , physical_line ,
192
- filename ):
189
+ if not _common_service_clients_check (logical_line , filename , noqa ):
193
190
return
194
191
195
192
for line in lines [line_number :]:
@@ -262,7 +259,7 @@ def dont_use_config_in_tempest_lib(logical_line, filename):
262
259
'oslo_config' in logical_line ):
263
260
msg = ('T114: tempest.lib can not have any dependency on tempest '
264
261
'config.' )
265
- yield (0 , msg )
262
+ yield (0 , msg )
266
263
267
264
268
265
@core .flake8ext
@@ -281,7 +278,7 @@ def dont_put_admin_tests_on_nonadmin_path(logical_line,
281
278
282
279
if not re .match (r'.\/tempest\/api\/.*\/admin\/.*' , filename ):
283
280
msg = 'T115: All admin tests should exist under admin path.'
284
- yield (0 , msg )
281
+ yield (0 , msg )
285
282
286
283
287
284
@core .flake8ext
@@ -293,11 +290,11 @@ def unsupported_exception_attribute_PY3(logical_line):
293
290
result = EX_ATTRIBUTE .search (logical_line )
294
291
msg = ("[T116] Unsupported 'message' Exception attribute in PY3" )
295
292
if result :
296
- yield (0 , msg )
293
+ yield (0 , msg )
297
294
298
295
299
296
@core .flake8ext
300
- def negative_test_attribute_always_applied_to_negative_tests (physical_line ,
297
+ def negative_test_attribute_always_applied_to_negative_tests (logical_line ,
301
298
filename ):
302
299
"""Check ``@decorators.attr(type=['negative'])`` applied to negative tests.
303
300
@@ -307,13 +304,13 @@ def negative_test_attribute_always_applied_to_negative_tests(physical_line,
307
304
308
305
if re .match (r'.\/tempest\/api\/.*_negative.*' , filename ):
309
306
310
- if NEGATIVE_TEST_DECORATOR .match (physical_line ):
307
+ if NEGATIVE_TEST_DECORATOR .match (logical_line ):
311
308
_HAVE_NEGATIVE_DECORATOR = True
312
309
return
313
310
314
- if TEST_DEFINITION .match (physical_line ):
311
+ if TEST_DEFINITION .match (logical_line ):
315
312
if not _HAVE_NEGATIVE_DECORATOR :
316
- return (
313
+ yield (
317
314
0 , "T117: Must apply `@decorators.attr(type=['negative'])`"
318
315
" to all negative API tests"
319
316
)
0 commit comments