]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python3: do not use __builtin__
authorCyril Roelandt <cyril@redhat.com>
Mon, 22 Jun 2015 13:02:17 +0000 (13:02 +0000)
committerCyril Roelandt <cyril@redhat.com>
Mon, 22 Jun 2015 14:03:51 +0000 (16:03 +0200)
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

neutron/tests/unit/agent/linux/test_daemon.py
neutron/tests/unit/agent/linux/test_dhcp.py
neutron/tests/unit/agent/linux/test_external_process.py
neutron/tests/unit/common/test_ipv6_utils.py
neutron/tests/unit/db/test_db_base_plugin_v2.py
neutron/tests/unit/db/test_migration.py
neutron/tests/unit/extensions/test_securitygroup.py
neutron/tests/unit/tests/test_post_mortem_debug.py
tox.ini

index 1ff0cc12268223ab7ad428fcb330e8cb6ce9cf52..5914c55f48324a7d280819dd5ceca0c0d3206633 100644 (file)
@@ -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()
index 44a017245a34884b9efe0b1a582466b4c734ba33..330e0d8607cf1e0bf7788ea3712cbdf27e8026da 100644 (file)
@@ -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",
index cb99da8f73f267cdbb79d3a038927541f6702739..079b370aea2ce8785f0ae6f8014a2ad0ac860f80 100644 (file)
@@ -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 = \
index 9ec11c8fafa0b5c87a31899e806a206c8b6ad325..e7d77c5abb002f17f74c5ec185e91b5b2811f994 100644 (file)
@@ -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):
index ba99aa6248760baccff968085c851f042a483b1f..aec1e57f96572e4fa1bf42bfa5252300362abab1 100644 (file)
@@ -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')
index a5cc18e8f2606b0cd696eba1a31394dc194ef89f..f795bafb080aa2203e973d657864fba67d580dca 100644 (file)
@@ -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()
 
index cf616cc45d60daef572820fa96a17c82047a26d0..31b191cf89d75123fc81d268e6c7fa60071ec75b 100644 (file)
@@ -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(
index 652bdee6bfd0745e6714e28dda97858651e914b2..5c6692d63ec04c28fd364bd9d21679937d14c1af 100644 (file)
@@ -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__)
diff --git a/tox.ini b/tox.ini
index 45f8968fd4876efa2c3a59104f98501227c75722..296a0cb6efd2820ebe9c94bdb772ac413ce0621b 100644 (file)
--- a/tox.ini
+++ b/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 \