From 923238aa1ba0963c414ba5321cd3910b2910f4ed Mon Sep 17 00:00:00 2001 From: janonymous Date: Tue, 28 Jul 2015 20:35:25 +0530 Subject: [PATCH] test/(functional/probe):Replace python print operator with print function (pep H233, py33) 'print' function is compatible with 2.x and 3.x python versions Link : https://www.python.org/dev/peps/pep-3105/ Python 2.6 has a __future__ import that removes print as language syntax, letting you use the functional form instead Change-Id: I416c6ac21ccbfb91ec328ffb1ed21e492ef52d58 --- test/__init__.py | 17 +++++++---------- test/functional/__init__.py | 33 +++++++++++++++++---------------- test/probe/brain.py | 6 +++--- test/probe/common.py | 18 +++++++++--------- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index 3bd25b1407..b3ebefe70c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -15,7 +15,7 @@ # See http://code.google.com/p/python-nose/issues/detail?id=373 # The code below enables nosetests to work with i18n _() blocks - +from __future__ import print_function import sys import os try: @@ -63,15 +63,12 @@ def get_config(section_name=None, defaults=None): config = readconf(config_file, section_name) except SystemExit: if not os.path.exists(config_file): - print >>sys.stderr, \ - 'Unable to read test config %s - file not found' \ - % config_file + print('Unable to read test config %s - file not found' + % config_file, file=sys.stderr) elif not os.access(config_file, os.R_OK): - print >>sys.stderr, \ - 'Unable to read test config %s - permission denied' \ - % config_file + print('Unable to read test config %s - permission denied' + % config_file, file=sys.stderr) else: - print >>sys.stderr, \ - 'Unable to read test config %s - section %s not found' \ - % (config_file, section_name) + print('Unable to read test config %s - section %s not found' + % (config_file, section_name), file=sys.stderr) return config diff --git a/test/functional/__init__.py b/test/functional/__init__.py index 8f16f5ac23..f07d162691 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import mock import os import sys @@ -128,7 +129,7 @@ class InProcessException(BaseException): def _info(msg): - print >> sys.stderr, msg + print(msg, file=sys.stderr) def _debug(msg): @@ -501,7 +502,7 @@ def get_cluster_info(): # Most likely the swift cluster has "expose_info = false" set # in its proxy-server.conf file, so we'll just do the best we # can. - print >>sys.stderr, "** Swift Cluster not exposing /info **" + print("** Swift Cluster not exposing /info **", file=sys.stderr) # Finally, we'll allow any constraint present in the swift-constraints # section of test.conf to override everything. Note that only those @@ -513,8 +514,8 @@ def get_cluster_info(): except KeyError: pass except ValueError: - print >>sys.stderr, "Invalid constraint value: %s = %s" % ( - k, test_constraints[k]) + print("Invalid constraint value: %s = %s" % ( + k, test_constraints[k]), file=sys.stderr) eff_constraints.update(test_constraints) # Just make it look like these constraints were loaded from a /info call, @@ -564,8 +565,8 @@ def setup_package(): in_process_setup(the_object_server=( mem_object_server if in_mem_obj else object_server)) except InProcessException as exc: - print >> sys.stderr, ('Exception during in-process setup: %s' - % str(exc)) + print(('Exception during in-process setup: %s' + % str(exc)), file=sys.stderr) raise global web_front_end @@ -674,20 +675,19 @@ def setup_package(): global skip skip = not all([swift_test_auth, swift_test_user[0], swift_test_key[0]]) if skip: - print >>sys.stderr, 'SKIPPING FUNCTIONAL TESTS DUE TO NO CONFIG' + print('SKIPPING FUNCTIONAL TESTS DUE TO NO CONFIG', file=sys.stderr) global skip2 skip2 = not all([not skip, swift_test_user[1], swift_test_key[1]]) if not skip and skip2: - print >>sys.stderr, \ - 'SKIPPING SECOND ACCOUNT FUNCTIONAL TESTS' \ - ' DUE TO NO CONFIG FOR THEM' + print('SKIPPING SECOND ACCOUNT FUNCTIONAL TESTS ' + 'DUE TO NO CONFIG FOR THEM', file=sys.stderr) global skip3 skip3 = not all([not skip, swift_test_user[2], swift_test_key[2]]) if not skip and skip3: - print >>sys.stderr, \ - 'SKIPPING THIRD ACCOUNT FUNCTIONAL TESTS DUE TO NO CONFIG FOR THEM' + print('SKIPPING THIRD ACCOUNT FUNCTIONAL TESTS' + 'DUE TO NO CONFIG FOR THEM', file=sys.stderr) global skip_if_not_v3 skip_if_not_v3 = (swift_test_auth_version != '3' @@ -695,16 +695,17 @@ def setup_package(): swift_test_user[3], swift_test_key[3]])) if not skip and skip_if_not_v3: - print >>sys.stderr, \ - 'SKIPPING FUNCTIONAL TESTS SPECIFIC TO AUTH VERSION 3' + print('SKIPPING FUNCTIONAL TESTS SPECIFIC TO AUTH VERSION 3', + file=sys.stderr) global skip_service_tokens skip_service_tokens = not all([not skip, swift_test_user[4], swift_test_key[4], swift_test_tenant[4], swift_test_service_prefix]) if not skip and skip_service_tokens: - print >>sys.stderr, \ - 'SKIPPING FUNCTIONAL TESTS SPECIFIC TO SERVICE TOKENS' + print( + 'SKIPPING FUNCTIONAL TESTS SPECIFIC TO SERVICE TOKENS', + file=sys.stderr) if policy_specified: policies = FunctionalStoragePolicyCollection.from_info() diff --git a/test/probe/brain.py b/test/probe/brain.py index bec97c78bc..9ec907c0a2 100644 --- a/test/probe/brain.py +++ b/test/probe/brain.py @@ -11,7 +11,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import print_function import sys import itertools import uuid @@ -226,8 +226,8 @@ def main(): try: brain.run(command, *args) except ClientException as e: - print '**WARNING**: %s raised %s' % (command, e) - print 'STATUS'.join(['*' * 25] * 2) + print('**WARNING**: %s raised %s' % (command, e)) + print('STATUS'.join(['*' * 25] * 2)) brain.servers.status() sys.exit() diff --git a/test/probe/common.py b/test/probe/common.py index 07977f5cd7..1479ba9ddc 100644 --- a/test/probe/common.py +++ b/test/probe/common.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import print_function import os from subprocess import Popen, PIPE import sys @@ -86,9 +86,9 @@ def check_server(ipport, ipport2server, pids, timeout=CHECK_SERVER_TIMEOUT): break except Exception as err: if time() > try_until: - print err - print 'Giving up on %s:%s after %s seconds.' % ( - server, ipport, timeout) + print(err) + print('Giving up on %s:%s after %s seconds.' % ( + server, ipport, timeout)) raise err sleep(0.1) else: @@ -102,8 +102,8 @@ def check_server(ipport, ipport2server, pids, timeout=CHECK_SERVER_TIMEOUT): return url, token, account except Exception as err: if time() > try_until: - print err - print 'Giving up on proxy:8080 after 30 seconds.' + print(err) + print('Giving up on proxy:8080 after 30 seconds.') raise err sleep(0.1) return None @@ -258,7 +258,7 @@ def get_policy(**kwargs): def resetswift(): p = Popen("resetswift 2>&1", shell=True, stdout=PIPE) stdout, _stderr = p.communicate() - print stdout + print(stdout) Manager(['all']).stop() @@ -407,11 +407,11 @@ if __name__ == "__main__": force_validate=True) except SkipTest as err: sys.exit('%s ERROR: %s' % (server, err)) - print '%s OK' % server + print('%s OK' % server) for policy in POLICIES: try: get_ring(policy.ring_name, 3, 4, server='object', force_validate=True) except SkipTest as err: sys.exit('object ERROR (%s): %s' % (policy.name, err)) - print 'object OK (%s)' % policy.name + print('object OK (%s)' % policy.name)