From 8a82233b55b61e4c2ebcb7dd9fdd597d98ee0684 Mon Sep 17 00:00:00 2001 From: Jianquan Ye Date: Tue, 17 Dec 2024 13:22:23 +1000 Subject: [PATCH] Add test cases --- tests/test_rfc2737.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/test_rfc2737.py b/tests/test_rfc2737.py index afd96b6df..079e5ef28 100644 --- a/tests/test_rfc2737.py +++ b/tests/test_rfc2737.py @@ -24,14 +24,16 @@ class TestPhysicalTableMIBUpdater(TestCase): def test_PhysicalTableMIBUpdater_exception_in_reinit_data_wont_block_reinit_iteration_first(self, mock_xcvr_reinit_data): updater = PhysicalTableMIBUpdater() - with (pytest.raises(Exception) as excinfo, - mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.XcvrCacheUpdater.reinit_data') as mocked_xcvr_reinit_data, + with (mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.XcvrCacheUpdater.reinit_data') as mocked_xcvr_reinit_data, mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.PsuCacheUpdater.reinit_data') as mocked_psu_reinit_data, mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.FanDrawerCacheUpdater.reinit_data') as mocked_fan_drawer_reinit_data, mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.FanCacheUpdater.reinit_data') as mocked_fan_cache_reinit_data, mock.patch('sonic_ax_impl.mibs.ietf.rfc2737.ThermalCacheUpdater.reinit_data') as mocked_thermal_reinit_data, mock.patch('sonic_ax_impl.mibs.cancel_redis_pubsub') as mocked_cancel_redis_pubsub): - updater.reinit_data() + + with pytest.raises(Exception) as excinfo: + updater.reinit_data() + assert str(excinfo.value) == "mocked error" mocked_xcvr_reinit_data.assert_called() mocked_psu_reinit_data.assert_called() @@ -81,13 +83,13 @@ def test_PhysicalTableMIBUpdater_runtime_exc_in_reinit_data_wont_block_reinit_it 'sonic_ax_impl.mibs.ietf.rfc2737.ThermalCacheUpdater.reinit_data') as mocked_thermal_reinit_data, mock.patch('sonic_ax_impl.mibs.cancel_redis_pubsub') as mocked_cancel_redis_pubsub): updater.reinit_data() - assert str(excinfo.value) == "mocked runtime error" - mocked_xcvr_reinit_data.assert_called() - mocked_psu_reinit_data.assert_called() - mocked_fan_drawer_reinit_data.assert_called() - mocked_fan_cache_reinit_data.assert_called() - mocked_thermal_reinit_data.assert_called() - mocked_cancel_redis_pubsub.assert_called() + assert str(excinfo.value) == "mocked runtime error" + mocked_xcvr_reinit_data.assert_called() + mocked_psu_reinit_data.assert_called() + mocked_fan_drawer_reinit_data.assert_called() + mocked_fan_cache_reinit_data.assert_called() + mocked_thermal_reinit_data.assert_called() + mocked_cancel_redis_pubsub.assert_called() # Given: 5 physical updaters are register into reinit of PhysicalTableMIBUpdater # When: The last updater(XcvrCacheUpdater) raises Runtime exception in the reinit