def _render_results(self, results, **kwargs): """Render a given set of result objects into their related string form.""" with tempfile.TemporaryFile() as f: with reporters.FancyReporter(out=PlainTextFormatter(f), **kwargs) as reporter: for result in sorted(results): reporter.report(result) f.seek(0) output = f.read().decode() return output
def test_replay(self, capsys): result = ProfileWarning('profile warning: foo') for reporter_cls in (reporters.BinaryPickleStream, reporters.JsonStream): with tempfile.NamedTemporaryFile() as f: out = PlainTextFormatter(f) with reporter_cls(out) as reporter: reporter.report(result) with patch('sys.argv', self.args + ['-R', 'StrReporter', f.name]): with pytest.raises(SystemExit) as excinfo: self.script() out, err = capsys.readouterr() assert not err assert out == 'profile warning: foo\n'
def execute_main(self, *a, **kw): config = self.parse(*a, **kw) out = PlainTextFormatter(BytesIO()) ret = config.main_func(config, out, out) return ret, config, out
def mk_reporter(self, **kwargs): out = PlainTextFormatter(sys.stdout) return self.reporter_cls(out, **kwargs)