Replaces __builtin__ with six.moves.builtins

__builtin__ does not exist in Python 3. Replacing it with
six.moves.builtins will ensure compatibility with both Python 2.7
and Python 3.4.

Change-Id: Id185ee8331e69b534d43f6898e2c2163dbd99425
This commit is contained in:
Bo Wang 2016-01-12 19:52:27 +08:00
parent 5293536792
commit f22fe6b465
4 changed files with 11 additions and 9 deletions

View File

@ -65,7 +65,7 @@ class TestLocalManager(base.BaseTestCase):
def _store_cert(self):
file_mock = mock.mock_open()
# Attempt to store the cert
with mock.patch('__builtin__.open', file_mock, create=True):
with mock.patch('six.moves.builtins.open', file_mock, create=True):
cert_id = local_cert_manager.CertManager.store_cert(
certificate=self.certificate,
intermediates=self.intermediates,
@ -97,7 +97,7 @@ class TestLocalManager(base.BaseTestCase):
def _get_cert(self, cert_id):
file_mock = mock.mock_open()
# Attempt to retrieve the cert
with mock.patch('__builtin__.open', file_mock, create=True):
with mock.patch('six.moves.builtins.open', file_mock, create=True):
data = local_cert_manager.CertManager.get_cert(cert_id)
# Verify the correct files were opened

View File

@ -241,7 +241,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
def test_update(self):
self.driver._get_state_file_path = mock.Mock(return_value='/path')
self.driver._spawn = mock.Mock()
with mock.patch('__builtin__.open') as m_open:
with mock.patch('six.moves.builtins.open') as m_open:
file_mock = mock.MagicMock()
m_open.return_value = file_mock
file_mock.__enter__.return_value = file_mock
@ -667,7 +667,7 @@ class TestNamespaceDriverModule(base.BaseTestCase):
@mock.patch('neutron.agent.linux.utils.execute')
def test_kill_pids_in_file(self, execute, exists):
pid_path = '/var/lib/data'
with mock.patch('__builtin__.open') as m_open:
with mock.patch('six.moves.builtins.open') as m_open:
exists.return_value = False
file_mock = mock.MagicMock()
m_open.return_value = file_mock

View File

@ -20,6 +20,7 @@ import mock
from neutron.common import exceptions
from neutron.extensions import portbindings
from neutron.plugins.common import constants
import six
from neutron_lbaas.db.loadbalancer import models
from neutron_lbaas.drivers.haproxy \
@ -78,7 +79,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
rdb.asert_called_once_with(dirs)
upin.assert_has_calls([mock.call(lbs[0]), mock.call(lbs[1])])
self.assertEqual(2, upin.call_count)
#deployed_loadbalancer_ids is a set
# deployed_loadbalancer_ids is a set
self.assertEqual(1, len(self.driver.deployed_loadbalancer_ids))
self.assertIn(self._sample_in_loadbalancer().id,
self.driver.deployed_loadbalancer_ids)
@ -514,7 +515,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
with contextlib.nested(
mock.patch.object(self.driver, '_get_state_file_path'),
mock.patch.object(self.driver, '_spawn'),
mock.patch('__builtin__.open')
mock.patch.object(six.moves.builtins, 'open')
) as (gsp, spawn, mock_open):
mock_open.return_value = ['5']
@ -650,7 +651,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
def test_kill_pids_in_file(self):
with contextlib.nested(
mock.patch('os.path.exists'),
mock.patch('__builtin__.open'),
mock.patch.object(six.moves.builtins, 'open'),
mock.patch('neutron.agent.linux.utils.execute'),
mock.patch.object(namespace_driver.LOG, 'exception'),
) as (path_exists, mock_open, mock_execute, mock_log):

View File

@ -16,6 +16,7 @@ import contextlib
import mock
from neutron.common import exceptions
import six
from neutron_lbaas.services.loadbalancer.drivers.haproxy \
import namespace_driver
@ -73,7 +74,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
with contextlib.nested(
mock.patch.object(self.driver, '_get_state_file_path'),
mock.patch.object(self.driver, '_spawn'),
mock.patch('__builtin__.open')
mock.patch.object(six.moves.builtins, 'open')
) as (gsp, spawn, mock_open):
mock_open.return_value = ['5']
@ -410,7 +411,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
def test_kill_pids_in_file(self):
with contextlib.nested(
mock.patch('os.path.exists'),
mock.patch('__builtin__.open'),
mock.patch.object(six.moves.builtins, 'open'),
mock.patch('neutron.agent.linux.utils.execute'),
mock.patch.object(namespace_driver.LOG, 'exception'),
) as (path_exists, mock_open, mock_execute, mock_log):