diff --git a/test/unit/__init__.py b/test/unit/__init__.py index fd9411b942..a6c5001c3c 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 85d4d4109d..5402ab1de8 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 4d43ceed75..0fc251fe92 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 d113a70afe..85c27fa2ed 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 @@ -8460,7 +8461,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 33544eb64b..fcaca52ef5 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 sys @@ -74,4 +75,4 @@ if __name__ == "__main__": os.environ['SWIFT_LOCALEDIR'] = os.path.dirname(__file__) sys.path = sys.argv[1].split(':') from swift import gettext_ as _ - print _('test message') + print(_('test message'))