diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-08-03 11:06:29 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-08-03 11:06:29 +1200 |
commit | 62088a666156f70b65d331bc002a946e58c76013 (patch) | |
tree | b9d6c9c8ccaa546dcfe9eabd193d7cbf21b69411 /test | |
parent | a817db5bd6b55cfb86de24cf7bc8aa8bb400653d (diff) | |
download | mitmproxy-62088a666156f70b65d331bc002a946e58c76013.tar.gz mitmproxy-62088a666156f70b65d331bc002a946e58c76013.tar.bz2 mitmproxy-62088a666156f70b65d331bc002a946e58c76013.zip |
Start stubbing out a much more powerful script architecture.
Diffstat (limited to 'test')
-rw-r--r-- | test/plugins/a.py | 9 | ||||
-rw-r--r-- | test/plugins/syntaxerr.py | 3 | ||||
-rw-r--r-- | test/test_plugins.py | 35 |
3 files changed, 47 insertions, 0 deletions
diff --git a/test/plugins/a.py b/test/plugins/a.py new file mode 100644 index 00000000..0a21b619 --- /dev/null +++ b/test/plugins/a.py @@ -0,0 +1,9 @@ + +var = 0 +def here(ctx): + global var + var += 1 + return var + +def errargs(): + pass diff --git a/test/plugins/syntaxerr.py b/test/plugins/syntaxerr.py new file mode 100644 index 00000000..219d6b84 --- /dev/null +++ b/test/plugins/syntaxerr.py @@ -0,0 +1,3 @@ + + +a + diff --git a/test/test_plugins.py b/test/test_plugins.py new file mode 100644 index 00000000..135d93ce --- /dev/null +++ b/test/test_plugins.py @@ -0,0 +1,35 @@ +import os +from libmproxy import plugins, flow +import libpry + +class uPlugin(libpry.AutoTree): + def test_simple(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + + p = plugins.Plugin(os.path.join("plugins", "a.py"), fm) + assert "here" in p.ns + assert p.run("here") == (True, 1) + assert p.run("here") == (True, 2) + + ret = p.run("errargs") + assert not ret[0] + assert len(ret[1]) == 2 + + # Check reload + p.load() + assert p.run("here") == (True, 1) + + def test_err(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + + libpry.raises(IOError, plugins.Plugin, "nonexistent", fm) + libpry.raises(SyntaxError, plugins.Plugin, os.path.join("plugins", "syntaxerr.py"), fm) + + + +tests = [ + uPlugin(), +] + |