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


Python StringIO.getvalue方法代码示例

本文整理汇总了Python中coverage.backward.StringIO.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.getvalue方法的具体用法?Python StringIO.getvalue怎么用?Python StringIO.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage.backward.StringIO的用法示例。


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

示例1: StdStreamCapturingMixin

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
class StdStreamCapturingMixin(TestCase):
    """A test case mixin that captures stdout and stderr."""

    def setUp(self):
        super(StdStreamCapturingMixin, self).setUp()

        # Capture stdout and stderr so we can examine them in tests.
        # nose keeps stdout from littering the screen, so we can safely Tee it,
        # but it doesn't capture stderr, so we don't want to Tee stderr to the
        # real stderr, since it will interfere with our nice field of dots.
        self.old_stdout = sys.stdout
        self.captured_stdout = StringIO()
        sys.stdout = Tee(sys.stdout, self.captured_stdout)

        self.old_stderr = sys.stderr
        self.captured_stderr = StringIO()
        sys.stderr = self.captured_stderr

        self.addCleanup(self.cleanup_std_streams)

    def cleanup_std_streams(self):
        """Restore stdout and stderr."""
        sys.stdout = self.old_stdout
        sys.stderr = self.old_stderr

    def stdout(self):
        """Return the data written to stdout during the test."""
        return self.captured_stdout.getvalue()

    def stderr(self):
        """Return the data written to stderr during the test."""
        return self.captured_stderr.getvalue()
开发者ID:BLourence,项目名称:RemoteIR,代码行数:34,代码来源:test_helpers.py

示例2: test_plugin_with_no_sys_info

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_plugin_with_no_sys_info(self):
        self.make_file(
            "plugin_no_sys_info.py",
            """\
            import coverage

            class Plugin(coverage.CoveragePlugin):
                pass

            def coverage_init(reg, options):
                reg.add_noop(Plugin())
            """,
        )
        debug_out = StringIO()
        cov = coverage.Coverage(debug=["sys"])
        cov._debug_file = debug_out
        cov.config["run:plugins"] = ["plugin_no_sys_info"]
        cov.load()

        out_lines = debug_out.getvalue().splitlines()
        expected_end = [
            "-- sys: plugin_no_sys_info.Plugin ----------------------------",
            "-- end -------------------------------------------------------",
        ]
        self.assertEqual(expected_end, out_lines[-len(expected_end) :])
开发者ID:silviot,项目名称:coveragepy,代码行数:27,代码来源:test_plugins.py

示例3: pretend_to_be_pytestcov

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def pretend_to_be_pytestcov(self, append):
        """Act like pytest-cov."""
        self.make_file("prog.py", """\
            a = 1
            b = 2
            if b == 1:
                c = 4
            """)
        self.make_file(".coveragerc", """\
            [run]
            parallel = True
            source = .
            """)

        cov = coverage.Coverage(source=None, branch=None, config_file='.coveragerc')
        if append:
            cov.load()
        else:
            cov.erase()
        self.start_import_stop(cov, "prog")
        cov.combine()
        cov.save()
        report = StringIO()
        cov.report(show_missing=None, ignore_errors=True, file=report, skip_covered=None)
        self.assertEqual(report.getvalue(), textwrap.dedent("""\
            Name      Stmts   Miss  Cover
            -----------------------------
            prog.py       4      1    75%
            """))
        self.assert_file_count(".coverage", 0)
        self.assert_file_count(".coverage.*", 1)
开发者ID:hugovk,项目名称:coveragepy,代码行数:33,代码来源:test_api.py

示例4: test_plugin_with_no_sys_info

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_plugin_with_no_sys_info(self):
        self.make_file("plugin_no_sys_info.py", """\
            import coverage

            class Plugin(coverage.CoveragePlugin):
                pass

            def coverage_init(reg, options):
                reg.add_configurer(Plugin())
            """)
        debug_out = StringIO()
        cov = coverage.Coverage(debug=["sys"])
        cov._debug_file = debug_out
        cov.set_option("run:plugins", ["plugin_no_sys_info"])
        cov.start()
        cov.stop()      # pragma: nested

        out_lines = [line.strip() for line in debug_out.getvalue().splitlines()]
        self.assertIn('plugins.file_tracers: -none-', out_lines)
        self.assertIn('plugins.configurers: plugin_no_sys_info.Plugin', out_lines)
        expected_end = [
            "-- sys: plugin_no_sys_info.Plugin ----------------------------",
            "-- end -------------------------------------------------------",
            ]
        self.assertEqual(expected_end, out_lines[-len(expected_end):])
