diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_termlog.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/test/mitmproxy/addons/test_termlog.py b/test/mitmproxy/addons/test_termlog.py index 9d49a8c0..e21aecec 100644 --- a/test/mitmproxy/addons/test_termlog.py +++ b/test/mitmproxy/addons/test_termlog.py @@ -1,18 +1,27 @@ +import sys +import pytest + from mitmproxy.addons import termlog from mitmproxy import log -from mitmproxy.tools import dump +from mitmproxy.tools.dump import Options +from mitmproxy.test import taddons class TestTermLog: - def test_simple(self, capsys): - t = termlog.TermLog() - t.configure(dump.Options(verbosity = 2), set([])) - t.log(log.LogEntry("one", "info")) - t.log(log.LogEntry("two", "debug")) - t.log(log.LogEntry("three", "warn")) - t.log(log.LogEntry("four", "error")) - out, err = capsys.readouterr() - assert "one" in out - assert "two" not in out - assert "three" in out - assert "four" in err + @pytest.mark.usefixtures('capfd') + @pytest.mark.parametrize('outfile, expected_out, expected_err', [ + (None, 'one\nthree\n', 'four\n'), + (sys.stdout, 'one\nthree\nfour\n', ''), + (sys.stderr, '', 'one\nthree\nfour\n'), + ]) + def test_output(self, outfile, expected_out, expected_err, capfd): + t = termlog.TermLog(outfile=outfile) + with taddons.context(options=Options(verbosity=2)) as tctx: + tctx.configure(t) + t.log(log.LogEntry("one", "info")) + t.log(log.LogEntry("two", "debug")) + t.log(log.LogEntry("three", "warn")) + t.log(log.LogEntry("four", "error")) + out, err = capfd.readouterr() + assert out == expected_out + assert err == expected_err |