aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-07-30 02:33:00 +0200
committerGitHub <noreply@github.com>2017-07-30 02:33:00 +0200
commit7594dac94bede4b03660c76af9e353d8646cdf39 (patch)
tree2d984ade6a463a2cdbef227195b7636c1a969c84 /test
parentecc01b0f02b60cfce00f36057a78354780278aca (diff)
parent3b8e3e4aa9cb39c8942cf9871ea84feb925e2aee (diff)
downloadmitmproxy-7594dac94bede4b03660c76af9e353d8646cdf39.tar.gz
mitmproxy-7594dac94bede4b03660c76af9e353d8646cdf39.tar.bz2
mitmproxy-7594dac94bede4b03660c76af9e353d8646cdf39.zip
Merge pull request #2482 from mhils/pure-script-load
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 5bff61d1..722d108b 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")
tctx.master.clear()
a.get("one").tick = addons