コード例 #1
0
    def _src_path_stats(self, src_path):

        stats = super()._src_path_stats(src_path)

        # Load source snippets (if the report will display them)
        # If we cannot load the file, then fail gracefully
        formatted_snippets = {"html": [], "markdown": []}
        if self.INCLUDE_SNIPPETS:
            try:
                formatted_snippets = Snippet.load_formatted_snippets(
                    src_path, stats["violation_lines"])
            except OSError:
                pass

        stats.update({
            "snippets_html":
            formatted_snippets["html"],
            "snippets_markdown":
            formatted_snippets["markdown"],
            "violation_lines":
            TemplateReportGenerator.combine_adjacent_lines(
                stats["violation_lines"]),
        })

        return stats
コード例 #2
0
    def _src_path_stats(self, src_path):

        stats = super()._src_path_stats(src_path)

        # Load source snippets (if the report will display them)
        # If we cannot load the file, then fail gracefully
        formatted_snippets = {"html": [], "markdown": [], "terminal": []}
        if self.include_snippets:
            with contextlib.suppress(OSError):
                formatted_snippets = Snippet.load_formatted_snippets(
                    src_path, stats["violation_lines"])

        stats.update({
            "snippets_html":
            formatted_snippets["html"],
            "snippets_markdown":
            formatted_snippets["markdown"],
            "snippets_terminal":
            formatted_snippets["terminal"],
            "violation_lines":
            TemplateReportGenerator.combine_adjacent_lines(
                stats["violation_lines"]),
        })

        return stats
コード例 #3
0
def _compare_snippets_output(format_, filename, violations,
                             expected_out_filename):
    # One higher-level test to make sure
    # the snippets are being rendered correctly
    formatted_snippets = Snippet.load_formatted_snippets(filename, violations)
    snippets_selected = "\n\n".join(formatted_snippets[format_])
    # Load the fixture for the expected contents
    expected_path = fixture_path(expected_out_filename)
    with open(expected_path, encoding="utf-8") as fixture_file:
        expected = fixture_file.read()
        if isinstance(expected, bytes):
            expected = expected.decode("utf-8")

    # Check that we got what we expected
    assert expected.strip() == snippets_selected.strip()
コード例 #4
0
    def _compare_snippets_output(self, format, filename, violations,
                                 expected_out_filename):
        # Need to be in the fixture directory
        # so the source path is displayed correctly
        old_cwd = os.getcwd()
        self.addCleanup(lambda: os.chdir(old_cwd))
        os.chdir(fixture_path(""))

        # One higher-level test to make sure
        # the snippets are being rendered correctly
        formatted_snippets = Snippet.load_formatted_snippets(
            filename, violations)
        snippets_selected = "\n\n".join(formatted_snippets[format])
        # Load the fixture for the expected contents
        expected_path = fixture_path(expected_out_filename)
        with open(expected_path, encoding="utf-8") as fixture_file:
            expected = fixture_file.read()
            if isinstance(expected, bytes):
                expected = expected.decode("utf-8")

        # Check that we got what we expected
        assert_long_str_equal(expected, snippets_selected, strip=True)