From 6780e5025a971e27f921aecf92ccf4ed5a05c7e0 Mon Sep 17 00:00:00 2001 From: kira0204 Date: Tue, 10 Apr 2018 08:33:40 +0530 Subject: Handling user script exceptions, fix #2839 --- test/mitmproxy/addons/test_script.py | 23 +++++++++++++++------- test/mitmproxy/data/addonscripts/recorder/error.py | 7 +++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/mitmproxy/data/addonscripts/recorder/error.py (limited to 'test') diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 3f0ce68c..96e19841 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -12,18 +12,27 @@ from mitmproxy.test import tflow from mitmproxy.test import tutils -def test_load_script(): - ns = script.load_script( - tutils.test_data.path( - "mitmproxy/data/addonscripts/recorder/recorder.py" +@pytest.mark.asyncio +async def test_load_script(): + with taddons.context() as tctx: + ns = script.load_script( + tutils.test_data.path( + "mitmproxy/data/addonscripts/recorder/recorder.py" + ) ) - ) - assert ns.addons + assert ns.addons - with pytest.raises(FileNotFoundError): script.load_script( "nonexistent" ) + assert await tctx.master.await_log("No such file or directory") + + script.load_script( + tutils.test_data.path( + "mitmproxy/data/addonscripts/recorder/error.py" + ) + ) + assert await tctx.master.await_log("invalid syntax") def test_load_fullname(): diff --git a/test/mitmproxy/data/addonscripts/recorder/error.py b/test/mitmproxy/data/addonscripts/recorder/error.py new file mode 100644 index 00000000..2e7e648a --- /dev/null +++ b/test/mitmproxy/data/addonscripts/recorder/error.py @@ -0,0 +1,7 @@ +""" +This file is intended to have syntax errors for test purposes +""" + +impotr recorder # Intended Syntax Error + +addons = [recorder.Recorder("e")] -- cgit v1.2.3