aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-07-29 21:08:24 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-07-30 02:03:26 +0200
commit3b8e3e4aa9cb39c8942cf9871ea84feb925e2aee (patch)
treeef6af26cb6207ca2911c2e45b84d2b80a01b799b /test
parent9ffd42edeacb19c3961840289bb25eaeca5991a5 (diff)
downloadmitmproxy-3b8e3e4aa9cb39c8942cf9871ea84feb925e2aee.tar.gz
mitmproxy-3b8e3e4aa9cb39c8942cf9871ea84feb925e2aee.tar.bz2
mitmproxy-3b8e3e4aa9cb39c8942cf9871ea84feb925e2aee.zip
make load_script pure
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_script.py60
-rw-r--r--test/mitmproxy/test_addonmanager.py2
2 files changed, 28 insertions, 34 deletions
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index b7e6c82a..64fd9505 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -1,6 +1,5 @@
import traceback
import sys
-import time
import os
import pytest
@@ -14,20 +13,17 @@ from mitmproxy.addons import script
def test_load_script():
- with taddons.context() as tctx:
- ns = script.load_script(
- tctx.ctx(),
- tutils.test_data.path(
- "mitmproxy/data/addonscripts/recorder/recorder.py"
- )
+ ns = script.load_script(
+ tutils.test_data.path(
+ "mitmproxy/data/addonscripts/recorder/recorder.py"
)
- assert ns.addons
+ )
+ assert ns.addons
- ns = script.load_script(
- tctx.ctx(),
+ with pytest.raises(FileNotFoundError):
+ script.load_script(
"nonexistent"
)
- assert not ns
def test_load_fullname():
@@ -36,22 +32,19 @@ def test_load_fullname():
This only succeeds if they get assigned different basenames.
"""
- with taddons.context() as tctx:
- ns = script.load_script(
- tctx.ctx(),
- tutils.test_data.path(
- "mitmproxy/data/addonscripts/addon.py"
- )
+ ns = script.load_script(
+ tutils.test_data.path(
+ "mitmproxy/data/addonscripts/addon.py"
)
- assert ns.addons
- ns2 = script.load_script(
- tctx.ctx(),
- tutils.test_data.path(
- "mitmproxy/data/addonscripts/same_filename/addon.py"
- )
+ )
+ assert ns.addons
+ ns2 = script.load_script(
+ tutils.test_data.path(
+ "mitmproxy/data/addonscripts/same_filename/addon.py"
)
- assert ns.name != ns2.name
- assert not hasattr(ns2, "addons")
+ )
+ assert ns.name != ns2.name
+ assert not hasattr(ns2, "addons")
def test_script_print_stdout():
@@ -59,7 +52,6 @@ def test_script_print_stdout():
with mock.patch('mitmproxy.ctx.log.warn') as mock_warn:
with addonmanager.safecall():
ns = script.load_script(
- tctx.ctx(),
tutils.test_data.path(
"mitmproxy/data/addonscripts/print.py"
)
@@ -103,11 +95,13 @@ class TestScript:
sc = script.Script(str(f))
tctx.configure(sc)
sc.tick()
- for _ in range(3):
- sc.last_load, sc.last_mtime = 0, 0
- sc.tick()
- time.sleep(0.1)
- tctx.master.has_log("Loading")
+ assert tctx.master.has_log("Loading")
+ tctx.master.clear()
+ assert not tctx.master.has_log("Loading")
+
+ sc.last_load, sc.last_mtime = 0, 0
+ sc.tick()
+ assert tctx.master.has_log("Loading")
def test_exception(self):
with taddons.context() as tctx:
@@ -121,8 +115,8 @@ class TestScript:
f = tflow.tflow(resp=True)
tctx.master.addons.trigger("request", f)
- tctx.master.has_log("ValueError: Error!")
- tctx.master.has_log("error.py")
+ assert tctx.master.has_log("ValueError: Error!")
+ assert tctx.master.has_log("error.py")
def test_addon(self):
with taddons.context() as tctx:
diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py
index 678bc1b7..7295a468 100644
--- a/test/mitmproxy/test_addonmanager.py
+++ b/test/mitmproxy/test_addonmanager.py
@@ -115,7 +115,7 @@ def test_simple():
a.add(TAddon("one"))
a.trigger("done")
a.trigger("tick")
- tctx.master.has_log("not callable")
+ assert tctx.master.has_log("not callable")
a.remove(a.get("one"))
assert not a.get("one")