本文整理汇总了Python中twisted.python.compat.NativeStringIO.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python NativeStringIO.truncate方法的具体用法?Python NativeStringIO.truncate怎么用?Python NativeStringIO.truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.compat.NativeStringIO
的用法示例。
在下文中一共展示了NativeStringIO.truncate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PythonLoggingObserverTestCase
# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import truncate [as 别名]
class PythonLoggingObserverTestCase(unittest.SynchronousTestCase):
"""
Test the bridge with python logging module.
"""
def setUp(self):
self.out = StringIO()
rootLogger = logging.getLogger("")
self.originalLevel = rootLogger.getEffectiveLevel()
rootLogger.setLevel(logging.DEBUG)
self.hdlr = logging.StreamHandler(self.out)
fmt = logging.Formatter(logging.BASIC_FORMAT)
self.hdlr.setFormatter(fmt)
rootLogger.addHandler(self.hdlr)
self.lp = log.LogPublisher()
self.obs = log.PythonLoggingObserver()
self.lp.addObserver(self.obs.emit)
def tearDown(self):
rootLogger = logging.getLogger("")
rootLogger.removeHandler(self.hdlr)
rootLogger.setLevel(self.originalLevel)
logging.shutdown()
def test_singleString(self):
"""
Test simple output, and default log level.
"""
self.lp.msg("Hello, world.")
self.assertIn("Hello, world.", self.out.getvalue())
self.assertIn("INFO", self.out.getvalue())
def test_errorString(self):
"""
Test error output.
"""
self.lp.msg(failure=failure.Failure(ValueError("That is bad.")), isError=True)
self.assertIn("ERROR", self.out.getvalue())
def test_formatString(self):
"""
Test logging with a format.
"""
self.lp.msg(format="%(bar)s oo %(foo)s", bar="Hello", foo="world")
self.assertIn("Hello oo world", self.out.getvalue())
def test_customLevel(self):
"""
Test the logLevel keyword for customizing level used.
"""
self.lp.msg("Spam egg.", logLevel=logging.DEBUG)
self.assertIn("Spam egg.", self.out.getvalue())
self.assertIn("DEBUG", self.out.getvalue())
self.out.seek(0, 0)
self.out.truncate()
self.lp.msg("Foo bar.", logLevel=logging.WARNING)
self.assertIn("Foo bar.", self.out.getvalue())
self.assertIn("WARNING", self.out.getvalue())
def test_strangeEventDict(self):
"""
Verify that an event dictionary which is not an error and has an empty
message isn't recorded.
"""
self.lp.msg(message='', isError=False)
self.assertEqual(self.out.getvalue(), '')