From e1ff079f01a391bdbc6a2ddab8aae2ea2eb9a42f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Nov 2013 18:59:59 +0100 Subject: [PATCH] Replace mox with mock in publisher and pipeline Replace mox with mock in tests.publisher and tests.test_pipeline Change-Id: I3ec2d16bb586c4265cb65414a9b5647832d903f2 --- ceilometer/tests/publisher/test_udp.py | 11 ++++------- ceilometer/tests/test_pipeline.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ceilometer/tests/publisher/test_udp.py b/ceilometer/tests/publisher/test_udp.py index 9006d293a..c094cb7a8 100644 --- a/ceilometer/tests/publisher/test_udp.py +++ b/ceilometer/tests/publisher/test_udp.py @@ -24,7 +24,6 @@ import mock import msgpack from ceilometer.openstack.common.fixture import config -from ceilometer.openstack.common.fixture import moxstubout from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import test from ceilometer.publisher import udp @@ -103,15 +102,13 @@ class TestUDPPublisher(test.BaseTestCase): def _fake_socket_socket(family, type): def record_data(msg, dest): published.append((msg, dest)) - udp_socket = self.mox.CreateMockAnything() + udp_socket = mock.Mock() udp_socket.sendto = record_data - self.mox.ReplayAll() return udp_socket return _fake_socket_socket def setUp(self): super(TestUDPPublisher, self).setUp() - self.mox = self.useFixture(moxstubout.MoxStubout()).mox self.CONF = self.useFixture(config.Config()).conf def test_published(self): @@ -140,13 +137,13 @@ class TestUDPPublisher(test.BaseTestCase): sorted([dict(d.as_dict()) for d in self.test_data])) @staticmethod - def _raise_ioerror(): + def _raise_ioerror(*args): raise IOError def _make_broken_socket(self, family, type): - udp_socket = self.mox.CreateMockAnything() + udp_socket = mock.Mock() udp_socket.sendto = self._raise_ioerror - self.mox.ReplayAll() + return udp_socket def test_publish_error(self): with mock.patch('socket.socket', diff --git a/ceilometer/tests/test_pipeline.py b/ceilometer/tests/test_pipeline.py index 8aa57a763..ccdd2f7cc 100644 --- a/ceilometer/tests/test_pipeline.py +++ b/ceilometer/tests/test_pipeline.py @@ -21,7 +21,7 @@ import datetime from stevedore import extension -from ceilometer.openstack.common.fixture import moxstubout +from ceilometer.openstack.common.fixture import mockpatch from ceilometer.openstack.common import test from ceilometer.openstack.common import timeutils from ceilometer import pipeline @@ -149,16 +149,16 @@ class TestPipeline(test.BaseTestCase): resource_metadata={} ) - self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs - self.stubs.Set(transformer.TransformerExtensionManager, - "__init__", - self.fake_tem_init) + self.useFixture(mockpatch.PatchObject( + transformer.TransformerExtensionManager, "__init__", + side_effect=self.fake_tem_init)) - self.stubs.Set(transformer.TransformerExtensionManager, - "get_ext", - self.fake_tem_get_ext) + self.useFixture(mockpatch.PatchObject( + transformer.TransformerExtensionManager, "get_ext", + side_effect=self.fake_tem_get_ext)) - self.stubs.Set(publisher, 'get_publisher', self.get_publisher) + self.useFixture(mockpatch.PatchObject( + publisher, 'get_publisher', side_effect=self.get_publisher)) self.transformer_manager = transformer.TransformerExtensionManager()