replace assert statement with unittest.assertXXX
There are two concerns to do this: * assert statement will not be executed when running under optimized mode (even though we don't really do this currently) * unittest.assertXXX provides more detailed message when test fail, for example, assert count == 2 will only have AssertionError, but unittest.assertXXX can tell you the test fail because 1 != 2 This patch replaces assert statement with unittest.assertXXX in our test code. Note, not all assert statements are replaced because some of them are not aiming at the test result. Change-Id: Ida44bf6876e6fa60a4d8213f1cdad6edefb34cab Closes-Bug: #1397883
This commit is contained in:
parent
2df093b75e
commit
6c4bdc43d9
@ -391,7 +391,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
|
||||
|
||||
result = self.controller.index(req, tenant_id=self.tenant)
|
||||
self.assertNotIn('count', result)
|
||||
assert not engine.count_stacks.called
|
||||
self.assertFalse(engine.count_stacks.called)
|
||||
|
||||
def test_index_with_count_is_invalid(self, mock_enforce):
|
||||
self._mock_enforce_setup(mock_enforce, 'index', True)
|
||||
|
@ -144,14 +144,14 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
query = mock.Mock()
|
||||
db_api._filter_and_page_query(self.ctx, query)
|
||||
|
||||
assert mock_paginate_query.called
|
||||
self.assertTrue(mock_paginate_query.called)
|
||||
|
||||
@mock.patch.object(db_api, '_events_paginate_query')
|
||||
def test_events_filter_and_page_query(self, mock_events_paginate_query):
|
||||
query = mock.Mock()
|
||||
db_api._events_filter_and_page_query(self.ctx, query)
|
||||
|
||||
assert mock_events_paginate_query.called
|
||||
self.assertTrue(mock_events_paginate_query.called)
|
||||
|
||||
@mock.patch.object(db_api.db_filters, 'exact_filter')
|
||||
def test_filter_and_page_query_handles_no_filters(self, mock_db_filter):
|
||||
@ -174,7 +174,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
filters = {'foo': 'bar'}
|
||||
db_api._filter_and_page_query(self.ctx, query, filters=filters)
|
||||
|
||||
assert mock_db_filter.called
|
||||
self.assertTrue(mock_db_filter.called)
|
||||
|
||||
@mock.patch.object(db_api.db_filters, 'exact_filter')
|
||||
def test_events_filter_and_page_query_applies_filters(self,
|
||||
@ -183,7 +183,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
filters = {'foo': 'bar'}
|
||||
db_api._events_filter_and_page_query(self.ctx, query, filters=filters)
|
||||
|
||||
assert mock_db_filter.called
|
||||
self.assertTrue(mock_db_filter.called)
|
||||
|
||||
@mock.patch.object(db_api, '_paginate_query')
|
||||
def test_filter_and_page_query_whitelists_sort_keys(self,
|
||||
|
@ -168,7 +168,7 @@ class StackLockTest(common.HeatTestCase):
|
||||
stack_lock_object.StackLock.create.call_count)
|
||||
raise exception.ActionInProgress
|
||||
self.assertRaises(exception.ActionInProgress, check_thread_lock)
|
||||
assert not stack_lock_object.StackLock.release.called
|
||||
self.assertFalse(stack_lock_object.StackLock.release.called)
|
||||
|
||||
def test_thread_lock_context_mgr_no_exception(self):
|
||||
stack_lock_object.StackLock.create = mock.Mock(return_value=None)
|
||||
@ -177,7 +177,7 @@ class StackLockTest(common.HeatTestCase):
|
||||
self.engine_id)
|
||||
with slock.thread_lock():
|
||||
self.assertEqual(1, stack_lock_object.StackLock.create.call_count)
|
||||
assert not stack_lock_object.StackLock.release.called
|
||||
self.assertFalse(stack_lock_object.StackLock.release.called)
|
||||
|
||||
def test_try_thread_lock_context_mgr_exception(self):
|
||||
stack_lock_object.StackLock.create = mock.Mock(return_value=None)
|
||||
@ -200,7 +200,7 @@ class StackLockTest(common.HeatTestCase):
|
||||
self.engine_id)
|
||||
with slock.try_thread_lock():
|
||||
self.assertEqual(1, stack_lock_object.StackLock.create.call_count)
|
||||
assert not stack_lock_object.StackLock.release.called
|
||||
self.assertFalse(stack_lock_object.StackLock.release.called)
|
||||
|
||||
def test_try_thread_lock_context_mgr_existing_lock(self):
|
||||
stack_lock_object.StackLock.create = mock.Mock(return_value=1234)
|
||||
@ -214,4 +214,4 @@ class StackLockTest(common.HeatTestCase):
|
||||
stack_lock_object.StackLock.create.call_count)
|
||||
raise self.TestThreadLockException
|
||||
self.assertRaises(self.TestThreadLockException, check_thread_lock)
|
||||
assert not stack_lock_object.StackLock.release.called
|
||||
self.assertFalse(stack_lock_object.StackLock.release.called)
|
||||
|
Loading…
Reference in New Issue
Block a user