本文整理汇总了Python中fixtures.FakeLogger方法的典型用法代码示例。如果您正苦于以下问题:Python fixtures.FakeLogger方法的具体用法?Python fixtures.FakeLogger怎么用?Python fixtures.FakeLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fixtures
的用法示例。
在下文中一共展示了fixtures.FakeLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_safe_delete_vpnservice
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_safe_delete_vpnservice(self):
vpn_gateway_api._safe_delete_vpnservice(
self.neutron, fakes.ID_OS_VPNSERVICE_1, fakes.ID_EC2_SUBNET_1)
self.neutron.delete_vpnservice.assert_called_once_with(
fakes.ID_OS_VPNSERVICE_1)
self.neutron.delete_vpnservice.side_effect = (
neutron_exception.NotFound())
with fixtures.FakeLogger() as log:
vpn_gateway_api._safe_delete_vpnservice(
self.neutron, fakes.ID_OS_VPNSERVICE_1, fakes.ID_EC2_SUBNET_1)
self.assertEqual(0, len(log.output))
self.neutron.delete_vpnservice.side_effect = (
neutron_exception.Conflict())
with fixtures.FakeLogger() as log:
vpn_gateway_api._safe_delete_vpnservice(
self.neutron, fakes.ID_OS_VPNSERVICE_1, fakes.ID_EC2_SUBNET_1)
self.assertIn(fakes.ID_EC2_SUBNET_1, log.output)
self.assertIn(fakes.ID_OS_VPNSERVICE_1, log.output)
示例2: setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def setUp(self):
"Run before each test method to initialize test environment."
super(TestCase, self).setUp()
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))
self.useFixture(fixtures.NestedTempfile())
self.useFixture(fixtures.TempHomeDir())
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))
self.log_fixture = self.useFixture(fixtures.FakeLogger())
示例3: setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
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))
self.useFixture(fixtures.NestedTempfile())
self.useFixture(fixtures.TempHomeDir())
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))
self.log_fixture = self.useFixture(fixtures.FakeLogger())
示例4: setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
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))
self.useFixture(fixtures.NestedTempfile())
self.temp_homedir = self.useFixture(fixtures.TempHomeDir()).path
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))
self.log_fixture = self.useFixture(fixtures.FakeLogger())
示例5: test_filter_tokens_from_log
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_filter_tokens_from_log(self):
logger = self.useFixture(fixtures.FakeLogger(nuke_handlers=False))
@webob.dec.wsgify
def application(req):
raise Exception()
app = catch_errors.CatchErrors(application)
req = webob.Request.blank('/test',
text=u'test data',
method='POST',
headers={'X-Auth-Token': 'secret1',
'X-Service-Token': 'secret2',
'X-Other-Token': 'secret3'})
res = req.get_response(app)
self.assertEqual(500, res.status_int)
output = logger.output
self.assertIn('X-Auth-Token: *****', output)
self.assertIn('X-Service-Token: *****', output)
self.assertIn('X-Other-Token: *****', output)
self.assertIn('test data', output)
示例6: test_save_and_reraise_when_rollback_exception
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_save_and_reraise_when_rollback_exception(self,
rollback_patch,
commit_patch):
context = oslo_context.RequestContext()
log = self.useFixture(fixtures.FakeLogger())
class RollbackException(Exception):
pass
class CommitException(Exception):
pass
commit_patch.side_effect = CommitException()
rollback_patch.side_effect = RollbackException()
@enginefacade.writer
def go_session(context):
context.session.add(self.User(name="u1"))
self.assertRaises(RollbackException, go_session, context)
self.assertIn('CommitException', log.output)
示例7: test_ensure_backend_available_no_connection_raises
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_ensure_backend_available_no_connection_raises(self):
log = self.useFixture(fixtures.FakeLogger())
err = OperationalError("Can't connect to database", None, None)
with mock.patch.object(
sqlalchemy.engine.base.Engine, 'connect') as mock_connect:
mock_connect.side_effect = err
exc = self.assertRaises(
exception.BackendNotAvailable,
provision.Backend._ensure_backend_available,
self.connect_string)
self.assertEqual(
"Backend 'postgresql' is unavailable: "
"Could not connect", str(exc))
self.assertEqual(
"The postgresql backend is unavailable: %s" % err,
log.output.strip())
示例8: test_ensure_backend_available_no_dbapi_raises
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_ensure_backend_available_no_dbapi_raises(self):
log = self.useFixture(fixtures.FakeLogger())
with mock.patch.object(sqlalchemy, 'create_engine') as mock_create:
mock_create.side_effect = ImportError(
"Can't import DBAPI module foobar")
exc = self.assertRaises(
exception.BackendNotAvailable,
provision.Backend._ensure_backend_available,
self.connect_string)
mock_create.assert_called_once_with(
sa_url.make_url(self.connect_string))
self.assertEqual(
"Backend 'postgresql' is unavailable: "
"No DBAPI installed", str(exc))
self.assertEqual(
"The postgresql backend is unavailable: Can't import "
"DBAPI module foobar", log.output.strip())
示例9: _test_and_check_logging_communicate_errors
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def _test_and_check_logging_communicate_errors(self, log_errors=None,
attempts=None):
mock = self.useFixture(fixtures.MockPatch(
'subprocess.Popen.communicate',
side_effect=OSError(errno.EAGAIN, 'fake-test')))
fixture = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
kwargs = {}
if log_errors:
kwargs.update({"log_errors": log_errors})
if attempts:
kwargs.update({"attempts": attempts})
self.assertRaises(OSError,
processutils.execute,
'/usr/bin/env',
'false',
**kwargs)
self.assertEqual(attempts if attempts else 1, mock.mock.call_count)
self.assertIn('Got an OSError', fixture.output)
self.assertIn('errno: %d' % errno.EAGAIN, fixture.output)
self.assertIn("'/usr/bin/env false'", fixture.output)
示例10: _test_and_check
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def _test_and_check(self, log_errors=None, attempts=None):
fixture = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
kwargs = {}
if log_errors:
kwargs.update({"log_errors": log_errors})
if attempts:
kwargs.update({"attempts": attempts})
err = self.assertRaises(processutils.ProcessExecutionError,
processutils.execute,
self.tmpfilename,
**kwargs)
self.assertEqual(41, err.exit_code)
self.assertIn(self.tmpfilename, fixture.output)
示例11: setup_logging
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def setup_logging(self):
# Assign default logs to self.LOG so we can still
# assert on senlin logs.
default_level = logging.INFO
if os.environ.get('OS_DEBUG') in _TRUE_VALUES:
default_level = logging.DEBUG
self.LOG = self.useFixture(
fixtures.FakeLogger(level=default_level, format=_LOG_FORMAT))
base_list = set([nlog.split('.')[0] for nlog in
logging.getLogger().logger.manager.loggerDict])
for base in base_list:
if base in TEST_DEFAULT_LOGLEVELS:
self.useFixture(fixtures.FakeLogger(
level=TEST_DEFAULT_LOGLEVELS[base],
name=base, format=_LOG_FORMAT))
elif base != 'senlin':
self.useFixture(fixtures.FakeLogger(
name=base, format=_LOG_FORMAT))
示例12: setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def setUp(self):
super(Base, self).setUp()
self.fake_logger = self.useFixture(
fixtures.FakeLogger(
format='%(levelname)8s %(name)s %(message)s',
level=logging.DEBUG,
nuke_handlers=True,
)
)
# Older git does not have config --local, so create a temporary home
# directory to permit using git config --global without stepping on
# developer configuration.
self.useFixture(fixtures.TempHomeDir())
self.useFixture(fixtures.NestedTempfile())
self.temp_dir = self.useFixture(fixtures.TempDir()).path
self.reporoot = os.path.join(self.temp_dir, 'reporoot')
self.repo = self.useFixture(GitRepoFixture(self.reporoot))
self.c = config.Config(self.reporoot)
self._counter = itertools.count(1)
self.get_note_num = lambda: next(self._counter)
示例13: test_sync_does_propagate_ioerror
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_sync_does_propagate_ioerror(self):
io_error = factory.make_exception_type(bases=(IOError,))
mock_sync = self.patch(download_descriptions.BasicMirrorWriter, "sync")
mock_sync.side_effect = io_error()
boot_images_dict = BootImageMapping()
dumper = RepoDumper(boot_images_dict)
with FakeLogger("maas.import-images", level=logging.INFO) as maaslog:
self.assertRaises(
io_error, dumper.sync, sentinel.reader, sentinel.path
)
self.assertDocTestMatches(
"...error...syncing boot images...", maaslog.output
)
示例14: test_query_all_nodes_swallows_PowerActionFail
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_query_all_nodes_swallows_PowerActionFail(self):
node1, node2 = self.make_nodes(2)
new_state_2 = self.pick_alternate_state(node2["power_state"])
get_power_state = self.patch(power, "get_power_state")
error_msg = factory.make_name("error")
get_power_state.side_effect = [
fail(exceptions.PowerActionFail(error_msg)),
succeed(new_state_2),
]
suppress_reporting(self)
with FakeLogger("maas.power", level=logging.DEBUG) as maaslog:
yield power.query_all_nodes([node1, node2])
self.assertDocTestMatches(
"""\
hostname-...: Could not query power state: %s.
hostname-...: Power state has changed from ... to ...
"""
% error_msg,
maaslog.output,
)
示例15: test_query_all_nodes_swallows_NoSuchNode
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import FakeLogger [as 别名]
def test_query_all_nodes_swallows_NoSuchNode(self):
node1, node2 = self.make_nodes(2)
new_state_2 = self.pick_alternate_state(node2["power_state"])
get_power_state = self.patch(power, "get_power_state")
get_power_state.side_effect = [
fail(exceptions.NoSuchNode()),
succeed(new_state_2),
]
suppress_reporting(self)
with FakeLogger("maas.power", level=logging.DEBUG) as maaslog:
yield power.query_all_nodes([node1, node2])
self.assertDocTestMatches(
"""\
hostname-...: Power state has changed from ... to ...
""",
maaslog.output,
)