Merge "Python 3 using builtins instead of __builtin__, rename raw_input() to input() from six.moves"

This commit is contained in:
Jenkins
2015-10-08 08:41:30 +00:00
committed by Gerrit Code Review
4 changed files with 17 additions and 16 deletions

View File

@@ -27,6 +27,7 @@ from textwrap import wrap
from time import time from time import time
import optparse import optparse
import math import math
from six.moves import input
from swift.common import exceptions from swift.common import exceptions
from swift.common.ring import RingBuilder, Ring from swift.common.ring import RingBuilder, Ring
@@ -188,8 +189,8 @@ def _set_weight_values(devs, weight):
print('Matched more than one device:') print('Matched more than one device:')
for dev in devs: for dev in devs:
print(' %s' % format_device(dev)) print(' %s' % format_device(dev))
if raw_input('Are you sure you want to update the weight for ' if input('Are you sure you want to update the weight for '
'these %s devices? (y/N) ' % len(devs)) != 'y': 'these %s devices? (y/N) ' % len(devs)) != 'y':
print('Aborting device modifications') print('Aborting device modifications')
exit(EXIT_ERROR) exit(EXIT_ERROR)
@@ -245,8 +246,8 @@ def _set_info_values(devs, change):
print('Matched more than one device:') print('Matched more than one device:')
for dev in devs: for dev in devs:
print(' %s' % format_device(dev)) print(' %s' % format_device(dev))
if raw_input('Are you sure you want to update the info for ' if input('Are you sure you want to update the info for '
'these %s devices? (y/N) ' % len(devs)) != 'y': 'these %s devices? (y/N) ' % len(devs)) != 'y':
print('Aborting device modifications') print('Aborting device modifications')
exit(EXIT_ERROR) exit(EXIT_ERROR)
@@ -732,8 +733,8 @@ swift-ring-builder <builder_file> search
print('Matched more than one device:') print('Matched more than one device:')
for dev in devs: for dev in devs:
print(' %s' % format_device(dev)) print(' %s' % format_device(dev))
if raw_input('Are you sure you want to remove these %s ' if input('Are you sure you want to remove these %s '
'devices? (y/N) ' % len(devs)) != 'y': 'devices? (y/N) ' % len(devs)) != 'y':
print('Aborting device removals') print('Aborting device removals')
exit(EXIT_ERROR) exit(EXIT_ERROR)

View File

