Modify use of assertTrue(A in B)

Developers should use assertIn(A, B) instead of assertTrue(A in B ).

TrivialFix

Change-Id: I5d710cf78ba5550935bc8510c7d29d99e080871b
This commit is contained in:
Bin Zhou 2016-09-12 19:53:55 +08:00
parent cb5241703c
commit 1f7b06213e
9 changed files with 24 additions and 24 deletions

View File

@ -141,7 +141,7 @@ class TestClient(testtools.TestCase):
except glanceclient.exc.CommunicationError as comm_err:
fail_msg = ("Exception message '%s' should contain '%s'" %
(comm_err.message, self.endpoint))
self.assertTrue(self.endpoint in comm_err.message, fail_msg)
self.assertIn(self.endpoint, comm_err.message, fail_msg)
def test_http_encoding(self):
# Lets fake the response

View File

@ -554,7 +554,7 @@ class ImageManagerTest(testtools.TestCase):
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
self.assertTrue(msg in str(e))
self.assertIn(msg, str(e))
def test_data_req_id(self):
params = {
@ -897,7 +897,7 @@ class ImageTest(testtools.TestCase):
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
self.assertTrue(msg in str(e))
self.assertIn(msg, str(e))
def test_data_with_checksum(self):
image = self.mgr.get('3')
@ -959,5 +959,5 @@ class UrlParameterTest(testtools.TestCase):
shell.do_image_list(self.gc, FakeArg({"is_public": "True"}))
parts = parse.urlparse(self.api.url)
qs_dict = parse.parse_qs(parts.query)
self.assertTrue('is_public' in qs_dict)
self.assertIn('is_public', qs_dict)
self.assertTrue(qs_dict['is_public'][0].lower() == "true")

View File

@ -451,7 +451,7 @@ class ShellStdinHandlingTests(testtools.TestCase):
self._do_update('44d2c7e1-de4e-4612-8aa2-ba26610c444f')
self.assertTrue('data' in self.collected_args[1])
self.assertIn('data', self.collected_args[1])
self.assertIsInstance(self.collected_args[1]['data'], file_type)
self.assertEqual('Some Data',
self.collected_args[1]['data'].read())
@ -476,7 +476,7 @@ class ShellStdinHandlingTests(testtools.TestCase):
self._do_update('44d2c7e1-de4e-4612-8aa2-ba26610c444f')
self.assertTrue('data' in self.collected_args[1])
self.assertIn('data', self.collected_args[1])
self.assertIsInstance(self.collected_args[1]['data'], file_type)
self.assertEqual('Some Data\n',
self.collected_args[1]['data'].read())

View File

@ -821,7 +821,7 @@ class TestController(testtools.TestCase):
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
self.assertTrue(msg in str(e))
self.assertIn(msg, str(e))
def test_data_with_checksum(self):
body = self.controller.data('1b1c6366-dd57-11e1-af0f-02163e68b1d8',
@ -984,17 +984,17 @@ class TestController(testtools.TestCase):
e = self.assertRaises(exc.HTTPBadRequest,
self.controller.add_location,
image_id, url, meta)
self.assertTrue(estr in str(e))
self.assertIn(estr, str(e))
e = self.assertRaises(exc.HTTPBadRequest,
self.controller.delete_locations,
image_id, set([url]))
self.assertTrue(estr in str(e))
self.assertIn(estr, str(e))
e = self.assertRaises(exc.HTTPBadRequest,
self.controller.update_location,
image_id, url, meta)
self.assertTrue(estr in str(e))
self.assertIn(estr, str(e))
def _empty_get(self, image_id):
return ('GET', '/v2/images/%s' % image_id, {}, None)
@ -1047,7 +1047,7 @@ class TestController(testtools.TestCase):
err = self.assertRaises(exc.HTTPNotFound,
self.controller.delete_locations,
image_id, url_set)
self.assertTrue(err_str in str(err))
self.assertIn(err_str, str(err))
def test_update_location(self):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
@ -1090,4 +1090,4 @@ class TestController(testtools.TestCase):
err = self.assertRaises(exc.HTTPNotFound,
self.controller.update_location,
image_id, **new_loc)
self.assertTrue(err_str in str(err))
self.assertIn(err_str, str(err))

View File

@ -28,7 +28,7 @@ class MessageTests(test.TestCase):
req = self.request
string = "Giant ants are attacking San Francisco!"
expected = ["error", force_text(string), ""]
self.assertTrue("async_messages" in req.horizon)
self.assertIn("async_messages", req.horizon)
self.assertItemsEqual(req.horizon['async_messages'], [])
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
messages.error(req, string)
@ -42,7 +42,7 @@ class MessageTests(test.TestCase):
req = self.request
string = mark_safe("We are now safe from ants! Go <a>here</a>!")
expected = ["error", force_text(string), " safe"]
self.assertTrue("async_messages" in req.horizon)
self.assertIn("async_messages", req.horizon)
self.assertItemsEqual(req.horizon['async_messages'], [])
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
messages.error(req, string)

View File

@ -540,7 +540,7 @@ class DataTableTests(test.TestCase):
# Ensure data is not cached on the column across table instances
self.table = MyTable(self.request, TEST_DATA_2)
row = self.table.get_rows()[0]
self.assertTrue("down" in row.cells['status'].value)
self.assertIn("down", row.cells['status'].value)
def test_table_row(self):
self.table = MyTable(self.request, TEST_DATA)
@ -1289,7 +1289,7 @@ class DataTableTests(test.TestCase):
# Ensure data is not cached on the column across table instances
self.table = MyTable(self.request, TEST_DATA_6)
row = self.table.get_rows()[0]
self.assertTrue("down" in row.cells['status'].value)
self.assertIn("down", row.cells['status'].value)
def test_broken_filter(self):
class MyTableBrokenFilter(MyTable):

View File

@ -28,4 +28,4 @@ class ErrorPageTests(test.TestCase):
TEMPLATE_DIRS = (path.join(settings.ROOT_PATH, 'templates'),)
with self.settings(TEMPLATE_DIRS=TEMPLATE_DIRS):
response = self.client.get('/500/')
self.assertTrue('Server error' in response.content)
self.assertIn('Server error', response.content)

View File

@ -22,8 +22,8 @@ class PolicyBackendTestCase(test.TestCase):
policy_backend.reset()
enforcer = policy_backend._get_enforcer()
self.assertEqual(2, len(enforcer))
self.assertTrue('identity' in enforcer)
self.assertTrue('compute' in enforcer)
self.assertIn('identity', enforcer)
self.assertIn('compute', enforcer)
def test_policy_reset(self):
policy_backend._get_enforcer()

View File

@ -38,7 +38,7 @@ class TemplateRenderTest(test.TestCase):
template.Context(context))
self.assertFalse("&amp;" in out)
self.assertTrue("ENG Perf R&D" in out)
self.assertIn("ENG Perf R&D", out)
def test_openrc_html_evil_shell_escape(self):
context = {
@ -52,7 +52,7 @@ class TemplateRenderTest(test.TestCase):
template.Context(context))
self.assertFalse('o"' in out)
self.assertTrue('\"' in out)
self.assertIn('\"', out)
def test_openrc_html_evil_shell_backslash_escape(self):
context = {
@ -67,7 +67,7 @@ class TemplateRenderTest(test.TestCase):
self.assertFalse('o\"' in out)
self.assertFalse('o"' in out)
self.assertTrue('\\"' in out)
self.assertIn('\\"', out)
def test_openrc_set_region(self):
context = {
@ -81,7 +81,7 @@ class TemplateRenderTest(test.TestCase):
context,
template.Context(context))
self.assertTrue("OS_REGION_NAME=\"Colorado\"" in out)
self.assertIn("OS_REGION_NAME=\"Colorado\"", out)
def test_openrc_region_not_set(self):
context = {
@ -94,4 +94,4 @@ class TemplateRenderTest(test.TestCase):
context,
template.Context(context))
self.assertTrue("OS_REGION_NAME=\"\"" in out)
self.assertIn("OS_REGION_NAME=\"\"", out)