chore: switch to py3 print function

Also fix other problems due to flake8 upgrades.

Change-Id: I5cb6194e48c66e40ec7aa9739eb37550d6bf3e2a
This commit is contained in:
Zhihao Yuan 2013-07-19 10:30:43 -04:00
parent 0b94bdcff2
commit dddea2747d
9 changed files with 65 additions and 58 deletions

View File

@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import atexit import atexit
import functools import functools
import sys import sys
@ -33,7 +34,7 @@ def _fail(returncode, ex):
:param ex: the error that occurred :param ex: the error that occurred
""" """
print >> sys.stderr, ex print(ex, file=sys.stderr)
LOG.exception(ex) LOG.exception(ex)
sys.exit(returncode) sys.exit(returncode)

View File

@ -29,7 +29,7 @@ def lazy_property(write=False, delete=True):
setattr(self, attr_name, fn(self)) setattr(self, attr_name, fn(self))
return getattr(self, attr_name) return getattr(self, attr_name)
def setter(self, value): def setter(self, value):
setattr(self, attr_name, value) setattr(self, attr_name, value)
def deleter(self): def deleter(self):

View File

@ -185,7 +185,7 @@ class MongodbMessageTests(base.MessageControllerTest):
self.assertEqual(marker1, marker2) self.assertEqual(marker1, marker2)
self.assertEqual(marker2, marker3) self.assertEqual(marker2, marker3)
self.assertEqual(marker1, i+2) self.assertEqual(marker1, i + 2)
def test_remove_expired(self): def test_remove_expired(self):
num_projects = 10 num_projects = 10

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import json import json
from marconi.tests.system.common import functionlib from marconi.tests.system.common import functionlib
@ -37,7 +38,7 @@ def verify_claim_msg(count, *claim_response):
if test_result_flag: if test_result_flag:
test_result_flag = query_claim(headers, body) test_result_flag = query_claim(headers, body)
else: else:
print 'More msgs returned than specified in limit' print('More msgs returned than specified in limit')
return test_result_flag return test_result_flag
@ -77,17 +78,17 @@ def query_claim(headers, *body):
test_result_flag = verify_query_msgs(query_msgs, msg_list) test_result_flag = verify_query_msgs(query_msgs, msg_list)
if not test_result_flag: if not test_result_flag:
print 'URL' print('URL')
print url print(url)
print 'HEADER' print('HEADER')
print header print(header)
print 'Messages returned by Query Claim' print('Messages returned by Query Claim')
print query_msgs print(query_msgs)
print '# of Messages returned by Query Claim', len(query_msgs) print('# of Messages returned by Query Claim', len(query_msgs))
print 'Messages returned by Claim Messages' print('Messages returned by Claim Messages')
print msg_list print(msg_list)
print '# of Messages returned by Claim messages', len(msg_list) print('# of Messages returned by Claim messages', len(msg_list))
print 'Query Claim Failed' print('Query Claim Failed')
return test_result_flag return test_result_flag
@ -128,9 +129,9 @@ def verify_patch_claim(url, header, ttl_extended):
ttl = response_body['ttl'] ttl = response_body['ttl']
if ttl < ttl_extended: if ttl < ttl_extended:
print get_claim.status_code print(get_claim.status_code)
print get_claim.headers print(get_claim.headers)
print get_claim.text print(get_claim.text)
test_result_flag = False test_result_flag = False
return test_result_flag return test_result_flag
@ -163,11 +164,11 @@ def delete_claimed_msgs(*claim_response):
if delete_response.status_code == 204: if delete_response.status_code == 204:
test_result_flag = functionlib.verify_delete(url, header) test_result_flag = functionlib.verify_delete(url, header)
else: else:
print 'DELETE message with claim ID: {}'.format(url) print('DELETE message with claim ID: {}'.format(url))
print delete_response.status_code print(delete_response.status_code)
print delete_response.headers print(delete_response.headers)
print delete_response.text print(delete_response.text)
print 'Delete Claimed Message Failed' print('Delete Claimed Message Failed')
return test_result_flag return test_result_flag
@ -185,9 +186,9 @@ def get_claimed_msgs(*claim_response):
for url in urllist: for url in urllist:
get_response = http.get(url, header) get_response = http.get(url, header)
if get_response.status_code != 200: if get_response.status_code != 200:
print url print(url)
print header print(header)
print 'Get Response Code: {}'.format(get_response.status_code) print('Get Response Code: {}'.format(get_response.status_code))
test_result_flag = False test_result_flag = False
if not test_result_flag: if not test_result_flag:
@ -212,9 +213,10 @@ def release_claim(*claim_response):
if release_response.status_code == 204: if release_response.status_code == 204:
test_result_flag = functionlib.verify_delete(url, header) test_result_flag = functionlib.verify_delete(url, header)
else: else:
print 'Release Claim HTTP code:{}'.format(release_response.status_code) print('Release Claim HTTP code:{}'.format(
print release_response.headers release_response.status_code))
print release_response.text print(release_response.headers)
print(release_response.text)
assert test_result_flag, 'Release Claim Failed' assert test_result_flag, 'Release Claim Failed'
if not test_result_flag: if not test_result_flag:

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import binascii import binascii
import json import json
import os import os
@ -177,11 +178,11 @@ def verify_delete(url, header):
else: else:
print('GET after DELETE failed') print('GET after DELETE failed')
print('URL') print('URL')
print url print(url)
print('headers') print('headers')
print header print(header)
print('Response Body') print('Response Body')
print getmsg.text print(getmsg.text)
print 'GET Code {}'.format(getmsg.status_code) print('GET Code {}'.format(getmsg.status_code))
return test_result_flag return test_result_flag

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import with_statement from __future__ import print_function
import json import json
import random import random
@ -129,11 +129,11 @@ def verify_post_msg(msg_headers, posted_body):
else: else:
print('Failed to GET {}'.format(url)) print('Failed to GET {}'.format(url))
print('Request Header') print('Request Header')
print header print(header)
print('Response Headers') print('Response Headers')
print getmsg.headers print(getmsg.headers)
print('Response Body') print('Response Body')
print getmsg.text print(getmsg.text)
return test_result_flag return test_result_flag
@ -196,11 +196,11 @@ def delete_msg(*postresponse):
else: else:
print('DELETE message failed') print('DELETE message failed')
print('URL') print('URL')
print url print(url)
print('headers') print('headers')
print header print(header)
print('Response Body') print('Response Body')
print deletemsg.text print(deletemsg.text)
print 'DELETE Code {}'.format(deletemsg.status_code) print('DELETE Code {}'.format(deletemsg.status_code))
return test_result_flag return test_result_flag

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import binascii import binascii
import json import json
import os import os
@ -56,8 +57,8 @@ def verify_queue_stats(*get_response):
if test_result_flag: if test_result_flag:
return test_result_flag return test_result_flag
else: else:
print headers print(headers)
print body print(body)
assert test_result_flag, 'Get Request stats failed' assert test_result_flag, 'Get Request stats failed'
@ -89,7 +90,7 @@ def verify_list_queues(*list_queue_response):
if False in test_result_flags: if False in test_result_flags:
test_result_flag = False test_result_flag = False
print 'List Queue API response: {}'.format(response_body) print('List Queue API response: {}'.format(response_body))
return test_result_flag return test_result_flag
if links[0]['rel'] == 'next': if links[0]['rel'] == 'next':
@ -117,8 +118,8 @@ def verify_listed(queue, detail_enabled):
if keys == expected_keys: if keys == expected_keys:
return test_result_flag return test_result_flag
else: else:
print 'list_queue response does not match expected response' print('list_queue response does not match expected response')
print queue print(queue)
test_result_flag = False test_result_flag = False
return test_result_flag return test_result_flag

