From c5b5cf91a984f80cc6cbe42735b242083d700542 Mon Sep 17 00:00:00 2001 From: janonymous Date: Tue, 28 Jul 2015 21:03:05 +0530 Subject: [PATCH] test/unit: 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: I94e1bc6bd83ad6b05695c7ebdf7cbfd8f6d9f9af --- test/unit/__init__.py | 7 ++++--- test/unit/common/test_db_replicator.py | 3 ++- test/unit/common/test_manager.py | 12 ++++++------ test/unit/common/test_utils.py | 14 +++++++------- test/unit/proxy/controllers/test_container.py | 3 ++- test/unit/proxy/test_server.py | 3 ++- test/unit/test_locale/test_locale.py | 3 ++- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/test/unit/__init__.py b/test/unit/__init__.py index b67f44342c..16057e91ce 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -15,6 +15,7 @@ """ Swift tests """ +from __future__ import print_function import os import copy import logging @@ -572,8 +573,8 @@ class FakeLogger(logging.Logger, object): try: line = record.getMessage() except TypeError: - print 'WARNING: unable to format log message %r %% %r' % ( - record.msg, record.args) + print('WARNING: unable to format log message %r %% %r' % ( + record.msg, record.args)) raise self.lines_dict[record.levelname.lower()].append(line) @@ -597,7 +598,7 @@ class DebugLogger(FakeLogger): def handle(self, record): self._handle(record) - print self.formatter.format(record) + print(self.formatter.format(record)) class DebugLogAdapter(utils.LogAdapter): diff --git a/test/unit/common/test_db_replicator.py b/test/unit/common/test_db_replicator.py index f15a895e9f..91a5adfbfd 100644 --- a/test/unit/common/test_db_replicator.py +++ b/test/unit/common/test_db_replicator.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 unittest from contextlib import contextmanager import os @@ -1304,7 +1305,7 @@ def attach_fake_replication_rpc(rpc, replicate_hook=None): self.host = node['replication_ip'] def replicate(self, op, *sync_args): - print 'REPLICATE: %s, %s, %r' % (self.path, op, sync_args) + print('REPLICATE: %s, %s, %r' % (self.path, op, sync_args)) replicate_args = self.path.lstrip('/').split('/') args = [op] + list(sync_args) swob_response = rpc.dispatch(replicate_args, args) diff --git a/test/unit/common/test_manager.py b/test/unit/common/test_manager.py index d759a9ba97..ebdab67d26 100644 --- a/test/unit/common/test_manager.py +++ b/test/unit/common/test_manager.py @@ -12,7 +12,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import print_function import unittest from test.unit import temptree @@ -1188,9 +1188,9 @@ class TestServer(unittest.TestCase): pass def fail(self): - print >>self._stdout, 'mock process started' + print('mock process started', file=self._stdout) sleep(self.delay) # perform setup processing - print >>self._stdout, 'mock process failed to start' + print('mock process failed to start', file=self._stdout) self.close_stdout() def poll(self): @@ -1198,12 +1198,12 @@ class TestServer(unittest.TestCase): return self.returncode or None def run(self): - print >>self._stdout, 'mock process started' + print('mock process started', file=self._stdout) sleep(self.delay) # perform setup processing - print >>self._stdout, 'setup complete!' + print('setup complete!', file=self._stdout) self.close_stdout() sleep(self.delay) # do some more processing - print >>self._stdout, 'mock process finished' + print('mock process finished', file=self._stdout) self.finished = True class MockTime(object): diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index b5dc6edf32..1d2c105dd2 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -14,7 +14,7 @@ # limitations under the License. """Tests for swift.common.utils""" - +from __future__ import print_function from test.unit import temptree import ctypes @@ -1047,22 +1047,22 @@ class TestUtils(unittest.TestCase): lfo_stdout = utils.LoggerFileObject(logger) lfo_stderr = utils.LoggerFileObject(logger) lfo_stderr = utils.LoggerFileObject(logger, 'STDERR') - print 'test1' + print('test1') self.assertEquals(sio.getvalue(), '') sys.stdout = lfo_stdout - print 'test2' + print('test2') self.assertEquals(sio.getvalue(), 'STDOUT: test2\n') sys.stderr = lfo_stderr - print >> sys.stderr, 'test4' + print('test4', file=sys.stderr) self.assertEquals(sio.getvalue(), 'STDOUT: test2\nSTDERR: test4\n') sys.stdout = orig_stdout - print 'test5' + print('test5') self.assertEquals(sio.getvalue(), 'STDOUT: test2\nSTDERR: test4\n') - print >> sys.stderr, 'test6' + print('test6', file=sys.stderr) self.assertEquals(sio.getvalue(), 'STDOUT: test2\nSTDERR: test4\n' 'STDERR: test6\n') sys.stderr = orig_stderr - print 'test8' + print('test8') self.assertEquals(sio.getvalue(), 'STDOUT: test2\nSTDERR: test4\n' 'STDERR: test6\n') lfo_stdout.writelines(['a', 'b', 'c']) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index d2b7ce450e..69e8fedbc9 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.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 unittest @@ -164,7 +165,7 @@ class TestContainerController(TestRingBase): self.app._error_limiting = {} req = Request.blank('/v1/a/c', method=method) with mocked_http_conn(*statuses) as fake_conn: - print 'a' * 50 + print('a' * 50) resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) for req in fake_conn.requests: diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index dde59e3597..b2b87dbc0b 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import email.parser import logging import math @@ -9128,7 +9129,7 @@ class TestProxyObjectPerformance(unittest.TestCase): self.assertEqual(total, self.obj_len) end = time.time() - print "Run %02d took %07.03f" % (i, end - start) + print("Run %02d took %07.03f" % (i, end - start)) @patch_policies([StoragePolicy(0, 'migrated', object_ring=FakeRing()), diff --git a/test/unit/test_locale/test_locale.py b/test/unit/test_locale/test_locale.py index a0804ed0eb..a5973cd83f 100644 --- a/test/unit/test_locale/test_locale.py +++ b/test/unit/test_locale/test_locale.py @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import os import unittest import string @@ -75,4 +76,4 @@ if __name__ == "__main__": os.environ['SWIFT_LOCALEDIR'] = os.path.dirname(__file__) sys.path = string.split(sys.argv[1], ':') from swift import gettext_ as _ - print _('test message') + print(_('test message'))