Python3: do not use __builtin__
It has been replaced with builtins in Python 3. Use six.moves.builtins, since it works with Python 2 and 3. Change-Id: I9e1b0060a5b18116d991cafb1de085d4d084db38 Blueprint: neutron-python3
This commit is contained in:
parent
1b1d07823d
commit
0faf4a2645
|
@ -171,7 +171,7 @@ class TestPidfile(base.BaseTestCase):
|
|||
self.assertEqual(34, p.read())
|
||||
|
||||
def test_is_running(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
p = daemon.Pidfile('thefile', 'python')
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
|
@ -184,7 +184,7 @@ class TestPidfile(base.BaseTestCase):
|
|||
mock_open.assert_called_once_with('/proc/34/cmdline', 'r')
|
||||
|
||||
def test_is_running_uuid_true(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
p = daemon.Pidfile('thefile', 'python', uuid='1234')
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
|
@ -197,7 +197,7 @@ class TestPidfile(base.BaseTestCase):
|
|||
mock_open.assert_called_once_with('/proc/34/cmdline', 'r')
|
||||
|
||||
def test_is_running_uuid_false(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
p = daemon.Pidfile('thefile', 'python', uuid='6789')
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
|
|
|
@ -824,7 +824,7 @@ class TestDhcpLocalProcess(TestBase):
|
|||
parent.assert_has_calls(expected)
|
||||
|
||||
def test_get_interface_name(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.read.return_value = 'tap0'
|
||||
|
@ -1369,7 +1369,7 @@ class TestDnsmasq(TestBase):
|
|||
exp_addn_name, exp_addn_data,
|
||||
exp_opt_name, exp_opt_data,) = self._test_reload_allocation_data
|
||||
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.readline.return_value = None
|
||||
|
@ -1472,7 +1472,7 @@ class TestDnsmasq(TestBase):
|
|||
|
||||
def test_read_hosts_file_leases(self):
|
||||
filename = '/path/to/file'
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
lines = ["00:00:80:aa:bb:cc,inst-name,192.168.0.1",
|
||||
|
@ -1489,7 +1489,7 @@ class TestDnsmasq(TestBase):
|
|||
|
||||
def test_read_hosts_file_leases_with_client_id(self):
|
||||
filename = '/path/to/file'
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
lines = ["00:00:80:aa:bb:cc,id:client1,inst-name,192.168.0.1",
|
||||
|
|
|
@ -213,7 +213,7 @@ class TestProcessManager(base.BaseTestCase):
|
|||
self.assertEqual(retval, '/var/path/uuid.pid')
|
||||
|
||||
def test_pid(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.read.return_value = '5'
|
||||
|
@ -221,7 +221,7 @@ class TestProcessManager(base.BaseTestCase):
|
|||
self.assertEqual(manager.pid, 5)
|
||||
|
||||
def test_pid_no_an_int(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.read.return_value = 'foo'
|
||||
|
@ -235,7 +235,7 @@ class TestProcessManager(base.BaseTestCase):
|
|||
self.assertIsNone(manager.pid)
|
||||
|
||||
def test_active(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.readline.return_value = \
|
||||
|
@ -256,7 +256,7 @@ class TestProcessManager(base.BaseTestCase):
|
|||
self.assertFalse(manager.active)
|
||||
|
||||
def test_active_cmd_mismatch(self):
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.readline.return_value = \
|
||||
|
|
|
@ -65,7 +65,7 @@ class TestIsEnabled(base.BaseTestCase):
|
|||
self.addCleanup(reset_detection_flag)
|
||||
self.mock_exists = mock.patch("os.path.exists",
|
||||
return_value=True).start()
|
||||
mock_open = mock.patch("__builtin__.open").start()
|
||||
mock_open = mock.patch("six.moves.builtins.open").start()
|
||||
self.mock_read = mock_open.return_value.__enter__.return_value.read
|
||||
|
||||
def test_enabled(self):
|
||||
|
|
|
@ -972,7 +972,7 @@ class TestPortsV2(NeutronDbPluginV2TestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
with self.network() as net:
|
||||
res = self._create_port_bulk(self.fmt, 2, net['network']['id'],
|
||||
|
@ -1003,7 +1003,7 @@ class TestPortsV2(NeutronDbPluginV2TestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
orig = manager.NeutronManager.get_plugin().create_port
|
||||
method_to_patch = _get_create_db_method('port')
|
||||
|
@ -2435,7 +2435,7 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
res = self._create_network_bulk(self.fmt, 2, 'test', True)
|
||||
self._validate_behavior_on_bulk_success(res, 'networks')
|
||||
|
@ -2461,7 +2461,7 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
|
|||
|
||||
orig = manager.NeutronManager.get_plugin().create_network
|
||||
#ensures the API choose the emulation code path
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
method_to_patch = _get_create_db_method('network')
|
||||
with mock.patch.object(manager.NeutronManager.get_plugin(),
|
||||
|
@ -2924,7 +2924,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
with self.network() as net:
|
||||
res = self._create_subnet_bulk(self.fmt, 2,
|
||||
|
@ -2941,7 +2941,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
orig = manager.NeutronManager.get_plugin().create_subnet
|
||||
method_to_patch = _get_create_db_method('subnet')
|
||||
|
|
|
@ -173,7 +173,7 @@ class TestCli(base.BaseTestCase):
|
|||
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
|
||||
fc.return_value.get_heads.return_value = heads
|
||||
fc.return_value.get_current_head.return_value = heads[0]
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
mock_open.return_value.read.return_value = file_content
|
||||
|
@ -219,7 +219,7 @@ class TestCli(base.BaseTestCase):
|
|||
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
|
||||
fc.return_value.get_heads.return_value = ['a']
|
||||
fc.return_value.get_current_head.return_value = 'a'
|
||||
with mock.patch('__builtin__.open') as mock_open:
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_open.return_value.__enter__ = lambda s: s
|
||||
mock_open.return_value.__exit__ = mock.Mock()
|
||||
|
||||
|
|
|
@ -1292,7 +1292,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
with self.security_group() as sg:
|
||||
rule1 = self._build_security_group_rule(
|
||||
|
@ -1363,7 +1363,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
|
||||
with self.security_group() as sg:
|
||||
|
@ -1400,7 +1400,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
|
|||
return False
|
||||
return real_has_attr(item, attr)
|
||||
|
||||
with mock.patch('__builtin__.hasattr',
|
||||
with mock.patch('six.moves.builtins.hasattr',
|
||||
new=fakehasattr):
|
||||
with self.security_group() as sg:
|
||||
rule = self._build_security_group_rule(
|
||||
|
|
|
@ -48,7 +48,8 @@ class TestTesttoolsExceptionHandler(base.BaseTestCase):
|
|||
mod_mock.post_mortem = mock.Mock()
|
||||
return mod_mock
|
||||
|
||||
with mock.patch('__builtin__.__import__', side_effect=import_mock):
|
||||
with mock.patch('six.moves.builtins.__import__',
|
||||
side_effect=import_mock):
|
||||
pdb_debugger = post_mortem_debug._get_debugger('pdb')
|
||||
pudb_debugger = post_mortem_debug._get_debugger('pudb')
|
||||
self.assertEqual('pdb', pdb_debugger.__name__)
|
||||
|
|
10
tox.ini
10
tox.ini
|
@ -98,6 +98,8 @@ commands = python -m testtools.run \
|
|||
neutron.tests.unit.services.metering.drivers.test_iptables \
|
||||
neutron.tests.unit.services.l3_router.test_l3_apic \
|
||||
neutron.tests.unit.plugins.sriovnicagent.test_sriov_nic_agent \
|
||||
neutron.tests.unit.plugins.sriovnicagent.test_eswitch_manager \
|
||||
neutron.tests.unit.plugins.sriovnicagent.common.test_config \
|
||||
neutron.tests.unit.plugins.sriovnicagent.test_pci_lib \
|
||||
neutron.tests.unit.plugins.openvswitch.agent.ovs_test_base \
|
||||
neutron.tests.unit.plugins.openvswitch.agent.openflow.ovs_ofctl.test_br_phys \
|
||||
|
@ -116,6 +118,7 @@ commands = python -m testtools.run \
|
|||
neutron.tests.unit.plugins.ml2.drivers.test_mech_openvswitch \
|
||||
neutron.tests.unit.plugins.ml2.drivers.test_mech_linuxbridge \
|
||||
neutron.tests.unit.plugins.ml2.drivers.base_type_tunnel \
|
||||
neutron.tests.unit.plugins.ml2.drivers.opendaylight.test_driver \
|
||||
neutron.tests.unit.plugins.ml2.drivers.ext_test \
|
||||
neutron.tests.unit.plugins.ml2.drivers.mech_sriov.test_mech_sriov_nic_switch \
|
||||
neutron.tests.unit.plugins.ml2.drivers.mech_fake_agent \
|
||||
|
@ -133,9 +136,11 @@ commands = python -m testtools.run \
|
|||
neutron.tests.unit.plugins.cisco.n1kv.fake_client \
|
||||
neutron.tests.unit.plugins.cisco.test_network_db \
|
||||
neutron.tests.unit.db.test_l3_dvr_db \
|
||||
neutron.tests.unit.db.test_migration \
|
||||
neutron.tests.unit.db.test_agents_db \
|
||||
neutron.tests.unit.db.test_dvr_mac_db \
|
||||
neutron.tests.unit.debug.test_commands \
|
||||
neutron.tests.unit.tests.test_post_mortem_debug \
|
||||
neutron.tests.unit.tests.test_base \
|
||||
neutron.tests.unit.database_stubs \
|
||||
neutron.tests.unit.dummy_plugin \
|
||||
|
@ -161,12 +166,15 @@ commands = python -m testtools.run \
|
|||
neutron.tests.unit.agent.common.test_polling \
|
||||
neutron.tests.unit.agent.linux.test_ip_lib \
|
||||
neutron.tests.unit.agent.linux.test_keepalived \
|
||||
neutron.tests.unit.agent.linux.test_daemon \
|
||||
neutron.tests.unit.agent.linux.test_ipset_manager \
|
||||
neutron.tests.unit.agent.linux.test_iptables_firewall \
|
||||
neutron.tests.unit.agent.linux.test_ebtables_manager \
|
||||
neutron.tests.unit.agent.linux.test_ebtables_driver \
|
||||
neutron.tests.unit.agent.linux.test_polling \
|
||||
neutron.tests.unit.agent.linux.test_ip_monitor \
|
||||
neutron.tests.unit.agent.linux.test_iptables_manager \
|
||||
neutron.tests.unit.agent.linux.test_external_process \
|
||||
neutron.tests.unit.agent.linux.test_ovsdb_monitor \
|
||||
neutron.tests.unit.agent.linux.test_bridge_lib \
|
||||
neutron.tests.unit.agent.linux.test_ip_link_support \
|
||||
|
@ -181,6 +189,8 @@ commands = python -m testtools.run \
|
|||
neutron.tests.unit.hacking.test_checks \
|
||||
neutron.tests.unit.common.test_config \
|
||||
neutron.tests.unit.common.test_rpc \
|
||||
neutron.tests.unit.common.test_log \
|
||||
neutron.tests.unit.common.test_ipv6_utils \
|
||||
neutron.tests.unit.cmd.test_ovs_cleanup \
|
||||
neutron.tests.unit.cmd.test_netns_cleanup \
|
||||
neutron.tests.unit.ipam.drivers.neutrondb_ipam.test_db_api \
|
||||
|
|
Loading…
Reference in New Issue