fix up assertEqual(None...) check to catch more cases

To finally close out bug #1280522 it turned out that our hacking check
to eliminate assertEqual(None, ...) was pretty sub optimal. The
perfect fix would actually use the tokenizer, however this is a better
regex which catches a few more missing bits in our codebase. It's
probably close enough for most of what we need.

Fix the relevant tests that would fail the updating hacking check.

Change-Id: Ic8cb1192e001409d827c8da55fe536681895944b
Closes-Bug: #1280522
changes/82/121582/1
Sean Dague 8 years ago
parent a5f09ddddf
commit 5dd34c93e2
  1. 8
      nova/hacking/checks.py
  2. 2
      nova/tests/api/openstack/test_wsgi.py
  3. 6
      nova/tests/network/test_api.py
  4. 4
      nova/tests/pci/test_pci_stats.py
  5. 4
      nova/tests/virt/libvirt/test_blockinfo.py
  6. 2
      nova/tests/virt/libvirt/test_imagebackend.py
  7. 11
      nova/tests/virt/xenapi/test_volume_utils.py

@ -51,9 +51,9 @@ asse_equal_type_re = re.compile(
r"(.)*assertEqual\(type\((\w|\.|\'|\"|\[|\])+\), "
"(\w|\.|\'|\"|\[|\])+\)")
asse_equal_end_with_none_re = re.compile(
r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
r"assertEqual\(.*?,\s+None\)$")
asse_equal_start_with_none_re = re.compile(
r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
r"assertEqual\(None,")
conf_attribute_set_re = re.compile(r"CONF\.[a-z0-9_.]+\s*=\s*\w")
log_translation = re.compile(
r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)\(\s*('|\")")
@ -250,8 +250,8 @@ def assert_equal_none(logical_line):
N318
"""
res = (asse_equal_start_with_none_re.match(logical_line) or
asse_equal_end_with_none_re.match(logical_line))
res = (asse_equal_start_with_none_re.search(logical_line) or
asse_equal_end_with_none_re.search(logical_line))
if res:
yield (0, "N318: assertEqual(A, None) or assertEqual(None, A) "
"sentences not allowed")

@ -125,7 +125,7 @@ class RequestTest(test.NoDBTestCase):
compute_nodes[1])
self.assertEqual(request.get_db_compute_node('id2'),
compute_nodes[2])
self.assertEqual(request.get_db_compute_node('id3'), None)
self.assertIsNone(request.get_db_compute_node('id3'))
self.assertEqual(request.get_db_compute_nodes(),
{'id0': compute_nodes[0],
'id1': compute_nodes[1],

@ -517,9 +517,9 @@ class ApiTestCase(test.TestCase):
@mock.patch('nova.objects.FixedIP.get_by_floating_address')
def test_get_instance_by_floating_address_none(self, mock_get_by_floating):
mock_get_by_floating.return_value = None
self.assertEqual(None,
self.network_api.get_instance_id_by_floating_address(
self.context, mock.sentinel.floating))
self.assertIsNone(
self.network_api.get_instance_id_by_floating_address(
self.context, mock.sentinel.floating))
mock_get_by_floating.assert_called_once_with(self.context,
mock.sentinel.floating)

@ -237,7 +237,7 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
pci_dev_obj = objects.PciDevice.create(pci_dev)
self.pci_stats.add_device(pci_dev_obj)
# There should be no change
self.assertEqual(None,
self.assertIsNone(
self.pci_stats._create_pool_keys_from_dev(pci_dev_obj))
self._assertPools()
@ -253,7 +253,7 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
pci_dev_obj = objects.PciDevice.create(pci_dev)
self.pci_stats.remove_device(pci_dev_obj)
# There should be no change
self.assertEqual(None,
self.assertIsNone(
self.pci_stats._create_pool_keys_from_dev(pci_dev_obj))
self._assertPools()

@ -725,10 +725,10 @@ class LibvirtBlockInfoTest(test.TestCase):
self.assertEqual('/dev/vda', blockinfo.get_device_name(driver_bdm))
bdm_obj.device_name = None
self.assertEqual(None, blockinfo.get_device_name(bdm_obj))
self.assertIsNone(blockinfo.get_device_name(bdm_obj))
driver_bdm = driver_block_device.DriverVolumeBlockDevice(bdm_obj)
self.assertEqual(None, blockinfo.get_device_name(driver_bdm))
self.assertIsNone(blockinfo.get_device_name(driver_bdm))
@mock.patch('nova.virt.libvirt.blockinfo.find_disk_dev_for_disk_bus',
return_value='vda')

@ -1287,6 +1287,6 @@ class UtilTestCase(test.NoDBTestCase):
def test_get_hw_disk_discard(self):
self.assertEqual('unmap', imagebackend.get_hw_disk_discard("unmap"))
self.assertEqual('ignore', imagebackend.get_hw_disk_discard("ignore"))
self.assertEqual(None, imagebackend.get_hw_disk_discard(None))
self.assertIsNone(imagebackend.get_hw_disk_discard(None))
self.assertRaises(RuntimeError, imagebackend.get_hw_disk_discard,
"fake")

@ -37,9 +37,8 @@ class SROps(stubs.XenAPITestBaseNoDB):
self.session = mock.Mock()
self.session.XenAPI.Failure = UUIDException
self.session.call_xenapi.side_effect = UUIDException
self.assertEqual(volume_utils.find_sr_by_uuid(self.session,
'sr_uuid'),
None)
self.assertIsNone(
volume_utils.find_sr_by_uuid(self.session, 'sr_uuid'))
def test_find_sr_from_vdi(self):
vdi_ref = 'fake-ref'
@ -81,11 +80,9 @@ class ISCSIParametersTestCase(stubs.XenAPITestBaseNoDB):
'host')
# There is no default value
self.assertEqual(volume_utils._get_target_host(':port'),
None)
self.assertIsNone(volume_utils._get_target_host(':port'))
self.assertEqual(volume_utils._get_target_host(None),
None)
self.assertIsNone(volume_utils._get_target_host(None))
def test_target_port(self):
self.assertEqual(volume_utils._get_target_port('host:port'),

Loading…
Cancel
Save