Replace stubout with fixtures

blueprint remove-mox

The last step in removing mox is to remove stubout usage. Lucky for us,
the fixtures library, which we are already using, can take on the
challenge quite well.

Change-Id: Id33cc8988935a1905f9a14351964f0bb24ef82e3
This commit is contained in:
Monty Taylor 2013-11-11 04:30:54 -05:00
parent 01a30c78b5
commit ccc086f374
7 changed files with 20 additions and 45 deletions

View File

@ -19,8 +19,6 @@
Neutron base exception handling.
"""
_FATAL_EXCEPTION_FORMAT_ERRORS = False
class NeutronException(Exception):
"""Base Neutron Exception.
@ -36,7 +34,7 @@ class NeutronException(Exception):
super(NeutronException, self).__init__(self.message % kwargs)
self.msg = self.message % kwargs
except Exception:
if _FATAL_EXCEPTION_FORMAT_ERRORS:
if self.use_fatal_exceptions():
raise
else:
# at least get the core message out if something happened
@ -45,6 +43,9 @@ class NeutronException(Exception):
def __unicode__(self):
return unicode(self.msg)
def use_fatal_exceptions(self):
return False
class BadRequest(NeutronException):
message = _('Bad %(resource)s request: %(msg)s')

View File

@ -24,17 +24,18 @@ import os
import eventlet.timeout
import fixtures
from oslo.config import cfg
import stubout
import testtools
from neutron.common import exceptions
CONF = cfg.CONF
TRUE_STRING = ['True', '1']
LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
def fake_use_fatal_exceptions(*args):
return True
class BaseTestCase(testtools.TestCase):
def setUp(self):
@ -72,8 +73,9 @@ class BaseTestCase(testtools.TestCase):
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING:
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(exceptions, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
self.useFixture(fixtures.MonkeyPatch(
'neutron.common.exceptions.NeutronException.use_fatal_exceptions',
fake_use_fatal_exceptions))
def config(self, **kw):
"""Override some configuration values.

View File

@ -18,13 +18,12 @@
Unit Tests for linuxbridge rpc
"""
import fixtures
from oslo.config import cfg
import stubout
from neutron.agent import rpc as agent_rpc
from neutron.common import topics
from neutron.openstack.common import context
from neutron.openstack.common import rpc
from neutron.plugins.linuxbridge import lb_neutron_plugin as plb
from neutron.tests import base
@ -49,8 +48,8 @@ class rpcApiTestCase(base.BaseTestCase):
if expected_retval:
return expected_retval
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
self.useFixture(fixtures.MonkeyPatch(
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
retval = getattr(rpcapi, method)(ctxt, **kwargs)

View File

@ -19,13 +19,12 @@
Unit Tests for Mellanox RPC (major reuse of linuxbridge rpc unit tests)
"""
import fixtures
from oslo.config import cfg
import stubout
from neutron.agent import rpc as agent_rpc
from neutron.common import topics
from neutron.openstack.common import context
from neutron.openstack.common import rpc
from neutron.plugins.mlnx import agent_notify_api
from neutron.tests import base
@ -51,8 +50,8 @@ class rpcApiTestCase(base.BaseTestCase):
if expected_retval:
return expected_retval
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
self.useFixture(fixtures.MonkeyPatch(
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
retval = getattr(rpcapi, method)(ctxt, **kwargs)

View File

@ -18,12 +18,11 @@
Unit Tests for openvswitch rpc
"""
import stubout
import fixtures
from neutron.agent import rpc as agent_rpc
from neutron.common import topics
from neutron.openstack.common import context
from neutron.openstack.common import rpc
from neutron.plugins.openvswitch.common import constants
from neutron.plugins.openvswitch import ovs_neutron_plugin as povs
from neutron.tests import base
@ -48,8 +47,8 @@ class rpcApiTestCase(base.BaseTestCase):
if expected_retval:
return expected_retval
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
self.useFixture(fixtures.MonkeyPatch(
'neutron.openstack.common.rpc.' + rpc_method, _fake_rpc_method))
retval = getattr(rpcapi, method)(ctxt, **kwargs)

View File

@ -18,9 +18,6 @@
# @author: Salvatore Orlando, Nicira, Inc
#
import stubout
import fixtures
import mock
from oslo.config import cfg
from webob import exc
@ -49,25 +46,6 @@ FAKE_ROUTER_PORT_ID = _uuid()
FAKE_ROUTER_PORT_MAC = 'bb:bb:bb:bb:bb:bb'
class StuboutFixture(fixtures.Fixture):
"""Setup stubout and add unsetAll to cleanup."""
def setUp(self):
super(StuboutFixture, self).setUp()
self.stubs = stubout.StubOutForTesting()
self.addCleanup(self.stubs.UnsetAll)
self.addCleanup(self.stubs.SmartUnsetAll)
def stubout_floating_ip_calls(stubs, fake_count=0):
def get_floatingips_count(_1, _2, filters):
return fake_count
stubs.Set(l3_db.L3_NAT_db_mixin, 'get_floatingips_count',
get_floatingips_count)
class TestExtensionManager(object):
def get_resources(self):
@ -104,8 +82,6 @@ class TestL3GwModeMixin(base.BaseTestCase):
def setUp(self):
super(TestL3GwModeMixin, self).setUp()
stubout_fixture = self.useFixture(StuboutFixture())
self.stubs = stubout_fixture.stubs
self.target_object = TestDbIntPlugin()
# Patch the context
ctx_patcher = mock.patch('neutron.context', autospec=True)

View File

@ -5,7 +5,6 @@ coverage>=3.6
discover
fixtures>=0.3.14
mock>=1.0
mox>=0.5.3
python-subunit
sphinx>=1.1.2
testrepository>=0.0.17