From 472b68f9d7c04738b4587cccb8e9b56f9c0e320d Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Fri, 30 Jan 2015 11:31:53 -0500 Subject: [PATCH] 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 --- doc/source/api/fixtures.rst | 9 +++++++++ oslo_log/fixture/__init__.py | 16 ++++++++++++++++ oslo_log/fixture/logging_error.py | 7 +++++-- oslo_log/fixture/setlevel.py | 4 +++- .../tests/unit/fixture/test_logging_error.py | 4 ++-- oslo_log/tests/unit/fixture/test_setlevel.py | 6 +++--- 6 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 doc/source/api/fixtures.rst diff --git a/doc/source/api/fixtures.rst b/doc/source/api/fixtures.rst new file mode 100644 index 00000000..97f69abe --- /dev/null +++ b/doc/source/api/fixtures.rst @@ -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 diff --git a/oslo_log/fixture/__init__.py b/oslo_log/fixture/__init__.py index e69de29b..577ac911 100644 --- a/oslo_log/fixture/__init__.py +++ b/oslo_log/fixture/__init__.py @@ -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 diff --git a/oslo_log/fixture/logging_error.py b/oslo_log/fixture/logging_error.py index 3823a035..9a3140ac 100644 --- a/oslo_log/fixture/logging_error.py +++ b/oslo_log/fixture/logging_error.py @@ -18,8 +18,11 @@ import fixtures def get_logging_handle_error_fixture(): """returns a fixture to make logging raise formatting exceptions. - Usage: - self.useFixture(logging.get_logging_handle_error_fixture()) + To use:: + + from oslo_log import fixture as log_fixture + + self.useFixture(log_fixture.get_logging_handle_error_fixture()) """ return fixtures.MonkeyPatch('logging.Handler.handleError', _handleError) diff --git a/oslo_log/fixture/setlevel.py b/oslo_log/fixture/setlevel.py index 4938911a..d3e2e2c1 100644 --- a/oslo_log/fixture/setlevel.py +++ b/oslo_log/fixture/setlevel.py @@ -23,7 +23,9 @@ class SetLogLevel(fixtures.Fixture): 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 to getLogger(). diff --git a/oslo_log/tests/unit/fixture/test_logging_error.py b/oslo_log/tests/unit/fixture/test_logging_error.py index 0ae6ef4f..504864ac 100644 --- a/oslo_log/tests/unit/fixture/test_logging_error.py +++ b/oslo_log/tests/unit/fixture/test_logging_error.py @@ -11,7 +11,7 @@ # under the License. -from oslo_log.fixture import logging_error +from oslo_log import fixture from oslo_log import log as logging from oslotest import base as test_base @@ -21,7 +21,7 @@ LOG = logging.getLogger(__name__) class TestLoggingFixture(test_base.BaseTestCase): def test_logging_handle_error(self): 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, LOG.error, 'pid of first child is %(foo)s', diff --git a/oslo_log/tests/unit/fixture/test_setlevel.py b/oslo_log/tests/unit/fixture/test_setlevel.py index c4f4c12f..eaaa7e4f 100644 --- a/oslo_log/tests/unit/fixture/test_setlevel.py +++ b/oslo_log/tests/unit/fixture/test_setlevel.py @@ -12,7 +12,7 @@ import logging -from oslo_log.fixture import setlevel +from oslo_log import fixture from oslotest import base as test_base @@ -21,7 +21,7 @@ class TestSetLevelFixture(test_base.BaseTestCase): def test_unset_before(self): logger = logging.getLogger('no-such-logger-unset') 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: self.assertEqual(logging.DEBUG, 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.setLevel(logging.ERROR) 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: self.assertEqual(logging.DEBUG, logger.level) self.assertEqual(logging.ERROR, logger.level)