@@ -554,11 +554,11 @@ class TestReconCommands(unittest.TestCase):
mock.call('=' * 79), mock.call('=' * 79),
] ]
with mock.patch('__builtin__.print') as mock_print: with mock.patch('six.moves.builtins.print') as mock_print:
cli.disk_usage([('127.0.0.1', 6010)]) cli.disk_usage([('127.0.0.1', 6010)])
mock_print.assert_has_calls(default_calls) mock_print.assert_has_calls(default_calls)
with mock.patch('__builtin__.print') as mock_print: with mock.patch('six.moves.builtins.print') as mock_print:
expected_calls = default_calls + [ expected_calls = default_calls + [
mock.call('LOWEST 5'), mock.call('LOWEST 5'),
mock.call('85.00% 127.0.0.1 sdc1'), mock.call('85.00% 127.0.0.1 sdc1'),
@@ -568,7 +568,7 @@ class TestReconCommands(unittest.TestCase):
cli.disk_usage([('127.0.0.1', 6010)], 0, 5) cli.disk_usage([('127.0.0.1', 6010)], 0, 5)
mock_print.assert_has_calls(expected_calls) mock_print.assert_has_calls(expected_calls)
with mock.patch('__builtin__.print') as mock_print: with mock.patch('six.moves.builtins.print') as mock_print:
expected_calls = default_calls + [ expected_calls = default_calls + [
mock.call('TOP 5'), mock.call('TOP 5'),
mock.call('90.00% 127.0.0.1 sdb1'), mock.call('90.00% 127.0.0.1 sdb1'),
@@ -578,7 +578,7 @@ class TestReconCommands(unittest.TestCase):
cli.disk_usage([('127.0.0.1', 6010)], 5, 0) cli.disk_usage([('127.0.0.1', 6010)], 5, 0)
mock_print.assert_has_calls(expected_calls) mock_print.assert_has_calls(expected_calls)
@mock.patch('__builtin__.print') @mock.patch('six.moves.builtins.print')
@mock.patch('time.time') @mock.patch('time.time')
def test_replication_check(self, mock_now, mock_print): def test_replication_check(self, mock_now, mock_print):
now = 1430000000.0 now = 1430000000.0
@@ -633,7 +633,7 @@ class TestReconCommands(unittest.TestCase):
# that is returned from the recon middleware, thus can't rely on it # that is returned from the recon middleware, thus can't rely on it
mock_print.assert_has_calls(default_calls, any_order=True) mock_print.assert_has_calls(default_calls, any_order=True)
@mock.patch('__builtin__.print') @mock.patch('six.moves.builtins.print')
@mock.patch('time.time') @mock.patch('time.time')
def test_load_check(self, mock_now, mock_print): def test_load_check(self, mock_now, mock_print):
now = 1430000000.0 now = 1430000000.0
@@ -672,7 +672,7 @@ class TestReconCommands(unittest.TestCase):
# that is returned from the recon middleware, thus can't rely on it # that is returned from the recon middleware, thus can't rely on it
mock_print.assert_has_calls(default_calls, any_order=True) mock_print.assert_has_calls(default_calls, any_order=True)
@mock.patch('__builtin__.print') @mock.patch('six.moves.builtins.print')
@mock.patch('time.time') @mock.patch('time.time')
def test_time_check(self, mock_now, mock_print): def test_time_check(self, mock_now, mock_print):
now = 1430000000.0 now = 1430000000.0
@@ -704,7 +704,7 @@ class TestReconCommands(unittest.TestCase):
# that is returned from the recon middleware, thus can't rely on it # that is returned from the recon middleware, thus can't rely on it
mock_print.assert_has_calls(default_calls, any_order=True) mock_print.assert_has_calls(default_calls, any_order=True)
@mock.patch('__builtin__.print') @mock.patch('six.moves.builtins.print')
@mock.patch('time.time') @mock.patch('time.time')
def test_time_check_mismatch(self, mock_now, mock_print): def test_time_check_mismatch(self, mock_now, mock_print):
now = 1430000000.0 now = 1430000000.0

View File

@@ -1552,7 +1552,7 @@ class TestRingBuilder(unittest.TestCase):
self.assertEquals(loaded_rb.to_dict(), rb.to_dict()) self.assertEquals(loaded_rb.to_dict(), rb.to_dict())
self.assertEquals(loaded_rb.overload, 3.14159) self.assertEquals(loaded_rb.overload, 3.14159)
@mock.patch('__builtin__.open', autospec=True) @mock.patch('six.moves.builtins.open', autospec=True)
@mock.patch('swift.common.ring.builder.pickle.dump', autospec=True) @mock.patch('swift.common.ring.builder.pickle.dump', autospec=True)
def test_save(self, mock_pickle_dump, mock_open): def test_save(self, mock_pickle_dump, mock_open):
mock_open.return_value = mock_fh = mock.MagicMock() mock_open.return_value = mock_fh = mock.MagicMock()

View File

@@ -3446,7 +3446,7 @@ class TestECDiskFile(DiskFileMixin, unittest.TestCase):
'Content-Length': '0', 'Content-Length': '0',
} }
writer.put(metadata) writer.put(metadata)
with mock.patch('__builtin__.open', mock_open): with mock.patch('six.moves.builtins.open', mock_open):
self.assertRaises(expected_exception, self.assertRaises(expected_exception,
writer.commit, writer.commit,
timestamp) timestamp)
@@ -3493,7 +3493,7 @@ class TestECDiskFile(DiskFileMixin, unittest.TestCase):
'Content-Length': '0', 'Content-Length': '0',
} }
writer.put(metadata) writer.put(metadata)
with mock.patch('__builtin__.open', mock_open): with mock.patch('six.moves.builtins.open', mock_open):
self.assertRaises(expected_exception, self.assertRaises(expected_exception,
writer.commit, writer.commit,
timestamp) timestamp)