开发者ID:hugovk,项目名称:coveragepy,代码行数:27,代码来源:test_plugins.py

示例5: test_plugin_sys_info

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_plugin_sys_info(self):
        self.make_file(
            "plugin_sys_info.py",
            """\
            import coverage

            class Plugin(coverage.CoveragePlugin):
                def sys_info(self):
                    return [("hello", "world")]

            def coverage_init(reg, options):
                reg.add_noop(Plugin())
            """,
        )
        debug_out = StringIO()
        cov = coverage.Coverage(debug=["sys"])
        cov._debug_file = debug_out
        cov.set_option("run:plugins", ["plugin_sys_info"])
        cov.load()

        out_lines = debug_out.getvalue().splitlines()
        expected_end = [
            "-- sys: plugin_sys_info.Plugin -------------------------------",
            " hello: world",
            "-- end -------------------------------------------------------",
        ]
        self.assertEqual(expected_end, out_lines[-len(expected_end) :])
开发者ID:jayhetee,项目名称:coveragepy,代码行数:29,代码来源:test_plugins.py

示例6: get_report

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
 def get_report(self, cov):
     """Get the report from `cov`, and canonicalize it."""
     repout = StringIO()
     cov.report(file=repout, show_missing=False)
     report = repout.getvalue().replace('\\', '/')
     report = re.sub(r" +", " ", report)
     return report
开发者ID:ziadsawalha,项目名称:coveragepy,代码行数:9,代码来源:test_summary.py

示例7: coverage_usepkgs

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
 def coverage_usepkgs(self, **kwargs):
     """Try coverage.report()."""
     cov = coverage.coverage()
     cov.start()
     import usepkgs  # pragma: nested   # pylint: disable=F0401,W0612
     cov.stop()      # pragma: nested
     report = StringIO()
     cov.report(file=report, **kwargs)
     return report.getvalue()
开发者ID:nveiseh,项目名称:apimedf,代码行数:11,代码来源:test_api.py

示例8: coverage_usepkgs

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
 def coverage_usepkgs(self, **kwargs):
     """Try coverage.report()."""
     cov = coverage.Coverage()
     cov.start()
     import usepkgs  # pragma: nested   # pylint: disable=import-error,unused-variable
     cov.stop()      # pragma: nested
     report = StringIO()
     cov.report(file=report, **kwargs)
     return report.getvalue()
开发者ID:d-b-w,项目名称:coveragepy,代码行数:11,代码来源:test_api.py

示例9: test_defer_to_python

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_defer_to_python(self):
        # A plugin that measures, but then wants built-in python reporting.
        self.make_file(
            "fairly_odd_plugin.py",
            """\
            # A plugin that claims all the odd lines are executed, and none of
            # the even lines, and then punts reporting off to the built-in
            # Python reporting.
            import coverage.plugin
            class Plugin(coverage.CoveragePlugin):
                def file_tracer(self, filename):
                    return OddTracer(filename)
                def file_reporter(self, filename):
                    return "python"

            class OddTracer(coverage.plugin.FileTracer):
                def __init__(self, filename):
                    self.filename = filename
                def source_filename(self):
                    return self.filename
                def line_number_range(self, frame):
                    lineno = frame.f_lineno
                    if lineno % 2:
                        return (lineno, lineno)
                    else:
                        return (-1, -1)

            def coverage_init(reg, options):
                reg.add_file_tracer(Plugin())
            """,
        )
        self.make_file(
            "unsuspecting.py",
            """\
            a = 1
            b = 2
            c = 3
            d = 4
            e = 5
            f = 6
            """,
        )
        cov = coverage.Coverage(include=["unsuspecting.py"])
        cov.set_option("run:plugins", ["fairly_odd_plugin"])
        self.start_import_stop(cov, "unsuspecting")

        repout = StringIO()
        total = cov.report(file=repout)
        report = repout.getvalue().splitlines()
        expected = [
            "Name              Stmts   Miss  Cover   Missing",
            "-----------------------------------------------",
            "unsuspecting.py       6      3    50%   2, 4, 6",
        ]
        self.assertEqual(report, expected)
        self.assertEqual(total, 50)
