From fbe032345fab21a73269dcf3112aa7ae65f27d48 Mon Sep 17 00:00:00 2001 From: Dao Cong Tien Date: Fri, 19 Aug 2016 14:25:35 +0700 Subject: [PATCH] Stop using mox in unit/*.py tests (1/2) As mox is not compatible with python 3, all test cases that use mox should be updated to use mock instead. Replaced stubs.Set() with mock_object() in some classes in cinder/tests/unit/*.py. Change-Id: I623b3b4bd27efc8e302e6bace011f9d807c2c64f --- cinder/test.py | 2 +- cinder/tests/unit/fake_notifier.py | 11 ++++++----- cinder/tests/unit/test_coprhd.py | 24 ++++++++++++------------ cinder/tests/unit/test_falconstor_fss.py | 2 +- cinder/tests/unit/test_volume_rpcapi.py | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cinder/test.py b/cinder/test.py index a10ce7b6584..f481587f3ca 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -187,7 +187,7 @@ class TestCase(testtools.TestCase): self.injected = [] self._services = [] - fake_notifier.stub_notifier(self.stubs) + fake_notifier.mock_notifier(self) self.override_config('fatal_exception_format_errors', True) # This will be cleaned up by the NestedTempfile fixture diff --git a/cinder/tests/unit/fake_notifier.py b/cinder/tests/unit/fake_notifier.py index 87eb9773142..45b1493a45d 100644 --- a/cinder/tests/unit/fake_notifier.py +++ b/cinder/tests/unit/fake_notifier.py @@ -64,13 +64,14 @@ class FakeNotifier(object): del self.notifications[:] -def stub_notifier(stubs): - stubs.Set(messaging, 'Notifier', FakeNotifier) +def mock_notifier(testcase): + testcase.mock_object(messaging, 'Notifier', FakeNotifier) if rpc.NOTIFIER: serializer = getattr(rpc.NOTIFIER, '_serializer', None) - stubs.Set(rpc, 'NOTIFIER', FakeNotifier(rpc.NOTIFIER.transport, - rpc.NOTIFIER.publisher_id, - serializer=serializer)) + testcase.mock_object(rpc, 'NOTIFIER', + FakeNotifier(rpc.NOTIFIER.transport, + rpc.NOTIFIER.publisher_id, + serializer=serializer)) def get_fake_notifier(service=None, host=None, publisher_id=None): diff --git a/cinder/tests/unit/test_coprhd.py b/cinder/tests/unit/test_coprhd.py index 556c39d32c7..eb1f3ac6f43 100644 --- a/cinder/tests/unit/test_coprhd.py +++ b/cinder/tests/unit/test_coprhd.py @@ -397,9 +397,9 @@ class EMCCoprHDISCSIDriverTest(test.TestCase): self.volume_type_id = self.create_coprhd_volume_type() - self.stubs.Set(coprhd_iscsi.EMCCoprHDISCSIDriver, - '_get_common_driver', - self._get_mocked_common_driver) + self.mock_object(coprhd_iscsi.EMCCoprHDISCSIDriver, + '_get_common_driver', + self._get_mocked_common_driver) self.driver = coprhd_iscsi.EMCCoprHDISCSIDriver( configuration=self.configuration) @@ -564,9 +564,9 @@ class EMCCoprHDFCDriverTest(test.TestCase): self.volume_type_id = self.create_coprhd_volume_type() - self.stubs.Set(coprhd_fc.EMCCoprHDFCDriver, - '_get_common_driver', - self._get_mocked_common_driver) + self.mock_object(coprhd_fc.EMCCoprHDFCDriver, + '_get_common_driver', + self._get_mocked_common_driver) self.driver = coprhd_fc.EMCCoprHDFCDriver( configuration=self.configuration) @@ -760,12 +760,12 @@ class EMCCoprHDScaleIODriverTest(test.TestCase): self.volume_type_id = self.create_coprhd_volume_type() - self.stubs.Set(coprhd_scaleio.EMCCoprHDScaleIODriver, - '_get_common_driver', - self._get_mocked_common_driver) - self.stubs.Set(coprhd_scaleio.EMCCoprHDScaleIODriver, - '_get_client_id', - self._get_client_id) + self.mock_object(coprhd_scaleio.EMCCoprHDScaleIODriver, + '_get_common_driver', + self._get_mocked_common_driver) + self.mock_object(coprhd_scaleio.EMCCoprHDScaleIODriver, + '_get_client_id', + self._get_client_id) self.driver = coprhd_scaleio.EMCCoprHDScaleIODriver( configuration=self.configuration) diff --git a/cinder/tests/unit/test_falconstor_fss.py b/cinder/tests/unit/test_falconstor_fss.py index ad72a0ffb29..7c04ca1f423 100644 --- a/cinder/tests/unit/test_falconstor_fss.py +++ b/cinder/tests/unit/test_falconstor_fss.py @@ -208,7 +208,7 @@ class FSSDriverTestCase(test.TestCase): self.mock_config.san_is_local = False self.mock_config.fss_debug = False self.mock_config.additional_retry_list = False - self.stubs.Set(time, 'sleep', Fake_sleep) + self.mock_object(time, 'sleep', Fake_sleep) class TestFSSISCSIDriver(FSSDriverTestCase): diff --git a/cinder/tests/unit/test_volume_rpcapi.py b/cinder/tests/unit/test_volume_rpcapi.py index 203c331259c..92a0f92c89c 100644 --- a/cinder/tests/unit/test_volume_rpcapi.py +++ b/cinder/tests/unit/test_volume_rpcapi.py @@ -188,8 +188,8 @@ class VolumeRpcAPITestCase(test.TestCase): if expected_retval: return expected_retval - self.stubs.Set(rpcapi.client, "prepare", _fake_prepare_method) - self.stubs.Set(rpcapi.client, rpc_method, _fake_rpc_method) + self.mock_object(rpcapi.client, "prepare", _fake_prepare_method) + self.mock_object(rpcapi.client, rpc_method, _fake_rpc_method) retval = getattr(rpcapi, method)(ctxt, **kwargs)