Fix H404/405 violations for tools

There is a lot of H404/405 violations in Tempest now, and that leads
difficult to migrate the code to tempest-lib or the other projects'
repos. This patch fixes these violations for tools for enabling
H404/405 rules on Tempest.

Change-Id: I4e1d78532d8f96edd5fd28a7bd2d62181fe9144b
This commit is contained in:
Ken'ichi Ohmichi 2015-11-17 13:12:55 +00:00 committed by Ken'ichi Ohmichi
parent b279084f73
commit 7616d19360
3 changed files with 20 additions and 27 deletions

View File

@ -114,10 +114,8 @@ class TestChecker(object):
@staticmethod @staticmethod
def _get_idempotent_id(test_node): def _get_idempotent_id(test_node):
""" # Return key-value dict with all metadata from @test.idempotent_id
Return key-value dict with all metadata from @test.idempotent_id # decorators for test method
decorators for test method
"""
idempotent_id = None idempotent_id = None
for decorator in test_node.decorator_list: for decorator in test_node.decorator_list:
if (hasattr(decorator, 'func') and if (hasattr(decorator, 'func') and
@ -264,8 +262,9 @@ class TestChecker(object):
return self._filter_tests(check_uuid_in_meta, tests) return self._filter_tests(check_uuid_in_meta, tests)
def report_collisions(self, tests): def report_collisions(self, tests):
"""Reports collisions if there are any. Returns true if """Reports collisions if there are any.
collisions exist.
Returns true if collisions exist.
""" """
uuids = {} uuids = {}
@ -298,8 +297,9 @@ class TestChecker(object):
return bool(self._filter_tests(report, tests)) return bool(self._filter_tests(report, tests))
def report_untagged(self, tests): def report_untagged(self, tests):
"""Reports untagged tests if there are any. Returns true if """Reports untagged tests if there are any.
untagged tests exist.
Returns true if untagged tests exist.
""" """
def report(module_name, test_name, tests): def report(module_name, test_name, tests):
error_str = "%s:%s\nmissing @test.idempotent_id('...')\n%s\n" % ( error_str = "%s:%s\nmissing @test.idempotent_id('...')\n%s\n" % (
@ -312,9 +312,7 @@ class TestChecker(object):
return bool(self._filter_tests(report, tests)) return bool(self._filter_tests(report, tests))
def fix_tests(self, tests): def fix_tests(self, tests):
"""Add uuids to all tests specified in tests and """Add uuids to all tests specified in tests and fix it"""
fix it in source files
"""
patcher = SourcePatcher() patcher = SourcePatcher()
for module_name in tests: for module_name in tests:
add_import_once = True add_import_once = True

View File

@ -50,9 +50,9 @@ import testtools
class _AnsiColorizer(object): class _AnsiColorizer(object):
""" """A colorizer is an object that loosely wraps around a stream
A colorizer is an object that loosely wraps around a stream, allowing
callers to write text to the stream in a particular color. allowing callers to write text to the stream in a particular color.
Colorizer classes must implement C{supported()} and C{write(text, color)}. Colorizer classes must implement C{supported()} and C{write(text, color)}.
""" """
@ -63,7 +63,8 @@ class _AnsiColorizer(object):
self.stream = stream self.stream = stream
def supported(cls, stream=sys.stdout): def supported(cls, stream=sys.stdout):
""" """Check the current platform supports coloring terminal output
A class method that returns True if the current platform supports A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise. coloring terminal output using this method. Returns False otherwise.
""" """
@ -86,8 +87,7 @@ class _AnsiColorizer(object):
supported = classmethod(supported) supported = classmethod(supported)
def write(self, text, color): def write(self, text, color):
""" """Write the given text to the stream in the given color.
Write the given text to the stream in the given color.
@param text: Text to be written to the stream. @param text: Text to be written to the stream.
@ -98,9 +98,7 @@ class _AnsiColorizer(object):
class _Win32Colorizer(object): class _Win32Colorizer(object):
""" """See _AnsiColorizer docstring."""
See _AnsiColorizer docstring.
"""
def __init__(self, stream): def __init__(self, stream):
import win32console import win32console
red, green, blue, bold = (win32console.FOREGROUND_RED, red, green, blue, bold = (win32console.FOREGROUND_RED,
@ -146,9 +144,7 @@ class _Win32Colorizer(object):
class _NullColorizer(object): class _NullColorizer(object):
""" """See _AnsiColorizer docstring."""
See _AnsiColorizer docstring.
"""
def __init__(self, stream): def __init__(self, stream):
self.stream = stream self.stream = stream

View File

@ -40,7 +40,8 @@ def debug(msg, *args, **kwargs):
def find_skips(start=TESTDIR): def find_skips(start=TESTDIR):
""" """Find skipped tests
Returns a list of tuples (method, bug) that represent Returns a list of tuples (method, bug) that represent
test methods that have been decorated to skip because of test methods that have been decorated to skip because of
a particular bug. a particular bug.
@ -67,9 +68,7 @@ def find_skips(start=TESTDIR):
def find_skips_in_file(path): def find_skips_in_file(path):
""" """Return the skip tuples in a test file"""
Return the skip tuples in a test file
"""
BUG_RE = re.compile(r'\s*@.*skip_because\(bug=[\'"](\d+)[\'"]') BUG_RE = re.compile(r'\s*@.*skip_because\(bug=[\'"](\d+)[\'"]')
DEF_RE = re.compile(r'\s*def (\w+)\(') DEF_RE = re.compile(r'\s*def (\w+)\(')
bug_found = False bug_found = False