Expose fixtures through oslo_log.fixture
Expose the fixtures through the package import instead of requiring the user to import each module. Add documentation for the fixtures. Change-Id: Ic96a030c45853406c2b77740b26d168cb8882f5c
This commit is contained in:
parent
5d9332e95f
commit
472b68f9d7
9
doc/source/api/fixtures.rst
Normal file
9
doc/source/api/fixtures.rst
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
==================
|
||||||
|
oslo_log.fixture
|
||||||
|
==================
|
||||||
|
|
||||||
|
.. module:: oslo_log.fixture
|
||||||
|
|
||||||
|
.. autofunction:: oslo_log.fixture.get_logging_handle_error_fixture
|
||||||
|
|
||||||
|
.. autoclass:: oslo_log.fixture.SetLogLevel
|
@ -0,0 +1,16 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
from .logging_error import get_logging_handle_error_fixture
|
||||||
|
from .setlevel import SetLogLevel
|
@ -18,8 +18,11 @@ import fixtures
|
|||||||
def get_logging_handle_error_fixture():
|
def get_logging_handle_error_fixture():
|
||||||
"""returns a fixture to make logging raise formatting exceptions.
|
"""returns a fixture to make logging raise formatting exceptions.
|
||||||
|
|
||||||
Usage:
|
To use::
|
||||||
self.useFixture(logging.get_logging_handle_error_fixture())
|
|
||||||
|
from oslo_log import fixture as log_fixture
|
||||||
|
|
||||||
|
self.useFixture(log_fixture.get_logging_handle_error_fixture())
|
||||||
"""
|
"""
|
||||||
return fixtures.MonkeyPatch('logging.Handler.handleError',
|
return fixtures.MonkeyPatch('logging.Handler.handleError',
|
||||||
_handleError)
|
_handleError)
|
||||||
|
@ -23,7 +23,9 @@ class SetLogLevel(fixtures.Fixture):
|
|||||||
|
|
||||||
To use::
|
To use::
|
||||||
|
|
||||||
self.setFixture(['myapp.foo'], logging.DEBUG)
|
from oslo_log import fixture as log_fixture
|
||||||
|
|
||||||
|
self.useFixture(log_fixture.SetLogLevel(['myapp.foo'], logging.DEBUG))
|
||||||
|
|
||||||
:param logger_names: Sequence of logger names, as would be passed
|
:param logger_names: Sequence of logger names, as would be passed
|
||||||
to getLogger().
|
to getLogger().
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
from oslo_log.fixture import logging_error
|
from oslo_log import fixture
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TestLoggingFixture(test_base.BaseTestCase):
|
class TestLoggingFixture(test_base.BaseTestCase):
|
||||||
def test_logging_handle_error(self):
|
def test_logging_handle_error(self):
|
||||||
LOG.error('pid of first child is %(foo)s', 1)
|
LOG.error('pid of first child is %(foo)s', 1)
|
||||||
self.useFixture(logging_error.get_logging_handle_error_fixture())
|
self.useFixture(fixture.get_logging_handle_error_fixture())
|
||||||
self.assertRaises(TypeError,
|
self.assertRaises(TypeError,
|
||||||
LOG.error,
|
LOG.error,
|
||||||
'pid of first child is %(foo)s',
|
'pid of first child is %(foo)s',
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_log.fixture import setlevel
|
from oslo_log import fixture
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class TestSetLevelFixture(test_base.BaseTestCase):
|
|||||||
def test_unset_before(self):
|
def test_unset_before(self):
|
||||||
logger = logging.getLogger('no-such-logger-unset')
|
logger = logging.getLogger('no-such-logger-unset')
|
||||||
self.assertEqual(logging.NOTSET, logger.level)
|
self.assertEqual(logging.NOTSET, logger.level)
|
||||||
fix = setlevel.SetLogLevel(['no-such-logger-unset'], logging.DEBUG)
|
fix = fixture.SetLogLevel(['no-such-logger-unset'], logging.DEBUG)
|
||||||
with fix:
|
with fix:
|
||||||
self.assertEqual(logging.DEBUG, logger.level)
|
self.assertEqual(logging.DEBUG, logger.level)
|
||||||
self.assertEqual(logging.NOTSET, logger.level)
|
self.assertEqual(logging.NOTSET, logger.level)
|
||||||
@ -30,7 +30,7 @@ class TestSetLevelFixture(test_base.BaseTestCase):
|
|||||||
logger = logging.getLogger('no-such-logger-set')
|
logger = logging.getLogger('no-such-logger-set')
|
||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
self.assertEqual(logging.ERROR, logger.level)
|
self.assertEqual(logging.ERROR, logger.level)
|
||||||
fix = setlevel.SetLogLevel(['no-such-logger-set'], logging.DEBUG)
|
fix = fixture.SetLogLevel(['no-such-logger-set'], logging.DEBUG)
|
||||||
with fix:
|
with fix:
|
||||||
self.assertEqual(logging.DEBUG, logger.level)
|
self.assertEqual(logging.DEBUG, logger.level)
|
||||||
self.assertEqual(logging.ERROR, logger.level)
|
self.assertEqual(logging.ERROR, logger.level)
|
||||||
|
Loading…
Reference in New Issue
Block a user