当前位置: 首页>>代码示例>>Python>>正文


Python utils.StringIO类代码示例

本文整理汇总了Python中robot.utils.StringIO的典型用法代码示例。如果您正苦于以下问题:Python StringIO类的具体用法?Python StringIO怎么用?Python StringIO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StringIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _read_html

 def _read_html(self, doctree, rawdata):
     htmlfile = StringIO()
     htmlfile.write(publish_from_doctree(
         doctree, writer_name='html',
         settings_overrides={'output_encoding': 'UTF-8'}))
     htmlfile.seek(0)
     return HtmlReader().read(htmlfile, rawdata)
开发者ID:RoyeeW,项目名称:robotframework,代码行数:7,代码来源:restreader.py

示例2: test_line_separator

 def test_line_separator(self):
     output = StringIO()
     writer = HtmlWriter(output)
     writer.start('b')
     writer.end('b')
     writer.element('i')
     assert_equal(repr(output.getvalue()), repr('<b>\n</b>\n<i></i>\n'))
开发者ID:koonchaim,项目名称:robotframework,代码行数:7,代码来源:test_htmlwriter.py

示例3: get_lines

def get_lines(suite=(), strings=(), basemillis=100, start_block='',
              end_block='', split_threshold=9999, min_level='INFO'):
    output = StringIO()
    data = JsExecutionResult(suite, None, None, strings, basemillis, min_level=min_level)
    writer = JsResultWriter(output, start_block, end_block, split_threshold)
    writer.write(data, settings={})
    return output.getvalue().splitlines()
开发者ID:moto-timo,项目名称:robotframework,代码行数:7,代码来源:test_jswriter.py

示例4: test_end_of_line_whitespace_is_removed

    def test_end_of_line_whitespace_is_removed(self):
        output = StringIO()
        create_test_case_file().save(output=output)
        expected = """\
*** test case ***     some    and other
A test                A kw    an arg
"""
        assert_equals(repr(expected), repr(output.getvalue()))
开发者ID:nurruden,项目名称:robotframework,代码行数:8,代码来源:test_filewriters.py

示例5: test_configuring_number_of_separating_spaces

    def test_configuring_number_of_separating_spaces(self):
        output = StringIO()
        create_test_case_file().save(output=output, txt_separating_spaces=8)
        expected = """\
*** test case ***         some        and other
A test                    A kw        an arg
"""
        assert_equals(repr(expected), repr(output.getvalue()))
开发者ID:nurruden,项目名称:robotframework,代码行数:8,代码来源:test_filewriters.py

示例6: test_json_dump_mapping

 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = "string"
     dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]], mapping={mapped1: "1", mapped2: "a"})
     assert_equal(output.getvalue(), "[1,[a,{a:1}]]")
     assert_raises(ValueError, dumper.dump, [mapped1])
开发者ID:robotframework,项目名称:robotframework,代码行数:8,代码来源:test_jsonwriter.py

示例7: test_dont_register_signal_handlers_then_run_on_thread

 def test_dont_register_signal_handlers_then_run_on_thread(self):
     stream = StringIO()
     thread = threading.Thread(target=run_without_outputs, args=(self.data,),
                               kwargs=dict(stdout=stream, stderr=stream))
     thread.start()
     thread.join()
     output = stream.getvalue()
     assert_true('ERROR' not in output.upper(), 'Errors:\n%s' % output)
开发者ID:moto-timo,项目名称:robotframework,代码行数:8,代码来源:test_run_and_rebot.py

示例8: _MockLogger

class _MockLogger(object):
    def __init__(self):
        self._output = StringIO()

    def message(self, msg):
        self._output.write(msg.message)

    def value(self):
        return self._output.getvalue()
开发者ID:HelioGuilherme66,项目名称:robotframework,代码行数:9,代码来源:test_populator.py

示例9: test_json_dump_mapping

 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = 'string'
     dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]],
                 mapping={mapped1: '1', mapped2: 'a'})
     assert_equal(output.getvalue(), '[1,[a,{a:1}]]')
     assert_raises(ValueError, dumper.dump, [mapped1])
开发者ID:synsun,项目名称:robotframework,代码行数:9,代码来源:test_jsonwriter.py

示例10: test_non_ascii

 def test_non_ascii(self):
     self.output = StringIO()
     writer = HtmlWriter(self.output)
     writer.start(u'p', attrs={'name': u'hyv\xe4\xe4'}, newline=False)
     writer.content(u'y\xf6')
     writer.element('i', u't\xe4', newline=False)
     writer.end('p', newline=False)
     self._verify(u'<p name="hyv\xe4\xe4">y\xf6<i>t\xe4</i></p>')
开发者ID:koonchaim,项目名称:robotframework,代码行数:8,代码来源:test_htmlwriter.py

示例11: __init__

 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)
开发者ID:moto-timo,项目名称:robotframework,代码行数:9,代码来源:outputcapture.py

示例12: PythonCapturer

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
开发者ID:moto-timo,项目名称:robotframework,代码行数:44,代码来源:outputcapture.py

示例13: ClosableOutput

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
开发者ID:BanerjeeSandipan,项目名称:robotframework,代码行数:21,代码来源:test_reporting.py

示例14: test_run_multiple_times_with_different_stdout_and_stderr

 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)])
开发者ID:BanerjeeSandipan,项目名称:robotframework,代码行数:16,代码来源:test_running.py

示例15: __init__

 def __init__(self, path):
     self._output = StringIO()
     self._path = path
开发者ID:BanerjeeSandipan,项目名称:robotframework,代码行数:3,代码来源:test_reporting.py


注:本文中的robot.utils.StringIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。