Fix pep8, flake8 and unit test failures

The patch edits the code so that it complies with W605 rule
wherever it makes sense. W504 rule is added to a ignore list.
High version cap of pyflakes and flake8 packages is increased
as well.

Change-Id: I51558ee9c808e03b4164d0832fc525c5556dddd1
This commit is contained in:
Martin Kopec 2020-11-18 14:13:26 +00:00
parent a2b4ce30b8
commit f069afca67
6 changed files with 14 additions and 13 deletions

View File

@ -85,10 +85,10 @@ class TestListParser(object):
for testcase in test_list:
if testcase.startswith("tempest"):
# Search for any strings like '[smoke, gate]' in the test ID.
match = re.search('(\[.*\])', testcase)
match = re.search(r'(\[.*\])', testcase)
if match:
testcase = re.sub('\[.*\]', '', testcase)
testcase = re.sub(r'\[.*\]', '', testcase)
test_mappings[testcase] = match.group(1)
else:
test_mappings[testcase] = ""
@ -195,16 +195,16 @@ class TestListParser(object):
"""This takes in a test list file, get normalized, and get whitelist
regexes using full qualified test names (one per line).
Ex:
'tempest.test1[id-2,gate]' -> tempest.test1\[
'tempest.test2[id-3,smoke](scenario)' -> tempest.test2\[
'tempest.test3[compute,id-4]' -> tempest.test3\[
'tempest.test1[id-2,gate]' -> tempest.test1\[ # noqa: W605
'tempest.test2[id-3,smoke](scenario)' -> tempest.test2\[ # noqa: W605
'tempest.test3[compute,id-4]' -> tempest.test3\[ # noqa: W605
:param list_location: file path or URL location of list file
"""
normalized_list = open(self.get_normalized_test_list(list_location),
'r').read()
# Keep the names
tests_list = [re.sub("\[", "\[", test)
for test in re.findall(".*\[", normalized_list)]
tests_list = [re.sub(r"\[", r"\[", test)
for test in re.findall(r".*\[", normalized_list)]
return self._write_normalized_test_list(tests_list)

View File

@ -330,7 +330,7 @@ class RefstackClient:
raise requests.exceptions.HTTPError(message)
# If a Key or Index Error was raised, one of the expected keys or
# indices for retrieving the identity service ID was not found.
except (KeyError, IndexError) as e:
except (KeyError, IndexError):
self.logger.warning('Unable to retrieve CPID from Keystone %s '
'catalog. The catalog or the identity '
'service endpoint was not '

View File

@ -50,7 +50,7 @@ class TempestSubunitTestResultPassOnly(testtools.TestResult):
# Remove any [] from the test ID before appending it.
# Will leave in any () for now as they are the only thing discerning
# certain test cases.
test_result = {'name': str(re.sub('\[.*\]', '', testcase.id()))}
test_result = {'name': str(re.sub(r'\[.*\]', '', testcase.id()))}
uuid = self.get_test_uuid(str(testcase.id()))
if uuid:
test_result['uuid'] = uuid

View File

@ -181,7 +181,7 @@ class TestTestListParser(unittest.TestCase):
expected_list = "tempest.test.one\[\n"\
"tempest.test.two\[\n"\
"tempest.test.three\[\n"
"tempest.test.three\[\n" # noqa W605
tmpfile = tempfile.mktemp()
with open(tmpfile, 'w') as f:

View File

@ -1,6 +1,6 @@
pep8==1.4.5
pyflakes>=0.7.2,<0.8.1
flake8<3.6.0
pyflakes>=0.7.2,<2.2.0
flake8<3.8.0
docutils>=0.11 # OSI-Approved Open Source, Public Domain
stestr>=1.1.0 # Apache-2.0
testtools>=0.9.34

View File

@ -46,7 +46,8 @@ commands = sphinx-build -b html doc/source doc/build/html
[flake8]
# E125 continuation line does not distinguish itself from next logical line
# H404 multi line docstring should start with a summary
ignore = E125,H404
# W504 skipped because it is overeager and unnecessary
ignore = E125,H404,W504
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,.tempest