def print_results(self, results, output, verbosity): """Print results to a given output stream. :param InterrogateResults results: results of docstring coverage interrogation. :param output: filename to output results. If ``None``, uses ``sys.stdout``. :type output: ``str`` or ``None`` :param int verbosity: level of detail to print out (``0``-``2``). """ with utils.smart_open(output, "w") as f: tw = py_io.TerminalWriter(file=f) results = self._sort_results(results) if verbosity > 0: base = self._get_header_base() tw.sep( "=", "Coverage for {}".format(base), fullwidth=utils.TERMINAL_WIDTH, ) if verbosity > 1: self._print_detailed_table(results, tw) if verbosity > 0: self._print_summary_table(results, tw) status = "PASSED" if results.ret_code > 0: status = "FAILED" status_line = "RESULT: {} (minimum: {}%, actual: {:.1f}%)".format( status, self.config.fail_under, results.perc_covered) if verbosity > 0: tw.sep("-", title=status_line, fullwidth=utils.TERMINAL_WIDTH) else: tw.line(status_line)
def test_smart_open(filename, mocker): """Handles both opening a file and stdout in the same manner.""" m_open = mocker.mock_open() mock_open = mocker.patch("interrogate.utils.open", m_open) with utils.smart_open(filename, fmode="r") as act_ret: pass if filename and filename != "-": mock_open.assert_called_once_with(filename, "r") assert act_ret.closed else: mock_open.assert_not_called() assert act_ret == sys.stdout
def print_results(self, results, output, verbosity): """Print results to a given output stream. :param InterrogateResults results: results of docstring coverage interrogation. :param output: filename to output results. If ``None``, uses ``sys.stdout``. :type output: ``str`` or ``None`` :param int verbosity: level of detail to print out (``0``-``2``). """ with utils.smart_open(output, "w") as f: self.output_formatter = utils.OutputFormatter( file=f, config=self.config ) results = self._sort_results(results) if verbosity > 0: base = self._get_header_base() self.output_formatter.tw.sep( "=", "Coverage for {}".format(base), fullwidth=self.output_formatter.TERMINAL_WIDTH, ) if verbosity > 1: self._print_detailed_table(results) if verbosity > 0: self._print_summary_table(results) status, color = "PASSED", {"green": True} if results.ret_code > 0: status, color = "FAILED", {"red": True} if self.output_formatter.should_markup() is False: color = {} status_line = "RESULT: {} (minimum: {}%, actual: {:.1f}%)".format( status, self.config.fail_under, results.perc_covered ) if verbosity > 0: self.output_formatter.tw.sep( "-", title=status_line, fullwidth=self.output_formatter.TERMINAL_WIDTH, **color ) else: self.output_formatter.tw.line(status_line)