Remove already commented out and unused fixtures

Remove Service, Database and RPC fixtures, since we don't have services and
DB/RPC APIs to mock in this library. Remove unused configuration fixtures.

Change-Id: I3be004fa873baa06dae9e0fb55740b035581a85d
This commit is contained in:
Grzegorz Grasza 2015-02-19 14:53:28 +01:00
parent 0db953caf6
commit c5a73c44b4
4 changed files with 5 additions and 125 deletions

View File

@ -16,8 +16,7 @@
"""Base classes for our unit tests. """Base classes for our unit tests.
Allows overriding of flags for use of fakes, and some black magic for Some black magic for inline callbacks.
inline callbacks.
""" """
@ -33,32 +32,15 @@ from oslo_concurrency import lockutils
from oslo_config import cfg from oslo_config import cfg
from oslo_config import fixture as config_fixture from oslo_config import fixture as config_fixture
from oslo_log.fixture import logging_error from oslo_log.fixture import logging_error
import oslo_log.log as logging
from oslo_utils import timeutils from oslo_utils import timeutils
from oslotest import moxstubout from oslotest import moxstubout
import six import six
import testtools import testtools
from oslo_versionedobjects import _utils as utils
#from nova import db
#from nova.network import manager as network_manager
#from nova import objects
from oslo_versionedobjects.tests import obj_fixtures from oslo_versionedobjects.tests import obj_fixtures
CONF = cfg.CONF CONF = cfg.CONF
# CONF.import_opt('enabled', 'nova.api.openstack', group='osapi_v3')
# CONF.set_override('use_stderr', False)
logging.register_options(CONF)
logging.setup(CONF, 'versionedobjects')
# NOTE(comstud): Make sure we have all of the objects loaded. We do this
# at module import time, because we may be using mock decorators in our
# tests that run at import time.
# FIXME(dhellmann): We can't store library state in
# the application module.
# objects.register_all()
class TestingException(Exception): class TestingException(Exception):
@ -121,12 +103,7 @@ _patch_mock_to_raise_for_invalid_assert_calls()
class TestCase(testtools.TestCase): class TestCase(testtools.TestCase):
"""Test case base class for all unit tests. """Test case base class for all unit tests."""
Due to the slowness of DB access, please consider deriving from
`NoDBTestCase` first.
"""
USES_DB = True
REQUIRES_LOCKING = False REQUIRES_LOCKING = False
TIMEOUT_SCALING_FACTOR = 1 TIMEOUT_SCALING_FACTOR = 1
@ -165,21 +142,10 @@ class TestCase(testtools.TestCase):
self.fixture.config(lock_path=lock_path, self.fixture.config(lock_path=lock_path,
group='oslo_concurrency') group='oslo_concurrency')
# self.useFixture(config_fixture.ConfFixture(CONF))
# self.useFixture(obj_fixtures.RPCFixture('nova.test'))
# if self.USES_DB:
# self.useFixture(obj_fixtures.Database())
# NOTE(blk-u): WarningsFixture must be after the Database fixture # NOTE(blk-u): WarningsFixture must be after the Database fixture
# because sqlalchemy-migrate messes with the warnings filters. # because sqlalchemy-migrate messes with the warnings filters.
self.useFixture(obj_fixtures.WarningsFixture()) self.useFixture(obj_fixtures.WarningsFixture())
# NOTE(mnaser): All calls to utils.is_neutron() are cached in
# nova.utils._IS_NEUTRON. We set it to None to avoid any
# caching of that value.
utils._IS_NEUTRON = None
mox_fixture = self.useFixture(moxstubout.MoxStubout()) mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.mox = mox_fixture.mox self.mox = mox_fixture.mox
self.stubs = mox_fixture.stubs self.stubs = mox_fixture.stubs
@ -193,17 +159,6 @@ class TestCase(testtools.TestCase):
for key in [k for k in self.__dict__.keys() if k[0] != '_']: for key in [k for k in self.__dict__.keys() if k[0] != '_']:
del self.__dict__[key] del self.__dict__[key]
def flags(self, **kw):
"""Override flag variables for a test."""
group = kw.pop('group', None)
for k, v in kw.iteritems():
CONF.set_override(k, v, group)
def start_service(self, name, host=None, **kwargs):
svc = self.useFixture(
obj_fixtures.ServiceFixture(name, host, **kwargs))
return svc.service
def assertPublicAPISignatures(self, baseinst, inst): def assertPublicAPISignatures(self, baseinst, inst):
def get_public_apis(inst): def get_public_apis(inst):
methods = {} methods = {}
@ -259,15 +214,7 @@ class TimeOverride(fixtures.Fixture):
self.addCleanup(timeutils.clear_time_override) self.addCleanup(timeutils.clear_time_override)
class NoDBTestCase(TestCase): class BaseHookTestCase(TestCase):
"""`NoDBTestCase` differs from TestCase in that DB access is not supported.
This makes tests run significantly faster. If possible, all new tests
should derive from this class.
"""
USES_DB = False
class BaseHookTestCase(NoDBTestCase):
def assert_has_hook(self, expected_name, func): def assert_has_hook(self, expected_name, func):
self.assertTrue(hasattr(func, '__hook_name__')) self.assertTrue(hasattr(func, '__hook_name__'))
self.assertEqual(expected_name, func.__hook_name__) self.assertEqual(expected_name, func.__hook_name__)

