def _check_config(self, filename, own_rc):
        section = 'report' if own_rc else 'coverage:report'

        # Force own rc for pre 4.4.1
        if LooseVersion(coverage_version) < LooseVersion('4.4.1'):
            self.make_file(
                filename, """\
                [report]
                ignore_errors = true
                """)
        else:
            self.make_file(
                filename, """\
                [{}]
                ignore_errors = true
                """.format(section))

        debug_out = StringIO()
        cov = Coverage(config_file=filename, debug=['sys'])
        assert cov.config.get_option('report:ignore_errors') is True
        cov._debug_file = debug_out

        self.make_file(
            filename, """\
            [{}]
            ignore_errors = off
            """.format(section))

        cov.set_option('run:plugins', ['coverage_config_reload_plugin'])
        cov.start()
        cov.stop()

        assert cov.config.get_option('report:ignore_errors') is False
    def test_plugin_init(self):
        self.make_file('coveragerc_test_config', '')

        debug_out = StringIO()
        cov = Coverage(config_file='coveragerc_test_config', debug=['sys'])
        cov._debug_file = debug_out
        cov.set_option('run:plugins', ['coverage_config_reload_plugin'])
        cov.start()
        cov.stop()

        out_lines = [
            line.strip() for line in debug_out.getvalue().splitlines()
        ]
        self.assertIn('plugins.file_tracers: -none-', out_lines)

        expected_end = [
            '-- sys: coverage_config_reload_plugin.ConfigReloadPlugin -----',
            'configreload: True',
            '-- end -------------------------------------------------------',
        ]
        self.assertEqual(expected_end, out_lines[-len(expected_end):])

        if LooseVersion(coverage_version) >= LooseVersion('4.6'):
            self.assertIn(
                'plugins.configurers: coverage_config_reload_plugin.ConfigReloadPlugin',
                out_lines)
Beispiel #3
0
    def get_summary_text(self, *options):
        """Get text output from the SummaryReporter.

        The arguments are tuples: (name, value) for Coverage.set_option.
        """
        self.make_rigged_file("file1.py", 339, 155)
        self.make_rigged_file("file2.py", 13, 3)
        self.make_rigged_file("file10.py", 234, 228)
        self.make_file("doit.py", "import file1, file2, file10")

        cov = Coverage(source=["."], omit=["doit.py"])
        self.start_import_stop(cov, "doit")
        for name, value in options:
            cov.set_option(name, value)
        printer = SummaryReporter(cov)
        destination = io.StringIO()
        printer.report([], destination)
        return destination.getvalue()
Beispiel #4
0
    def test_reload_plugin_init(self):
        self._reset_env()

        self.make_file(
            '.coveragerc', """\
            [run]
            plugins = coverage_env_plugin, coverage_config_reload_plugin
            [coverage_env_plugin]
            markers = True
            [report]
            exclude_lines =
              pragma ${OS_NAME}: no cover
            """)

        debug_out = StringIO()
        cov = Coverage(config_file='.coveragerc', debug=['sys'])
        cov._debug_file = debug_out
        cov.set_option(
            'run:plugins',
            ['coverage_env_plugin', 'coverage_config_reload_plugin'])
        cov.start()
        cov.stop()

        assert cov.config.get_option('coverage_env_plugin:markers') == 'True'

        out_lines = [
            line.strip() for line in debug_out.getvalue().splitlines()
        ]
        self.assertIn('plugins.file_tracers: -none-', out_lines)

        if LooseVersion(config_reload_version) >= LooseVersion('0.3.0'):
            expected_end = [
                '-- sys: coverage_config_reload_plugin.ConfigReloadPlugin -----',
                'configreload: True',
                '-- end -------------------------------------------------------',
            ]
            self.assertEqual(expected_end, out_lines[-len(expected_end):])

            if LooseVersion(coverage_version) >= LooseVersion('4.6'):
                self.assertIn(
                    'plugins.configurers: coverage_config_reload_plugin.ConfigReloadPlugin',
                    out_lines)
Beispiel #5
0
    def get_summary_text(self, *options):
        """Get text output from the SummaryReporter.

        The arguments are tuples: (name, value) for Coverage.set_option.
        """
        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
        for name, value in options:
            cov.set_option(name, value)
        printer = SummaryReporter(cov)
        destination = StringIO()
        printer.report([], destination)
        return destination.getvalue()
    def test_no_reload_plugin(self):
        debug_out = StringIO()
        cov = Coverage(debug=['sys'])
        cov._debug_file = debug_out
        cov.set_option('run:plugins', [])
        cov.start()
        cov.stop()

        out_lines = [
            line.strip() for line in debug_out.getvalue().splitlines()
        ]
        self.assertIn('plugins.file_tracers: -none-', out_lines)

        expected_end = [
            '-- end -------------------------------------------------------',
        ]
        self.assertEqual(expected_end, out_lines[-len(expected_end):])

        if LooseVersion(coverage_version) >= LooseVersion('4.6'):
            self.assertIn('plugins.configurers: -none-', out_lines)

        assert cov.config.get_option('report:ignore_errors') is False