From 6c4bdc43d931bf38f7d9daad6fccc8c767378d5e Mon Sep 17 00:00:00 2001 From: Zhiqiang Fan Date: Mon, 28 Sep 2015 02:06:54 -0600 Subject: [PATCH] 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 --- heat/tests/api/openstack_v1/test_stacks.py | 2 +- heat/tests/db/test_sqlalchemy_api.py | 8 ++++---- heat/tests/test_stack_lock.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/heat/tests/api/openstack_v1/test_stacks.py b/heat/tests/api/openstack_v1/test_stacks.py index a98c55ef34..7f365ec8e0 100644 --- a/heat/tests/api/openstack_v1/test_stacks.py +++ b/heat/tests/api/openstack_v1/test_stacks.py @@ -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) diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py index fd51b829f3..b30c27fb51 100644 --- a/heat/tests/db/test_sqlalchemy_api.py +++ b/heat/tests/db/test_sqlalchemy_api.py @@ -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, diff --git a/heat/tests/test_stack_lock.py b/heat/tests/test_stack_lock.py index cccb793996..3b33f654f3 100644 --- a/heat/tests/test_stack_lock.py +++ b/heat/tests/test_stack_lock.py @@ -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)