Permalink
Browse files

Merge "Replace assertTrue/False with assertIn/NotIn"

  • Loading branch information...
2 parents 495214c + 5499758 commit 301f69041e4dd509155efcead81f93ff2bf6f6cb Jenkins committed with openstack-gerrit Jul 19, 2014
@@ -87,9 +87,9 @@ def test_index(self):
'migrations': migrations.output(migrations_obj)}
for mig in migrations_in_progress['migrations']:
- self.assertTrue('id' in mig)
- self.assertTrue('deleted' not in mig)
- self.assertTrue('deleted_at' not in mig)
+ self.assertIn('id', mig)
+ self.assertNotIn('deleted', mig)
+ self.assertNotIn('deleted_at', mig)
filters = {'host': 'host1', 'status': 'migrating',
'cell_name': 'ChildCell'}
@@ -453,7 +453,7 @@ def _verify_server_group(self, raw_group, tree):
for idx, gr_child in enumerate(child):
self.assertEqual(self._tag(gr_child), 'meta')
key = gr_child.get('key')
- self.assertTrue(key in ['key1', 'key2'])
+ self.assertIn(key, ['key1', 'key2'])
metas[key] = gr_child.text
self.assertEqual(len(metas), len(metadata))
for k in metadata:
@@ -334,8 +334,8 @@ def test_create_private_flavor_should_create_flavor_access(self):
"tenant_id": "%s" % ctxt.project_id,
"flavor_id": "%s" % body["flavor"]["id"]
}
- self.assertTrue(expected_flavor_access_body in
- flavor_access_body["flavor_access"])
+ self.assertIn(expected_flavor_access_body,
+ flavor_access_body["flavor_access"])
def test_create_public_flavor_should_not_create_flavor_access(self):
self.base_request_dict['flavor']['flavor-access:is_public'] = True
@@ -86,9 +86,9 @@ def test_index(self):
'migrations': migrations.output(migrations_obj)}
for mig in migrations_in_progress['migrations']:
- self.assertTrue('id' in mig)
- self.assertTrue('deleted' not in mig)
- self.assertTrue('deleted_at' not in mig)
+ self.assertIn('id', mig)
+ self.assertNotIn('deleted', mig)
+ self.assertNotIn('deleted_at', mig)
filters = {'host': 'host1', 'status': 'migrating',
'cell_name': 'ChildCell'}
@@ -910,7 +910,7 @@ def fake_block_device_mapping_get_all_by_instance(context, inst_id,
self.assertEqual(bdms[0]['snapshot_id'], snapshot['id'])
for fld in ('connection_info', 'id',
'instance_uuid', 'device_name'):
- self.assertTrue(fld not in bdms[0])
+ self.assertNotIn(fld, bdms[0])
for k in extra_properties.keys():
self.assertEqual(properties[k], extra_properties[k])
@@ -721,7 +721,7 @@ def fake_get_all(context, filters=None, sort_key=None,
req = fakes.HTTPRequestV3.blank('/servers?tenant_id=newfake')
res = self.controller.index(req)
- self.assertTrue('servers' in res)
+ self.assertIn('servers', res)
def test_tenant_id_filter_implies_all_tenants(self):
def fake_get_all(context, filters=None, sort_key=None,
@@ -743,7 +743,7 @@ def fake_get_all(context, filters=None, sort_key=None,
req = fakes.HTTPRequestV3.blank('/servers?tenant_id=newfake',
use_admin_context=True)
res = self.controller.index(req)
- self.assertTrue('servers' in res)
+ self.assertIn('servers', res)
def test_all_tenants_param_normal(self):
def fake_get_all(context, filters=None, sort_key=None,
@@ -1101,7 +1101,7 @@ def fake_block_device_mapping_get_all_by_instance(context, inst_id,
self.assertEqual(bdms[0]['snapshot_id'], snapshot['id'])
for fld in ('connection_info', 'id',
'instance_uuid', 'device_name'):
- self.assertTrue(fld not in bdms[0])
+ self.assertNotIn(fld, bdms[0])
for k in extra_properties.keys():
self.assertEqual(properties[k], extra_properties[k])
@@ -5660,8 +5660,7 @@ def test_add_instance_fault_with_remote_error(self):
exc_info = None
def fake_db_fault_create(ctxt, values):
- self.assertTrue('raise messaging.RemoteError'
- in values['details'])
+ self.assertIn('raise messaging.RemoteError', values['details'])
del values['details']
expected = {
@@ -666,8 +666,7 @@ def _setup_aggregate_with_host(self):
def test_aggregate_host_add(self):
aggregate_ref = self._setup_aggregate_with_host()
- self.assertTrue(any([host == 'bar'
- for host in aggregate_ref['hosts']]))
+ self.assertIn('bar', aggregate_ref['hosts'])
db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
@@ -680,8 +679,7 @@ def test_aggregate_host_delete(self):
aggregate_ref = db.aggregate_get(self.context.elevated(),
aggregate_ref['id'])
- self.assertFalse(any([host == 'bar'
- for host in aggregate_ref['hosts']]))
+ self.assertNotIn('bar', aggregate_ref['hosts'])
db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
@@ -467,9 +467,10 @@ def _verify_nw_info(self, nw_inf, index=0):
self.assertEqual('my_mac%s' % id_suffix, nw_inf[index]['address'])
self.assertEqual('10.0.%s.0/24' % id_suffix,
nw_inf[index]['network']['subnets'][0]['cidr'])
- self.assertTrue(model.IP(address='8.8.%s.1' % id_suffix,
- version=4, type='dns') in
- nw_inf[index]['network']['subnets'][0]['dns'])
+
+ ip_addr = model.IP(address='8.8.%s.1' % id_suffix,
+ version=4, type='dns')
+ self.assertIn(ip_addr, nw_inf[index]['network']['subnets'][0]['dns'])
def _get_instance_nw_info(self, number):
api = neutronapi.API()
@@ -207,7 +207,7 @@ def _check_parsing_result(self, weigher, setting, results):
weigher._parse_setting()
self.assertEqual(len(weigher.setting), len(results))
for item in results:
- self.assertTrue(item in weigher.setting)
+ self.assertIn(item, weigher.setting)
def test_parse_setting(self):
weigher = self.weight_classes[0]()
@@ -368,23 +368,23 @@ def fake_validate(obj, dct):
self.assertIn('field1', dev_dict)
self.assertIn('field2', dev_dict)
self.assertIn('db_field1', dev_dict)
- self.assertFalse('db_field2'in dev_dict)
+ self.assertNotIn('db_field2', dev_dict)
# Make sure all expected fields are defaulted
dev_dict = block_device.BlockDeviceDict({'field1': 'foo'})
self.assertIn('field1', dev_dict)
self.assertIn('field2', dev_dict)
self.assertIsNone(dev_dict['field2'])
self.assertNotIn('db_field1', dev_dict)
- self.assertFalse('db_field2'in dev_dict)
+ self.assertNotIn('db_field2', dev_dict)
# Unless they are not meant to be
dev_dict = block_device.BlockDeviceDict({'field1': 'foo'},
do_not_default=set(['field2']))
self.assertIn('field1', dev_dict)
self.assertNotIn('field2', dev_dict)
self.assertNotIn('db_field1', dev_dict)
- self.assertFalse('db_field2'in dev_dict)
+ self.assertNotIn('db_field2', dev_dict)
# Passing kwargs to constructor works
dev_dict = block_device.BlockDeviceDict(field1='foo')
@@ -542,7 +542,7 @@ def test_image_mapping(self):
mapping_bdm = fake_block_device.FakeDbBlockDeviceDict(
bdm).get_image_mapping()
for fld in removed_fields:
- self.assertTrue(fld not in mapping_bdm)
+ self.assertNotIn(fld, mapping_bdm)
def _test_snapshot_from_bdm(self, template):
snapshot = block_device.snapshot_from_bdm('new-snapshot-id', template)
@@ -117,14 +117,13 @@ def test_filter_rules_are_wrapped(self):
table = self.manager.ipv4['filter']
table.add_rule('FORWARD', '-s 1.2.3.4/5 -j DROP')
new_lines = self.manager._modify_rules(current_lines, table, 'filter')
- self.assertTrue('[0:0] -A %s-FORWARD '
- '-s 1.2.3.4/5 -j DROP' % self.binary_name in new_lines)
+ self.assertIn('[0:0] -A %s-FORWARD '
+ '-s 1.2.3.4/5 -j DROP' % self.binary_name, new_lines)
table.remove_rule('FORWARD', '-s 1.2.3.4/5 -j DROP')
new_lines = self.manager._modify_rules(current_lines, table, 'filter')
- self.assertTrue('[0:0] -A %s-FORWARD '
- '-s 1.2.3.4/5 -j DROP' % self.binary_name
- not in new_lines)
+ self.assertNotIn('[0:0] -A %s-FORWARD '
+ '-s 1.2.3.4/5 -j DROP' % self.binary_name, new_lines)
def test_remove_rules_regex(self):
current_lines = self.sample_nat
View
@@ -338,20 +338,20 @@ def test_monkey_patch(self):
self.assertEqual(ret_b, 8)
package_a = self.example_package + 'example_a.'
- self.assertTrue(package_a + 'example_function_a'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertIn(package_a + 'example_function_a',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
- self.assertTrue(package_a + 'ExampleClassA.example_method'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
- self.assertTrue(package_a + 'ExampleClassA.example_method_add'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertIn(package_a + 'ExampleClassA.example_method',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertIn(package_a + 'ExampleClassA.example_method_add',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
package_b = self.example_package + 'example_b.'
- self.assertFalse(package_b + 'example_function_b'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
- self.assertFalse(package_b + 'ExampleClassB.example_method'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
- self.assertFalse(package_b + 'ExampleClassB.example_method_add'
- in nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertNotIn(package_b + 'example_function_b',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertNotIn(package_b + 'ExampleClassB.example_method',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
+ self.assertNotIn(package_b + 'ExampleClassB.example_method_add',
+ nova.tests.monkey_patch_example.CALLED_FUNCTION)
class MonkeyPatchDefaultTestCase(test.NoDBTestCase):
@@ -7763,7 +7763,7 @@ def fake_baselineCPU(cpu, flag):
conn.post_live_migration_at_destination(self.context, instance,
network_info, True,
block_device_info=block_device_info)
- self.assertTrue('fake' in self.resultXML)
+ self.assertIn('fake', self.resultXML)
self.assertTrue(
block_device_info['block_device_mapping'][0].save.called)
@@ -802,8 +802,7 @@ def test_exception_msg_contains_vm_name(self):
try:
vm_utils.vm_ref_or_raise('session', 'somename')
except exception.InstanceNotFound as e:
- self.assertTrue(
- 'somename' in str(e))
+ self.assertIn('somename', str(e))
mock.VerifyAll()

0 comments on commit 301f690

Please sign in to comment.