View File

@ -19,6 +19,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import print_function
import os import os
import sys import sys
@ -44,7 +45,7 @@ def print_help(venv, root):
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print help % (venv, root) print(help % (venv, root))
def main(argv): def main(argv):

View File

@ -21,6 +21,7 @@ virtual environments.
Synced in from openstack-common Synced in from openstack-common
""" """
from __future__ import print_function
import argparse import argparse
import os import os
import subprocess import subprocess
@ -39,7 +40,7 @@ class InstallVenv(object):
self.project = project self.project = project
def die(self, message, *args): def die(self, message, *args):
print >> sys.stderr, message % args print(message % args, file=sys.stderr)
sys.exit(1) sys.exit(1)
def check_python_version(self): def check_python_version(self):
@ -86,20 +87,20 @@ class InstallVenv(object):
virtual environment. virtual environment.
""" """
if not os.path.isdir(self.venv): if not os.path.isdir(self.venv):
print 'Creating venv...', print('Creating venv...', end=' ')
if no_site_packages: if no_site_packages:
self.run_command(['virtualenv', '-q', '--no-site-packages', self.run_command(['virtualenv', '-q', '--no-site-packages',
self.venv]) self.venv])
else: else:
self.run_command(['virtualenv', '-q', self.venv]) self.run_command(['virtualenv', '-q', self.venv])
print 'done.' print('done.')
print 'Installing pip in venv...', print('Installing pip in venv...', end=' ')
if not self.run_command(['tools/with_venv.sh', 'easy_install', if not self.run_command(['tools/with_venv.sh', 'easy_install',
'pip>1.0']).strip(): 'pip>1.0']).strip():
self.die("Failed to install pip.") self.die("Failed to install pip.")
print 'done.' print('done.')
else: else:
print "venv already exists..." print("venv already exists...")
pass pass
def pip_install(self, *args): def pip_install(self, *args):
@ -108,7 +109,7 @@ class InstallVenv(object):
redirect_output=False) redirect_output=False)
def install_dependencies(self): def install_dependencies(self):
print 'Installing dependencies with pip (this can take a while)...' print('Installing dependencies with pip (this can take a while)...')
# First things first, make sure our venv has the latest pip and # First things first, make sure our venv has the latest pip and
# distribute. # distribute.
@ -150,12 +151,12 @@ class Distro(InstallVenv):
return return
if self.check_cmd('easy_install'): if self.check_cmd('easy_install'):
print 'Installing virtualenv via easy_install...', print('Installing virtualenv via easy_install...', end=' ')
if self.run_command(['easy_install', 'virtualenv']): if self.run_command(['easy_install', 'virtualenv']):
print 'Succeeded' print('Succeeded')
return return
else: else:
print 'Failed' print('Failed')
self.die('ERROR: virtualenv not found.\n\n%s development' self.die('ERROR: virtualenv not found.\n\n%s development'
' requires virtualenv, please install it using your' ' requires virtualenv, please install it using your'
@ -181,7 +182,7 @@ class Fedora(Distro):
check_exit_code=False)[1] == 0 check_exit_code=False)[1] == 0
def yum_install(self, pkg, **kwargs): def yum_install(self, pkg, **kwargs):
print "Attempting to install '%s' via yum" % pkg print("Attempting to install '%s' via yum" % pkg)
self.run_command(['sudo', 'yum', 'install', '-y', pkg], **kwargs) self.run_command(['sudo', 'yum', 'install', '-y', pkg], **kwargs)
def apply_patch(self, originalfile, patchfile): def apply_patch(self, originalfile, patchfile):