本文整理汇总了Python中distutils.log.fatal方法的典型用法代码示例。如果您正苦于以下问题:Python log.fatal方法的具体用法?Python log.fatal怎么用?Python log.fatal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类distutils.log
的用法示例。
在下文中一共展示了log.fatal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_non_ascii
# 需要导入模块: from distutils import log [as 别名]
# 或者: from distutils.log import fatal [as 别名]
def test_non_ascii(self):
# Issue #8663: test that non-ASCII text is escaped with
# backslashreplace error handler (stream use ASCII encoding and strict
# error handler)
old_stdout = sys.stdout
old_stderr = sys.stderr
old_threshold = log.set_threshold(log.DEBUG)
try:
with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
sys.stdout = stdout
sys.stderr = stderr
log.debug("debug:\xe9")
log.fatal("fatal:\xe9")
stdout.seek(0)
self.assertEqual(stdout.read().rstrip(), "debug:\\xe9")
stderr.seek(0)
self.assertEqual(stderr.read().rstrip(), "fatal:\\xe9")
finally:
log.set_threshold(old_threshold)
sys.stdout = old_stdout
sys.stderr = old_stderr
示例2: test_non_ascii
# 需要导入模块: from distutils import log [as 别名]
# 或者: from distutils.log import fatal [as 别名]
def test_non_ascii(self):
# Issues #8663, #34421: test that non-encodable text is escaped with
# backslashreplace error handler and encodable non-ASCII text is
# output as is.
for errors in ('strict', 'backslashreplace', 'surrogateescape',
'replace', 'ignore'):
with self.subTest(errors=errors):
stdout = io.TextIOWrapper(io.BytesIO(),
encoding='cp437', errors=errors)
stderr = io.TextIOWrapper(io.BytesIO(),
encoding='cp437', errors=errors)
old_threshold = log.set_threshold(log.DEBUG)
try:
with swap_attr(sys, 'stdout', stdout), \
swap_attr(sys, 'stderr', stderr):
log.debug('Dεbug\tMėssãge')
log.fatal('Fαtal\tÈrrōr')
finally:
log.set_threshold(old_threshold)
stdout.seek(0)
self.assertEqual(stdout.read().rstrip(),
'Dεbug\tM?ss?ge' if errors == 'replace' else
'Dεbug\tMssge' if errors == 'ignore' else
'Dεbug\tM\\u0117ss\\xe3ge')
stderr.seek(0)
self.assertEqual(stderr.read().rstrip(),
'Fαtal\t?rr?r' if errors == 'replace' else
'Fαtal\trrr' if errors == 'ignore' else
'Fαtal\t\\xc8rr\\u014dr')