本文整理汇总了Python中robot.utils.StringIO.close方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.close方法的具体用法?Python StringIO.close怎么用?Python StringIO.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robot.utils.StringIO
的用法示例。
在下文中一共展示了StringIO.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run_multiple_times_with_different_stdout_and_stderr
# 需要导入模块: from robot.utils import StringIO [as 别名]
# 或者: from robot.utils.StringIO import close [as 别名]
def test_run_multiple_times_with_different_stdout_and_stderr(self):
stdout, stderr = StringIO(), StringIO()
self._run(stdout, stderr)
self._assert_normal_stdout_stderr_are_empty()
self._assert_output(stdout, [('My Suite', 2), ('My Test', 1)])
self._assert_output(stderr, [('Hello, world!', 1)])
stdout.close(); stderr.close()
output = StringIO()
self._run(output, output, variable='MESSAGE:Hi, again!')
self._assert_normal_stdout_stderr_are_empty()
self._assert_output(output, [('My Suite', 2), ('My Test', 1),
('Hi, again!', 1), ('Hello, world!', 0)])
output.close()
self._run(variable='MESSAGE:Last hi!')
self._assert_output(sys.__stdout__, [('My Suite', 2), ('My Test', 1)])
self._assert_output(sys.__stderr__, [('Last hi!', 1), ('Hello, world!', 0)])
示例2: PythonCapturer
# 需要导入模块: from robot.utils import StringIO [as 别名]
# 或者: from robot.utils.StringIO import close [as 别名]
class PythonCapturer(object):
def __init__(self, stdout=True):
if stdout:
self._original = sys.stdout
self._set_stream = self._set_stdout
else:
self._original = sys.stderr
self._set_stream = self._set_stderr
self._stream = StringIO()
self._set_stream(self._stream)
def _set_stdout(self, stream):
sys.stdout = stream
def _set_stderr(self, stream):
sys.stderr = stream
def release(self):
# Original stream must be restored before closing the current
self._set_stream(self._original)
try:
return self._get_value(self._stream)
finally:
self._stream.close()
self._avoid_at_exit_errors(self._stream)
def _get_value(self, stream):
try:
return decode_output(stream.getvalue())
except UnicodeError:
# Error occurs if non-ASCII chars logged both as str and unicode.
stream.buf = decode_output(stream.buf)
stream.buflist = [decode_output(item) for item in stream.buflist]
return stream.getvalue()
def _avoid_at_exit_errors(self, stream):
# Avoid ValueError at program exit when logging module tries to call
# methods of streams it has intercepted that are already closed.
# Which methods are called, and does logging silence possible errors,
# depends on Python/Jython version. For related discussion see
# http://bugs.python.org/issue6333
stream.write = lambda s: None
stream.flush = lambda: None
示例3: ClosableOutput
# 需要导入模块: from robot.utils import StringIO [as 别名]
# 或者: from robot.utils.StringIO import close [as 别名]
class ClosableOutput(object):
def __init__(self, path):
self._output = StringIO()
self._path = path
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
def write(self, data):
self._output.write(data)
def close(self):
self.value = self._output.getvalue()
self._output.close()
def __str__(self):
return self._path