def _context(self): """ Return the context to pass to the template. The context is a dict of the form: { 'css_url': CSS_URL, 'report_name': REPORT_NAME, 'diff_name': DIFF_NAME, 'src_stats': {SRC_PATH: { 'percent_covered': PERCENT_COVERED, 'violation_lines': [LINE_NUM, ...] }, ... } 'total_num_lines': TOTAL_NUM_LINES, 'total_num_violations': TOTAL_NUM_VIOLATIONS, 'total_percent_covered': TOTAL_PERCENT_COVERED } """ # Include snippet style info if we're displaying # source code snippets if self.INCLUDE_SNIPPETS: snippet_style = Snippet.style_defs() else: snippet_style = None context = super().report_dict() context.update({ "css_url": self.css_url, "snippet_style": snippet_style }) return context
def test_style_defs(self): style_str = Snippet.style_defs() expected_styles = load_fixture(self.FIXTURES['style']).strip() # Check that a sample of the styles are present # (use only a sample to make the test more robust # against Pygment changes). for expect_line in expected_styles.split('\n'): self.assertIn(expect_line, style_str)
def test_style_defs(): style_str = Snippet.style_defs() expected_styles = load_fixture("snippet.css").strip() # Check that a sample of the styles are present # (use only a sample to make the test more robust # against Pygments changes). for expect_line in expected_styles.split("\n"): assert expect_line in style_str
def _context(self): """ Return the context to pass to the template. The context is a dict of the form: { 'css_url': CSS_URL, 'report_name': REPORT_NAME, 'diff_name': DIFF_NAME, 'src_stats': {SRC_PATH: { 'percent_covered': PERCENT_COVERED, 'violation_lines': [LINE_NUM, ...] }, ... } 'total_num_lines': TOTAL_NUM_LINES, 'total_num_violations': TOTAL_NUM_VIOLATIONS, 'total_percent_covered': TOTAL_PERCENT_COVERED } """ # Calculate the information to pass to the template src_stats = { src: self._src_path_stats(src) for src in self.src_paths() } # Include snippet style info if we're displaying # source code snippets if self.INCLUDE_SNIPPETS: snippet_style = Snippet.style_defs() else: snippet_style = None return { 'css_url': self.css_url, 'report_name': self.coverage_report_name(), 'diff_name': self.diff_report_name(), 'src_stats': src_stats, 'total_num_lines': self.total_num_lines(), 'total_num_violations': self.total_num_violations(), 'total_percent_covered': self.total_percent_covered(), 'snippet_style': snippet_style }
def _context(self): """ Return the context to pass to the template. The context is a dict of the form: { 'css_url': CSS_URL, 'report_name': REPORT_NAME, 'diff_name': DIFF_NAME, 'src_stats': {SRC_PATH: { 'percent_covered': PERCENT_COVERED, 'violation_lines': [LINE_NUM, ...] }, ... } 'total_num_lines': TOTAL_NUM_LINES, 'total_num_violations': TOTAL_NUM_VIOLATIONS, 'total_percent_covered': TOTAL_PERCENT_COVERED } """ # Calculate the information to pass to the template src_stats = dict( (src, self._src_path_stats(src)) for src in self.src_paths() ) # Include snippet style info if we're displaying # source code snippets if self.INCLUDE_SNIPPETS: snippet_style = Snippet.style_defs() else: snippet_style = None return { 'css_url': self.css_url, 'report_name': self.coverage_report_name(), 'diff_name': self.diff_report_name(), 'src_stats': src_stats, 'total_num_lines': self.total_num_lines(), 'total_num_violations': self.total_num_violations(), 'total_percent_covered': self.total_percent_covered(), 'snippet_style': snippet_style }