From 54ac5cfb9f3597ed16d2c7376d29cb04d5fb18ef Mon Sep 17 00:00:00 2001 From: Hiroaki Kobayashi Date: Wed, 1 Feb 2017 16:53:46 +0900 Subject: [PATCH] Use oslotest This patch converts the Blazar code base from its oslo-incubator test module to the oslotest module. Change-Id: I22d56b1b80acfbe103253c2e505d892b30a064a0 Closes-Bug: #1660901 --- .../common/db/sqlalchemy/test_base.py | 2 +- .../common/db/sqlalchemy/test_migrations.py | 2 +- climate/openstack/common/fixture/__init__.py | 0 climate/openstack/common/fixture/config.py | 46 ---------- climate/openstack/common/fixture/mockpatch.py | 51 ----------- .../openstack/common/fixture/moxstubout.py | 37 -------- climate/openstack/common/test.py | 90 ------------------- climate/tests/__init__.py | 6 +- test-requirements.txt | 2 +- 9 files changed, 6 insertions(+), 230 deletions(-) delete mode 100644 climate/openstack/common/fixture/__init__.py delete mode 100644 climate/openstack/common/fixture/config.py delete mode 100644 climate/openstack/common/fixture/mockpatch.py delete mode 100644 climate/openstack/common/fixture/moxstubout.py delete mode 100644 climate/openstack/common/test.py diff --git a/climate/openstack/common/db/sqlalchemy/test_base.py b/climate/openstack/common/db/sqlalchemy/test_base.py index 43fe5d52..73cb52b4 100644 --- a/climate/openstack/common/db/sqlalchemy/test_base.py +++ b/climate/openstack/common/db/sqlalchemy/test_base.py @@ -18,11 +18,11 @@ import functools import os import fixtures +from oslotest import base as test import six from climate.openstack.common.db.sqlalchemy import session from climate.openstack.common.db.sqlalchemy import utils -from climate.openstack.common import test class DbFixture(fixtures.Fixture): diff --git a/climate/openstack/common/db/sqlalchemy/test_migrations.py b/climate/openstack/common/db/sqlalchemy/test_migrations.py index 59e51b8d..6b65e3de 100644 --- a/climate/openstack/common/db/sqlalchemy/test_migrations.py +++ b/climate/openstack/common/db/sqlalchemy/test_migrations.py @@ -20,6 +20,7 @@ import subprocess import lockfile from oslo_log import log as logging +from oslotest import base as test from six import moves from six.moves.urllib import parse import sqlalchemy @@ -27,7 +28,6 @@ import sqlalchemy.exc from climate.i18n import _LE from climate.openstack.common.db.sqlalchemy import utils -from climate.openstack.common import test LOG = logging.getLogger(__name__) diff --git a/climate/openstack/common/fixture/__init__.py b/climate/openstack/common/fixture/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/climate/openstack/common/fixture/config.py b/climate/openstack/common/fixture/config.py deleted file mode 100644 index db79e63a..00000000 --- a/climate/openstack/common/fixture/config.py +++ /dev/null @@ -1,46 +0,0 @@ -# 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 -import six - - -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 six.iteritems(kw): - self.conf.set_override(k, v, group) diff --git a/climate/openstack/common/fixture/mockpatch.py b/climate/openstack/common/fixture/mockpatch.py deleted file mode 100644 index cd0d6ca6..00000000 --- a/climate/openstack/common/fixture/mockpatch.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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) diff --git a/climate/openstack/common/fixture/moxstubout.py b/climate/openstack/common/fixture/moxstubout.py deleted file mode 100644 index f277fdd7..00000000 --- a/climate/openstack/common/fixture/moxstubout.py +++ /dev/null @@ -1,37 +0,0 @@ -# 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) diff --git a/climate/openstack/common/test.py b/climate/openstack/common/test.py deleted file mode 100644 index 2f64b5de..00000000 --- a/climate/openstack/common/test.py +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 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. - -############################################################################## -############################################################################## -## -## DO NOT MODIFY THIS FILE -## -## This file is being graduated to the climatetest library. Please make all -## changes there, and only backport critical fixes here. - dhellmann -## -############################################################################## -############################################################################## - -"""Common utilities used in testing""" - -import os -import tempfile - -import fixtures -from oslo_log import log as logging -import testtools - -_TRUE_VALUES = ('True', 'true', '1', 'yes') -_LOG_FORMAT = "%(levelname)8s [%(name)s] %(message)s" - - -class BaseTestCase(testtools.TestCase): - - def setUp(self): - super(BaseTestCase, self).setUp() - self._set_timeout() - self._fake_output() - self._fake_logs() - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.TempHomeDir()) - self.tempdirs = [] - - def _set_timeout(self): - test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) - try: - test_timeout = int(test_timeout) - except ValueError: - # If timeout value is invalid do not set a timeout. - test_timeout = 0 - if test_timeout > 0: - self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) - - def _fake_output(self): - if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: - stdout = self.useFixture(fixtures.StringStream('stdout')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: - stderr = self.useFixture(fixtures.StringStream('stderr')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - - def _fake_logs(self): - if os.environ.get('OS_DEBUG') in _TRUE_VALUES: - level = logging.DEBUG - else: - level = logging.INFO - self.useFixture(fixtures.FakeLogger(format=_LOG_FORMAT, - level=level)) - - def create_tempfiles(self, files, ext='.conf'): - tempfiles = [] - for (basename, contents) in files: - if not os.path.isabs(basename): - (fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext) - else: - path = basename + ext - fd = os.open(path, os.O_CREAT | os.O_WRONLY) - tempfiles.append(path) - try: - os.write(fd, contents) - finally: - os.close(fd) - return tempfiles diff --git a/climate/tests/__init__.py b/climate/tests/__init__.py index 4d18a74e..70d4bc31 100644 --- a/climate/tests/__init__.py +++ b/climate/tests/__init__.py @@ -21,12 +21,12 @@ import testscenarios from oslo_config import cfg from oslo_log import log as logging +from oslotest import base +from oslotest import mockpatch from climate import context from climate.db.sqlalchemy import api as db_api from climate.db.sqlalchemy import facade_wrapper -from climate.openstack.common.fixture import mockpatch -from climate.openstack.common import test from climate import policy from climate.tests import fake_policy @@ -69,7 +69,7 @@ class PolicyFixture(fixtures.Fixture): self.addCleanup(policy.reset) -class TestCase(testscenarios.WithScenarios, test.BaseTestCase): +class TestCase(testscenarios.WithScenarios, base.BaseTestCase): """Test case base class for all unit tests. Due to the slowness of DB access, this class is not supporting DB tests. diff --git a/test-requirements.txt b/test-requirements.txt index 5c552f79..7f325014 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,7 +9,6 @@ mox>=0.5.3 # Apache-2.0 sphinx!=1.3b1,<1.4,>=1.2.1 # BSD sphinxcontrib-httpdomain # BSD lockfile>=0.8 - discover # BSD fixtures>=3.0.0 # Apache-2.0/BSD testrepository>=0.0.18 # Apache-2.0/BSD @@ -18,3 +17,4 @@ testtools>=1.4.0 # MIT coverage>=4.0 # Apache-2.0 pylint==1.4.5 # GPLv2 sphinxcontrib-pecanwsme>=0.8 # Apache-2.0 +oslotest>=1.10.0 # Apache-2.0