Resolves issues discovered using flake8 with Python 3.5

These are issues in Python 2.7 but were not caught by
its version of flake8.

Change-Id: I90349a6b4345b0787671a249a9d3b6a634372fc7
This commit is contained in:
Daryl Walleck 2017-01-26 13:22:11 -06:00
parent 3b454756c7
commit 525e44c925
10 changed files with 23 additions and 20 deletions

View File

@ -16,7 +16,8 @@ def print_configs():
for path, dirs, files in os.walk(config_dir):
for file_ in files:
if file_.endswith(".config"):
print os.path.join(path, file_)[len(config_dir) + len(os.sep):]
print(
os.path.join(path, file_)[len(config_dir) + len(os.sep):])
def print_imports(string):
@ -24,13 +25,13 @@ def print_imports(string):
if len(import_paths) == 1:
for _, module_name, _ in pkgutil.iter_modules():
if module_name.startswith(import_paths[0]):
print module_name
print(module_name)
else:
try:
base = importlib.import_module(import_paths[0])
for _, name, _ in pkgutil.iter_modules(base.__path__):
if name.startswith(import_paths[1]):
print "{0}.{1}".format(import_paths[0], name)
print("{0}.{1}".format(import_paths[0], name))
except:
return
@ -39,7 +40,7 @@ def print_products():
try:
base = importlib.import_module(ENGINE_CONFIG.default_test_repo)
for _, name, _ in pkgutil.iter_modules(base.__path__):
print name
print(name)
except:
return
@ -51,4 +52,5 @@ def print_configs_by_product(product):
for path, dirs, files in os.walk(config_dir):
for file_ in files:
if file_.endswith(".config"):
print os.path.join(path, file_)[len(config_dir) + len(os.sep):]
print(
os.path.join(path, file_)[len(config_dir) + len(os.sep):])

View File

@ -338,7 +338,7 @@ class BrewFile(object):
msg = (
"\nSection '{sec}' in runfile '{filename}' is "
"missing the '{attr}' option".format(
filename=f, sec=s, attr=attr))
filename=f, sec=section, attr=attr))
raise RunFileIncompleteBrewError(msg)
# config files are valid, return aggregate config parser object

View File

@ -49,7 +49,7 @@ class BrewRunner(UnittestRunner):
print("\t\t" + "\n\t\t ".join(brewfile.files))
if self.cl_args.verbose >= 2:
print("BREWS............:")
print "\t" + "\n\t".join(brewfile.brews_to_strings())
print("\t" + "\n\t".join(brewfile.brews_to_strings()))
if repos:
print("BREWING FROM: ....: {0}".format(repos[0]))
for repo in repos[1:]:

View File

@ -246,8 +246,8 @@ def skip_open_issue(type, bug_id):
from cafe.drivers.unittest.issue import skip_open_issue as skip_issue
return skip_issue(type, bug_id)
except ImportError:
print ('* Skip on issue plugin is not installed. Please install '
'the plugin to use this functionality')
print('* Skip on issue plugin is not installed. Please install '
'the plugin to use this functionality')
return lambda obj: obj

View File

@ -658,7 +658,7 @@ class _UnittestRunnerCLI(object):
# wasn't called
if args.product is None or args.config is None:
print(argparser.usage)
print (
print(
"cafe-runner: error: You must supply both a product and a "
"config to run tests")
exit(1)
@ -666,7 +666,7 @@ class _UnittestRunnerCLI(object):
if (args.result or args.result_directory) and (
args.result is None or args.result_directory is None):
print(argparser.usage)
print (
print(
"cafe-runner: error: You must supply both a --result and a "
"--result-directory to print out json or xml formatted "
"results.")

View File

@ -60,7 +60,7 @@ def import_repos(repo_list):
print_exception(
"Runner", "import_repos", repo_name, exception)
if len(repo_list) != len(repos):
exit(get_error(exception))
exit(1)
return repos

View File

@ -96,7 +96,7 @@ class SuiteBuilder(object):
exception)
error = True
if self.exit_on_error and error:
exit(get_error(exception))
exit(1)
return modules

View File

@ -187,8 +187,8 @@ class BaseHTTPClient(BaseClient):
warn('\n')
self._log.critical(warning_string)
self._log.exception(e)
else:
raise e
else:
raise e
def put(self, url, **kwargs):
""" HTTP PUT request """

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from six import StringIO
from six import StringIO, text_type
from socks import socket, create_connection
from uuid import uuid4
import io
@ -137,7 +137,7 @@ class SSHClient(BaseSSHClass):
if connect_kwargs.get("pkey") is not None:
connect_kwargs["pkey"] = RSAKey.from_private_key(
io.StringIO(unicode(connect_kwargs["pkey"])))
io.StringIO(text_type(connect_kwargs["pkey"])))
proxy_type = proxy_type or self.proxy_type
proxy_ip = proxy_ip or self.proxy_ip
@ -207,7 +207,7 @@ class SFTPShell(BaseSSHClass):
try:
self.sftp.stat(path)
ret_val = True
except IOError, e:
except IOError as e:
if e[0] != 2:
raise
ret_val = False

View File

@ -13,6 +13,7 @@
from datetime import datetime
import os
import six
import sys
import uuid
@ -56,13 +57,13 @@ class SubunitReport(BaseReport):
test_result['test_method_name'])
kwargs = {
"timestamp": datetime.now(pytz.UTC),
"test_id": unicode(test_id)}
"test_id": six.text_type(test_id)}
output.status(**kwargs)
kwargs["test_status"] = test_result['result']
kwargs["file_bytes"] = bytes(test_result.get(
'failure_trace') or test_result.get('error_trace') or "0")
kwargs["file_name"] = "stdout"
kwargs["mime_type"] = unicode("text/plain;charset=utf8")
kwargs["mime_type"] = six.text_type("text/plain;charset=utf8")
output.status(**kwargs)
output.stopTestRun()