View File

@ -20,16 +20,11 @@ from __future__ import absolute_import
import gettext import gettext
import logging import logging
import os import os
import uuid
import warnings import warnings
import fixtures import fixtures
from oslo_config import cfg from oslo_config import cfg
# from nova.db import migration
# from nova.db.sqlalchemy import api as session
# from nova import rpc
# from nova import service
_TRUE_VALUES = ('True', 'true', '1', 'yes') _TRUE_VALUES = ('True', 'true', '1', 'yes')
@ -37,25 +32,6 @@ CONF = cfg.CONF
DB_SCHEMA = "" DB_SCHEMA = ""
class ServiceFixture(fixtures.Fixture):
"""Run a service as a test fixture."""
def __init__(self, name, host=None, **kwargs):
name = name
host = host or uuid.uuid4().hex
kwargs.setdefault('host', host)
kwargs.setdefault('binary', 'versionedobjects-%s' % name)
self.kwargs = kwargs
def setUp(self):
super(ServiceFixture, self).setUp()
# FIXME(dhellmann): See work items in
# adopt-oslo-versionedobjects spec.
# self.service = service.Service.create(**self.kwargs)
# self.service.start()
# self.addCleanup(self.service.kill)
class TranslationFixture(fixtures.Fixture): class TranslationFixture(fixtures.Fixture):
"""Use gettext NullTranslation objects in tests.""" """Use gettext NullTranslation objects in tests."""
@ -139,10 +115,6 @@ class StandardLogging(fixtures.Fixture):
self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False)) self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False))
handler.setLevel(logging.DEBUG) handler.setLevel(logging.DEBUG)
# Don't log every single DB migration step
logging.getLogger(
'migrate.versioning.api').setLevel(logging.WARNING)
class OutputStreamCapture(fixtures.Fixture): class OutputStreamCapture(fixtures.Fixture):
"""Capture output streams during tests. """Capture output streams during tests.
@ -201,45 +173,6 @@ class Timeout(fixtures.Fixture):
self.useFixture(fixtures.Timeout(self.test_timeout, gentle=True)) self.useFixture(fixtures.Timeout(self.test_timeout, gentle=True))
# class Database(fixtures.Fixture):
# def _cache_schema(self):
# global DB_SCHEMA
# if not DB_SCHEMA:
# engine = session.get_engine()
# conn = engine.connect()
# migration.db_sync()
# DB_SCHEMA = "".join(line for line in conn.connection.iterdump())
# engine.dispose()
# def reset(self):
# self._cache_schema()
# engine = session.get_engine()
# engine.dispose()
# conn = engine.connect()
# conn.connection.executescript(DB_SCHEMA)
# def setUp(self):
# super(Database, self).setUp()
# self.reset()
# class RPCFixture(fixtures.Fixture):
# def __init__(self, *exmods):
# super(RPCFixture, self).__init__()
# self.exmods = []
# self.exmods.extend(exmods)
# def setUp(self):
# super(RPCFixture, self).setUp()
# self.addCleanup(rpc.cleanup)
# rpc.add_extra_exmods(*self.exmods)
# self.addCleanup(rpc.clear_extra_exmods)
# self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
# self.messaging_conf.transport_driver = 'fake'
# self.useFixture(self.messaging_conf)
# rpc.init(CONF)
class WarningsFixture(fixtures.Fixture): class WarningsFixture(fixtures.Fixture):
"""Filters out warnings during test runs.""" """Filters out warnings during test runs."""

View File

@ -34,7 +34,7 @@ class FakeFieldType(fields.FieldType):
return value[1:-1] return value[1:-1]
class TestField(test.NoDBTestCase): class TestField(test.TestCase):
def setUp(self): def setUp(self):
super(TestField, self).setUp() super(TestField, self).setUp()
self.field = fields.Field(FakeFieldType()) self.field = fields.Field(FakeFieldType())

View File

@ -21,7 +21,7 @@ from oslo_versionedobjects import test
CONF = cfg.CONF CONF = cfg.CONF
class VersionTestCase(test.NoDBTestCase): class VersionTestCase(test.TestCase):
def test_convert_version_to_int(self): def test_convert_version_to_int(self):
self.assertEqual(utils.convert_version_to_int('6.2.0'), 6002000) self.assertEqual(utils.convert_version_to_int('6.2.0'), 6002000)
self.assertEqual(utils.convert_version_to_int((6, 4, 3)), 6004003) self.assertEqual(utils.convert_version_to_int((6, 4, 3)), 6004003)