开发者ID:jayhetee,项目名称:coveragepy,代码行数:58,代码来源:test_plugins.py

示例10: get_summary_text

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
 def get_summary_text(self, coverage_data, options):
     """Get text output from the SummaryReporter."""
     cov = Coverage()
     cov.start()
     cov.stop()              # pragma: nested
     cov.data = coverage_data
     printer = SummaryReporter(cov, options)
     destination = StringIO()
     printer.report([], destination)
     return destination.getvalue()
开发者ID:iacopy,项目名称:coveragepy,代码行数:12,代码来源:test_summary.py

示例11: test_report_file

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
 def test_report_file(self):
     # The file= argument of coverage.report makes the report go there.
     self.do_report_work("mycode3")
     fout = StringIO()
     coverage.report(["mycode3.py"], file=fout)
     self.assertEqual(self.stdout(), "")
     self.assertEqual(fout.getvalue(), textwrap.dedent("""\
         Name         Stmts   Miss  Cover   Missing
         ------------------------------------------
         mycode3.py       7      3    57%   4-6
         """))
开发者ID:phenoxim,项目名称:coveragepy,代码行数:13,代码来源:test_api.py

示例12: test_empty_files

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_empty_files(self):
        # Shows that empty files like __init__.py are listed as having zero
        # statements, not one statement.
        cov = coverage.Coverage()
        cov.start()
        import usepkgs  # pragma: nested # pylint: disable=import-error,unused-variable
        cov.stop()      # pragma: nested

        repout = StringIO()
        cov.report(file=repout, show_missing=False)

        report = repout.getvalue().replace('\\', '/')
        report = re.sub(r"\s+", " ", report)
        self.assertIn("tests/modules/pkg1/__init__.py 1 0 100%", report)
        self.assertIn("tests/modules/pkg2/__init__.py 0 0 100%", report)
开发者ID:ziadsawalha,项目名称:coveragepy,代码行数:17,代码来源:test_summary.py

示例13: test_empty_files

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def test_empty_files(self):
        # Shows that empty files like __init__.py are listed as having zero
        # statements, not one statement.
        cov = coverage.coverage()
        cov.start()
        import usepkgs                      # pylint: disable=F0401,W0612
        cov.stop()

        repout = StringIO()
        cov.report(file=repout, show_missing=False)

        report = repout.getvalue().replace('\\', '/')
        report = re.sub(r"\s+", " ", report)
        self.assert_("test/modules/pkg1/__init__ 1 0 100%" in report)
        self.assert_("test/modules/pkg2/__init__ 0 0 100%" in report)
开发者ID:calvinchengx,项目名称:coveragepy,代码行数:17,代码来源:test_summary.py

示例14: get_summary_text

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def get_summary_text(self, options):
        """Get text output from the SummaryReporter."""
        self.make_rigged_file("file1.py", 339, 155)
        self.make_rigged_file("file2.py", 13, 3)
        self.make_rigged_file("file3.py", 234, 228)
        self.make_file("doit.py", "import file1, file2, file3")

        cov = Coverage(source=["."], omit=["doit.py"])
        cov.start()
        import doit             # pragma: nested # pylint: disable=import-error, unused-import
        cov.stop()              # pragma: nested
        printer = SummaryReporter(cov, options)
        destination = StringIO()
        printer.report([], destination)
        return destination.getvalue()
开发者ID:hugovk,项目名称:coveragepy,代码行数:17,代码来源:test_summary.py

示例15: f1_debug_output

# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
    def f1_debug_output(self, debug):
        """Runs some code with `debug` option, returns the debug output."""
        # Make code to run.
        self.make_file("f1.py", """\
            def f1(x):
                return x+1

            for i in range(5):
                f1(i)
            """)

        debug_out = StringIO()
        cov = coverage.Coverage(debug=debug)
        cov._debug_file = debug_out
        self.start_import_stop(cov, "f1")

        out_lines = debug_out.getvalue().splitlines()
        return out_lines
开发者ID:d-b-w,项目名称:coveragepy,代码行数:20,代码来源:test_debug.py


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