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


Python backward.StringIO类代码示例

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


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

示例1: test_plugin_with_no_sys_info

    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,代码行数:25,代码来源:test_plugins.py

示例2: pretend_to_be_pytestcov

    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,代码行数:31,代码来源:test_api.py

示例3: test_plugin_with_no_sys_info

    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,代码行数:25,代码来源:test_plugins.py

示例4: setUp

    def setUp(self):
        if self.run_in_temp_dir:
            # Create a temporary directory.
            self.noise = str(random.random())[2:]
            self.temp_root = os.path.join(tempfile.gettempdir(), 'test_cover')
            self.temp_dir = os.path.join(self.temp_root, self.noise)
            os.makedirs(self.temp_dir)
            self.old_dir = os.getcwd()
            os.chdir(self.temp_dir)


            # Modules should be importable from this temp directory.
            self.old_syspath = sys.path[:]
            sys.path.insert(0, '')

            # Keep a counter to make every call to check_coverage unique.
            self.n = 0

        # Record environment variables that we changed with set_environ.
        self.environ_undos = {}

        # 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

        # Record sys.modules here so we can restore it in tearDown.
        self.old_modules = dict(sys.modules)
开发者ID:sbook,项目名称:coveragepy,代码行数:34,代码来源:coveragetest.py

示例5: get_report

 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,代码行数:7,代码来源:test_summary.py

示例6: StdStreamCapturingMixin

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,代码行数:32,代码来源:test_helpers.py

示例7: test_plugin_sys_info

    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,代码行数:27,代码来源:test_plugins.py

示例8: coverage_usepkgs

 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,代码行数:9,代码来源:test_api.py

示例9: coverage_usepkgs

 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,代码行数:9,代码来源:test_api.py

示例10: test_defer_to_python

    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,代码行数:56,代码来源:test_plugins.py

示例11: get_summary_text

 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,代码行数:10,代码来源:test_summary.py

示例12: test_read_and_write_are_opposites

    def test_read_and_write_are_opposites(self):
        covdata1 = CoverageData()
        covdata1.add_arcs(ARCS_3)
        stringio = StringIO()
        covdata1.write_fileobj(stringio)

        stringio.seek(0)
        covdata2 = CoverageData()
        covdata2.read_fileobj(stringio)
        self.assert_arcs3_data(covdata2)
开发者ID:mociepka,项目名称:coveragepy,代码行数:10,代码来源:test_data.py

示例13: test_report_file

 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,代码行数:11,代码来源:test_api.py

示例14: setUp

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

        if _TEST_NAME_FILE:
            f = open(_TEST_NAME_FILE, "w")
            f.write("%s_%s" % (self.__class__.__name__, self._testMethodName))
            f.close()

        # Tell newer unittest implementations to print long helpful messages.
        self.longMessage = True

        # tearDown will restore the original sys.path
        self.old_syspath = sys.path[:]

        if self.run_in_temp_dir:
            # Create a temporary directory.
            self.noise = str(random.random())[2:]
            self.temp_root = os.path.join(tempfile.gettempdir(), 'test_cover')
            self.temp_dir = os.path.join(self.temp_root, self.noise)
            os.makedirs(self.temp_dir)
            self.old_dir = os.getcwd()
            os.chdir(self.temp_dir)

            # Modules should be importable from this temp directory.  We don't
            # use '' because we make lots of different temp directories and
            # nose's caching importer can get confused.  The full path prevents
            # problems.
            sys.path.insert(0, os.getcwd())

            # Keep a counter to make every call to check_coverage unique.
            self.n = 0

        # Record environment variables that we changed with set_environ.
        self.environ_undos = {}

        # 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

        # Record sys.modules here so we can restore it in tearDown.
        self.old_modules = dict(sys.modules)

        class_behavior = self.class_behavior()
        class_behavior.tests += 1
        class_behavior.test_method_made_any_files = False
        class_behavior.temp_dir = self.run_in_temp_dir
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:53,代码来源:coveragetest.py

示例15: test_empty_files

    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,代码行数:15,代码来源:test_summary.py


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