def generate_coverage_report(coverage_xml, compare_branch, html_report=None, css_file=None, ignore_staged=False, ignore_unstaged=False, exclude=None, src_roots=None): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ diff = GitDiffReporter( compare_branch, git_diff=GitDiffTool(), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, exclude=exclude) xml_roots = [cElementTree.parse(xml_root) for xml_root in coverage_xml] coverage = XmlCoverageReporter(xml_roots, src_roots) # Build a report generator if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlReportGenerator(coverage, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) reporter = StringReportGenerator(coverage, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer # Generate the report reporter.generate_report(output_file) return reporter.total_percent_covered()
def check_diff_committed(self, diff_range_notation, ignore_whitespace): self.tool = GitDiffTool(range_notation=diff_range_notation, ignore_whitespace=ignore_whitespace) self._set_git_diff_output("test output", "") output = self.tool.diff_committed() # Expect that we get the correct output self.assertEqual(output, "test output") # Expect that the correct command was executed expected = [ "git", "-c", "diff.mnemonicprefix=no", "-c", "diff.noprefix=no", "diff", "--no-color", "--no-ext-diff", "-U0", ] if ignore_whitespace: expected.append("--ignore-all-space") expected.append("--ignore-blank-lines") expected.append("origin/master{}HEAD".format(diff_range_notation)) self.subprocess.Popen.assert_called_with(expected, stdout=self.subprocess.PIPE, stderr=self.subprocess.PIPE)
def _inner(diff_range_notation, ignore_whitespace): tool_ = GitDiffTool(range_notation=diff_range_notation, ignore_whitespace=ignore_whitespace) set_git_diff_output("test output", "") output = tool_.diff_committed() # Expect that we get the correct output assert output == "test output" # Expect that the correct command was executed expected = [ "git", "-c", "diff.mnemonicprefix=no", "-c", "diff.noprefix=no", "diff", "--no-color", "--no-ext-diff", "-U0", ] if ignore_whitespace: expected.append("--ignore-all-space") expected.append("--ignore-blank-lines") expected.append(f"origin/master{diff_range_notation}HEAD") subprocess.Popen.assert_called_with(expected, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def generate_quality_report(tool, compare_branch, html_report=None, css_file=None, ignore_unstaged=False): """ Generate the quality report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool(), ignore_unstaged=ignore_unstaged) if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlQualityReportGenerator(tool, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) # Generate the report for stdout reporter = StringQualityReportGenerator(tool, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer reporter.generate_report(output_file) return reporter.total_percent_covered()
def generate_quality_report(tool, compare_branch, html_report=None, css_file=None, ignore_staged=False, ignore_unstaged=False, exclude=None, diff_range_notation=None): """ Generate the quality report, using kwargs from `parse_args()`. """ supported_extensions = getattr(tool, 'supported_extensions', None) \ or tool.driver.supported_extensions diff = GitDiffReporter( compare_branch, git_diff=GitDiffTool(diff_range_notation), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, supported_extensions=supported_extensions, exclude=exclude) if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlQualityReportGenerator(tool, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) # Generate the report for stdout reporter = StringQualityReportGenerator(tool, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer reporter.generate_report(output_file) return reporter.total_percent_covered()
def generate_coverage_report(coverage_xml, compare_branch, html_report=None, ignore_unstaged=False): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool(), ignore_unstaged=ignore_unstaged) xml_roots = [cElementTree.parse(xml_root) for xml_root in coverage_xml] coverage = XmlCoverageReporter(xml_roots) # Build a report generator if html_report is not None: reporter = HtmlReportGenerator(coverage, diff) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) reporter = StringReportGenerator(coverage, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer # Generate the report reporter.generate_report(output_file) return reporter.total_percent_covered()
def generate_quality_report( tool, compare_branch, html_report=None, json_report=None, markdown_report=None, css_file=None, ignore_staged=False, ignore_unstaged=False, include_untracked=False, exclude=None, include=None, diff_range_notation=None, ignore_whitespace=False, quiet=False, ): """ Generate the quality report, using kwargs from `parse_args()`. """ supported_extensions = (getattr(tool, "supported_extensions", None) or tool.driver.supported_extensions) diff = GitDiffReporter( compare_branch, git_diff=GitDiffTool(diff_range_notation, ignore_whitespace), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, include_untracked=include_untracked, supported_extensions=supported_extensions, exclude=exclude, include=include, ) if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlQualityReportGenerator(tool, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) if json_report is not None: reporter = JsonReportGenerator(tool, diff) with open(json_report, "wb") as output_file: reporter.generate_report(output_file) if markdown_report is not None: reporter = MarkdownQualityReportGenerator(tool, diff) with open(markdown_report, "wb") as output_file: reporter.generate_report(output_file) # Generate the report for stdout reporter = StringQualityReportGenerator(tool, diff) output_file = io.BytesIO() if quiet else sys.stdout.buffer reporter.generate_report(output_file) return reporter.total_percent_covered()
def generate_coverage_report( coverage_xml, compare_branch, html_report=None, css_file=None, json_report=None, markdown_report=None, ignore_staged=False, ignore_unstaged=False, exclude=None, src_roots=None, diff_range_notation=None, ignore_whitespace=False, quiet=False, show_uncovered=False, ): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ diff = GitDiffReporter( compare_branch, git_diff=GitDiffTool(diff_range_notation, ignore_whitespace), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, exclude=exclude, ) xml_roots = [etree.parse(xml_root) for xml_root in coverage_xml] coverage = XmlCoverageReporter(xml_roots, src_roots) # Build a report generator if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlReportGenerator(coverage, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) elif json_report is not None: reporter = JsonReportGenerator(coverage, diff) with open(json_report, "wb") as output_file: reporter.generate_report(output_file) elif markdown_report is not None: reporter = MarkdownReportGenerator(coverage, diff) with open(markdown_report, "wb") as output_file: reporter.generate_report(output_file) # Generate the report for stdout reporter = StringReportGenerator(coverage, diff, show_uncovered) output_file = io.BytesIO() if quiet else sys.stdout.buffer # Generate the report reporter.generate_report(output_file) return reporter.total_percent_covered()
def setUp(self): # Create mock subprocess to simulate `git diff` self.process = mock.Mock() self.subprocess = mock.patch('diff_cover.command_runner.subprocess').start() self.subprocess.Popen.return_value = self.process # Create the git diff tool self.tool = GitDiffTool()
def setUp(self): # Create mock subprocess to simulate `git diff` self.subprocess = mock.Mock() self.process = mock.Mock() self.subprocess.Popen = mock.Mock(return_value=self.process) self.process.communicate = mock.Mock() # Create the git diff tool self.tool = GitDiffTool(subprocess_mod=self.subprocess)
def setUp(self): # Create mock subprocess to simulate `git diff` self.process = mock.Mock() self.process.returncode = 0 self.subprocess = mock.patch('diff_cover.command_runner.subprocess').start() self.subprocess.Popen.return_value = self.process self.addCleanup(mock.patch.stopall) # Create the git diff tool self.tool = GitDiffTool('...')
def setUp(self): # Create mock subprocess to simulate `git diff` self.process = mock.Mock() self.process.returncode = 0 self.subprocess = mock.patch( "diff_cover.command_runner.subprocess").start() self.subprocess.Popen.return_value = self.process self.addCleanup(mock.patch.stopall) # Create the git diff tool self.tool = GitDiffTool(range_notation="...", ignore_whitespace=False)
def generate_coverage_report(coverage_xml, compare_branch, html_report=None, css_file=None, ignore_staged=False, ignore_unstaged=False, exclude=None): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool(), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, exclude=exclude) xml_roots = [cElementTree.parse(xml_root) for xml_root in coverage_xml] clover_xml_roots = [ clover_xml for clover_xml in xml_roots if clover_xml.findall('.[@clover]') ] cobertura_xml_roots = [ cobertura_xml for cobertura_xml in xml_roots if cobertura_xml.findall('.[@line-rate]') ] if clover_xml_roots and cobertura_xml_roots: raise TypeError("Can't handle mixed coverage reports") elif clover_xml_roots: coverage = CloverXmlCoverageReporter(clover_xml_roots) elif cobertura_xml_roots: coverage = XmlCoverageReporter(cobertura_xml_roots) # Build a report generator if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlReportGenerator(coverage, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) reporter = StringReportGenerator(coverage, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer # Generate the report reporter.generate_report(output_file) return reporter.total_percent_covered()
def generate_quality_report(tool, compare_branch, html_report=None): """ Generate the quality report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool()) if html_report is not None: reporter = HtmlQualityReportGenerator(tool, diff) output_file = open(html_report, "w") else: reporter = StringQualityReportGenerator(tool, diff) output_file = sys.stdout reporter.generate_report(output_file)
def generate_quality_report(tool, compare_branch, html_report=None): """ Generate the quality report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool()) if html_report is not None: reporter = HtmlQualityReportGenerator(tool, diff) output_file = open(html_report, "wb") else: reporter = StringQualityReportGenerator(tool, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer reporter.generate_report(output_file) return reporter.total_percent_covered()
def check_diff_committed(self, diff_range_notation): self.tool = GitDiffTool(diff_range_notation) self._set_git_diff_output('test output', '') output = self.tool.diff_committed() # Expect that we get the correct output self.assertEqual(output, 'test output') # Expect that the correct command was executed expected = ['git', '-c', 'diff.mnemonicprefix=no', '-c', 'diff.noprefix=no', 'diff', 'origin/master{}HEAD'.format(diff_range_notation), '--no-color', '--no-ext-diff'] self.subprocess.Popen.assert_called_with( expected, stdout=self.subprocess.PIPE, stderr=self.subprocess.PIPE )
def generate_coverage_report(coverage_xml, compare_branch, html_report=None): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ diff = GitDiffReporter(compare_branch, git_diff=GitDiffTool()) xml_roots = [etree.parse(xml_root) for xml_root in coverage_xml] git_path = GitPathTool(os.getcwd()) coverage = XmlCoverageReporter(xml_roots, git_path) # Build a report generator if html_report is not None: reporter = HtmlReportGenerator(coverage, diff) output_file = open(html_report, "w") else: reporter = StringReportGenerator(coverage, diff) output_file = sys.stdout # Generate the report reporter.generate_report(output_file)
def check_diff_committed(self, diff_range_notation): self.tool = GitDiffTool(diff_range_notation) self._set_git_diff_output("test output", "") output = self.tool.diff_committed() # Expect that we get the correct output self.assertEqual(output, "test output") # Expect that the correct command was executed expected = [ "git", "-c", "diff.mnemonicprefix=no", "-c", "diff.noprefix=no", "diff", "origin/master{}HEAD".format(diff_range_notation), "--no-color", "--no-ext-diff", "-U0", ] self.subprocess.Popen.assert_called_with(expected, stdout=self.subprocess.PIPE, stderr=self.subprocess.PIPE)
def tool(): return GitDiffTool(range_notation="...", ignore_whitespace=False)
def generate_coverage_report(coverage_xml, compare_branch, html_report=None, css_file=None, json_report=None, ignore_staged=False, ignore_unstaged=False, exclude=None, src_roots=None, diff_range_notation=None, target_dir=None, diff_json=None): """ Generate the diff coverage report, using kwargs from `parse_args()`. """ if target_dir: class FileDiffReporter(GitDiffReporter): def __init__(self, *args, **kwargs): self.target_dir = kwargs.pop("td") super(FileDiffReporter, self).__init__(*args, **kwargs) def _git_diff(self): def compare(left, right): d = difile.Difile() result = d.compare_dir(left, right) diff_result = dict() for each_file in result: if not each_file: continue key = each_file[0].file_path.as_posix() if key.startswith(str(self.target_dir)): key = key.replace(str(self.target_dir) + "/", "") if key not in diff_result: diff_result[key] = [] for each_line in each_file: diff_result[key].append(each_line.line_no) return diff_result return compare(src_roots[0], self.target_dir) diff = FileDiffReporter( compare_branch, git_diff=GitDiffTool(diff_range_notation), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, exclude=exclude, td=target_dir) else: diff = GitDiffReporter( compare_branch, git_diff=GitDiffTool(diff_range_notation), ignore_staged=ignore_staged, ignore_unstaged=ignore_unstaged, exclude=exclude) xml_roots = [etree.parse(xml_root) for xml_root in coverage_xml] coverage = XmlCoverageReporter(xml_roots, src_roots) if diff_json: diff_dict = diff._git_diff() with open(diff_json, "w") as f: json.dump(diff_dict, f) # Build a report generator if html_report is not None: css_url = css_file if css_url is not None: css_url = os.path.relpath(css_file, os.path.dirname(html_report)) reporter = HtmlReportGenerator(coverage, diff, css_url=css_url) with open(html_report, "wb") as output_file: reporter.generate_report(output_file) if css_file is not None: with open(css_file, "wb") as output_file: reporter.generate_css(output_file) elif json_report is not None: reporter = JsonReportGenerator(coverage, diff) with open(json_report, "wb") as output_file: reporter.generate_report(output_file) reporter = StringReportGenerator(coverage, diff) output_file = sys.stdout if six.PY2 else sys.stdout.buffer # Generate the report reporter.generate_report(output_file) return reporter.total_percent_covered()