Merge "test/unit: Replace python print operator with print function (pep H233, py33)"

This commit is contained in:
Jenkins 2015-08-11 09:49:50 +00:00 committed by Gerrit Code Review
commit f644eaef7d
7 changed files with 25 additions and 20 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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):

View File

@ -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'])

View File

@ -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:

View File

@ -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()),

View File

@ -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'))