From af9442a9bae834c82d50d3a9f31796377c29a9ad Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Mon, 7 Mar 2016 22:52:55 +0530 Subject: Add contextmanager to load an example --- test/mitmproxy/test_examples.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index a76d56a8..3244ebf2 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -1,4 +1,6 @@ import glob +import os +from contextlib import contextmanager from mitmproxy import utils, script from mitmproxy.proxy import config @@ -6,25 +8,28 @@ from netlib import tutils as netutils from netlib.http import Headers from . import tservers, tutils -from examples import ( - add_header, - custom_contentviews, - iframe_injector, - modify_form, - modify_querystring, - modify_response_body, - redirect_requests, -) +example_dir = utils.Data(__name__).path("../../examples") + + +@contextmanager +def example(command): + command = os.path.join(example_dir, command) + # tmaster = tservers.TestMaster(config.ProxyConfig()) + # ctx = script.ScriptContext(tmaster) + ctx = DummyContext() + s = script.Script(command, ctx) + yield s + s.unload() class DummyContext(object): + """Emulate script.ScriptContext() functionality.""" def log(self, *args, **kwargs): pass def test_load_scripts(): - example_dir = utils.Data(__name__).path("../../examples") scripts = glob.glob("%s/*.py" % example_dir) tmaster = tservers.TestMaster(config.ProxyConfig()) -- cgit v1.2.3