aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_script.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_script.py')
-rw-r--r--test/test_script.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/test_script.py b/test/test_script.py
new file mode 100644
index 00000000..f6cfcced
--- /dev/null
+++ b/test/test_script.py
@@ -0,0 +1,51 @@
+import os
+from libmproxy import script, flow
+import libpry
+
+class uScript(libpry.AutoTree):
+ def test_simple(self):
+ s = flow.State()
+ fm = flow.FlowMaster(None, s)
+
+ p = script.Script(os.path.join("scripts", "a.py"), fm)
+ p.load()
+ 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)
+
+ s = script.Script("nonexistent", fm)
+ libpry.raises(
+ script.ScriptError,
+ s.load
+ )
+
+ s = script.Script(os.path.join("scripts", "syntaxerr.py"), fm)
+ libpry.raises(
+ script.ScriptError,
+ s.load
+ )
+
+ s = script.Script(os.path.join("scripts", "loaderr.py"), fm)
+ libpry.raises(
+ script.ScriptError,
+ s.load
+ )
+
+
+
+tests = [
+ uScript(),
+]
+