Merge "Replace mox with mock in publisher and pipeline"
This commit is contained in:
commit
631c1fd560
@ -24,7 +24,6 @@ import mock
|
|||||||
import msgpack
|
import msgpack
|
||||||
|
|
||||||
from ceilometer.openstack.common.fixture import config
|
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 network_utils
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
from ceilometer.publisher import udp
|
from ceilometer.publisher import udp
|
||||||
@ -103,15 +102,13 @@ class TestUDPPublisher(test.BaseTestCase):
|
|||||||
def _fake_socket_socket(family, type):
|
def _fake_socket_socket(family, type):
|
||||||
def record_data(msg, dest):
|
def record_data(msg, dest):
|
||||||
published.append((msg, dest))
|
published.append((msg, dest))
|
||||||
udp_socket = self.mox.CreateMockAnything()
|
udp_socket = mock.Mock()
|
||||||
udp_socket.sendto = record_data
|
udp_socket.sendto = record_data
|
||||||
self.mox.ReplayAll()
|
|
||||||
return udp_socket
|
return udp_socket
|
||||||
return _fake_socket_socket
|
return _fake_socket_socket
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestUDPPublisher, self).setUp()
|
super(TestUDPPublisher, self).setUp()
|
||||||
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
|
|
||||||
self.CONF = self.useFixture(config.Config()).conf
|
self.CONF = self.useFixture(config.Config()).conf
|
||||||
|
|
||||||
def test_published(self):
|
def test_published(self):
|
||||||
@ -140,13 +137,13 @@ class TestUDPPublisher(test.BaseTestCase):
|
|||||||
sorted([dict(d.as_dict()) for d in self.test_data]))
|
sorted([dict(d.as_dict()) for d in self.test_data]))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _raise_ioerror():
|
def _raise_ioerror(*args):
|
||||||
raise IOError
|
raise IOError
|
||||||
|
|
||||||
def _make_broken_socket(self, family, type):
|
def _make_broken_socket(self, family, type):
|
||||||
udp_socket = self.mox.CreateMockAnything()
|
udp_socket = mock.Mock()
|
||||||
udp_socket.sendto = self._raise_ioerror
|
udp_socket.sendto = self._raise_ioerror
|
||||||
self.mox.ReplayAll()
|
return udp_socket
|
||||||
|
|
||||||
def test_publish_error(self):
|
def test_publish_error(self):
|
||||||
with mock.patch('socket.socket',
|
with mock.patch('socket.socket',
|
||||||
|
@ -21,7 +21,7 @@ import datetime
|
|||||||
|
|
||||||
from stevedore import extension
|
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 test
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer import pipeline
|
from ceilometer import pipeline
|
||||||
@ -149,16 +149,16 @@ class TestPipeline(test.BaseTestCase):
|
|||||||
resource_metadata={}
|
resource_metadata={}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
self.useFixture(mockpatch.PatchObject(
|
||||||
self.stubs.Set(transformer.TransformerExtensionManager,
|
transformer.TransformerExtensionManager, "__init__",
|
||||||
"__init__",
|
side_effect=self.fake_tem_init))
|
||||||
self.fake_tem_init)
|
|
||||||
|
|
||||||
self.stubs.Set(transformer.TransformerExtensionManager,
|
self.useFixture(mockpatch.PatchObject(
|
||||||
"get_ext",
|
transformer.TransformerExtensionManager, "get_ext",
|
||||||
self.fake_tem_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()
|
self.transformer_manager = transformer.TransformerExtensionManager()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user