diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-01-25 17:45:45 +0100 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-01-25 17:50:07 +0100 |
commit | 3028e06fd2b2c9d95c49ca790dc79bab4fc81dae (patch) | |
tree | cd0a98c4cf71817b6940fc0ae85fa566b08f4d5c /test | |
parent | ab45e4d183fe19a15cbe58f1dfbbde041e7c88bd (diff) | |
download | mitmproxy-3028e06fd2b2c9d95c49ca790dc79bab4fc81dae.tar.gz mitmproxy-3028e06fd2b2c9d95c49ca790dc79bab4fc81dae.tar.bz2 mitmproxy-3028e06fd2b2c9d95c49ca790dc79bab4fc81dae.zip |
simplify termlog outfile handling
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 |