Use the oslo fixture module
The oslo fixture import has been imported And the tests code have been updated to use this new module Change-Id: I3454440770402c028f49a92c6728d7bbad0c9aa0
This commit is contained in:
parent
5ccf8c4e5f
commit
b035359952
|
@ -0,0 +1,45 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
#
|
||||
# Copyright 2013 Mirantis, Inc.
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
class Config(fixtures.Fixture):
|
||||
"""Override some configuration values.
|
||||
|
||||
The keyword arguments are the names of configuration options to
|
||||
override and their values.
|
||||
|
||||
If a group argument is supplied, the overrides are applied to
|
||||
the specified configuration option group.
|
||||
|
||||
All overrides are automatically cleared at the end of the current
|
||||
test by the reset() method, which is registred by addCleanup().
|
||||
"""
|
||||
|
||||
def __init__(self, conf=cfg.CONF):
|
||||
self.conf = conf
|
||||
|
||||
def setUp(self):
|
||||
super(Config, self).setUp()
|
||||
self.addCleanup(self.conf.reset)
|
||||
|
||||
def config(self, **kw):
|
||||
group = kw.pop('group', None)
|
||||
for k, v in kw.iteritems():
|
||||
self.conf.set_override(k, v, group)
|
|
@ -0,0 +1,51 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
|
||||
|
||||
class PatchObject(fixtures.Fixture):
|
||||
"""Deal with code around mock."""
|
||||
|
||||
def __init__(self, obj, attr, **kwargs):
|
||||
self.obj = obj
|
||||
self.attr = attr
|
||||
self.kwargs = kwargs
|
||||
|
||||
def setUp(self):
|
||||
super(PatchObject, self).setUp()
|
||||
_p = mock.patch.object(self.obj, self.attr, **self.kwargs)
|
||||
self.mock = _p.start()
|
||||
self.addCleanup(_p.stop)
|
||||
|
||||
|
||||
class Patch(fixtures.Fixture):
|
||||
|
||||
"""Deal with code around mock.patch."""
|
||||
|
||||
def __init__(self, obj, **kwargs):
|
||||
self.obj = obj
|
||||
self.kwargs = kwargs
|
||||
|
||||
def setUp(self):
|
||||
super(Patch, self).setUp()
|
||||
_p = mock.patch(self.obj, **self.kwargs)
|
||||
self.mock = _p.start()
|
||||
self.addCleanup(_p.stop)
|
|
@ -0,0 +1,37 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
import mox
|
||||
import stubout
|
||||
|
||||
|
||||
class MoxStubout(fixtures.Fixture):
|
||||
"""Deal with code around mox and stubout as a fixture."""
|
||||
|
||||
def setUp(self):
|
||||
super(MoxStubout, self).setUp()
|
||||
# emulate some of the mox stuff, we can't use the metaclass
|
||||
# because it screws with our generators
|
||||
self.mox = mox.Mox()
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
self.addCleanup(self.mox.UnsetStubs)
|
||||
self.addCleanup(self.stubs.UnsetAll)
|
||||
self.addCleanup(self.stubs.SmartUnsetAll)
|
||||
self.addCleanup(self.mox.VerifyAll)
|
20
nova/test.py
20
nova/test.py
|
@ -35,9 +35,7 @@ import tempfile
|
|||
import uuid
|
||||
|
||||
import fixtures
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
import stubout
|
||||
import testtools
|
||||
|
||||
from nova import context
|
||||
|
@ -46,6 +44,7 @@ from nova.db import migration
|
|||
from nova.network import manager as network_manager
|
||||
from nova.objects import base as objects_base
|
||||
from nova.openstack.common.db.sqlalchemy import session
|
||||
from nova.openstack.common.fixture import moxstubout
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import paths
|
||||
|
@ -177,21 +176,6 @@ class ServiceFixture(fixtures.Fixture):
|
|||
self.addCleanup(self.service.kill)
|
||||
|
||||
|
||||
class MoxStubout(fixtures.Fixture):
|
||||
"""Deal with code around mox and stubout as a fixture."""
|
||||
|
||||
def setUp(self):
|
||||
super(MoxStubout, self).setUp()
|
||||
# emulate some of the mox stuff, we can't use the metaclass
|
||||
# because it screws with our generators
|
||||
self.mox = mox.Mox()
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
self.addCleanup(self.stubs.UnsetAll)
|
||||
self.addCleanup(self.stubs.SmartUnsetAll)
|
||||
self.addCleanup(self.mox.UnsetStubs)
|
||||
self.addCleanup(self.mox.VerifyAll)
|
||||
|
||||
|
||||
class TranslationFixture(fixtures.Fixture):
|
||||
"""Use gettext NullTranslation objects in tests."""
|
||||
|
||||
|
@ -260,7 +244,7 @@ class TestCase(testtools.TestCase):
|
|||
objects_base.NovaObject._obj_classes)
|
||||
self.addCleanup(self._restore_obj_registry)
|
||||
|
||||
mox_fixture = self.useFixture(MoxStubout())
|
||||
mox_fixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.mox = mox_fixture.mox
|
||||
self.stubs = mox_fixture.stubs
|
||||
self.addCleanup(self._clear_attrs)
|
||||
|
|
|
@ -21,9 +21,8 @@ from lxml import etree
|
|||
from nova.api.openstack.compute.contrib import migrations
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.openstack.common.fixture import moxstubout
|
||||
from nova import test
|
||||
from nova.test import MoxStubout
|
||||
|
||||
|
||||
fake_migrations = [
|
||||
{
|
||||
|
@ -70,7 +69,7 @@ class MigrationsTestCase(test.NoDBTestCase):
|
|||
self.context = context.get_admin_context()
|
||||
self.req = FakeRequest()
|
||||
self.req.environ['nova.context'] = self.context
|
||||
mox_fixture = self.useFixture(MoxStubout())
|
||||
mox_fixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.mox = mox_fixture.mox
|
||||
|
||||
def test_index(self):
|
||||
|
|
|
@ -21,8 +21,8 @@ from lxml import etree
|
|||
from nova.api.openstack.compute.plugins.v3 import migrations
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.openstack.common.fixture import moxstubout
|
||||
from nova import test
|
||||
from nova.test import MoxStubout
|
||||
|
||||
|
||||
fake_migrations = [
|
||||
|
@ -70,7 +70,7 @@ class MigrationsTestCase(test.NoDBTestCase):
|
|||
self.context = context.get_admin_context()
|
||||
self.req = FakeRequest()
|
||||
self.req.environ['nova.context'] = self.context
|
||||
mox_fixture = self.useFixture(MoxStubout())
|
||||
mox_fixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.mox = mox_fixture.mox
|
||||
|
||||
def test_index(self):
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
from nova import config
|
||||
from nova import ipv6
|
||||
from nova.openstack.common.fixture import config as config_fixture
|
||||
from nova import paths
|
||||
from nova.tests import utils
|
||||
|
||||
|
@ -38,15 +39,10 @@ CONF.import_opt('compute_driver', 'nova.virt.driver')
|
|||
CONF.import_opt('api_paste_config', 'nova.wsgi')
|
||||
|
||||
|
||||
class ConfFixture(fixtures.Fixture):
|
||||
class ConfFixture(config_fixture.Config):
|
||||
"""Fixture to manage global conf settings."""
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
def setUp(self):
|
||||
super(ConfFixture, self).setUp()
|
||||
|
||||
self.conf.set_default('api_paste_config',
|
||||
paths.state_path_def('etc/nova/api-paste.ini'))
|
||||
self.conf.set_default('host', 'fake-mini')
|
||||
|
@ -70,6 +66,5 @@ class ConfFixture(fixtures.Fixture):
|
|||
self.conf.set_default('verbose', True)
|
||||
self.conf.set_default('vlan_interface', 'eth0')
|
||||
config.parse_args([], default_config_files=[])
|
||||
self.addCleanup(self.conf.reset)
|
||||
self.addCleanup(utils.cleanup_dns_managers)
|
||||
self.addCleanup(ipv6.api.reset_backend)
|
||||
|
|
|
@ -9,6 +9,7 @@ module=db.sqlalchemy
|
|||
module=eventlet_backdoor
|
||||
module=excutils
|
||||
module=fileutils
|
||||
module=fixture
|
||||
module=flakes
|
||||
module=gettextutils
|
||||
module=importutils
|
||||
|
|
Loading…
Reference in New Issue