diff options
-rw-r--r-- | mitmproxy/addonmanager.py | 4 | ||||
-rw-r--r-- | mitmproxy/master.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_script.py | 19 |
3 files changed, 11 insertions, 17 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index bfaacf6d..61c59b7b 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -57,10 +57,10 @@ class StreamLog: def safecall(): # resolve ctx.master here. # we want to be threadsafe, and ctx.master may already be cleared when an addon prints(). - tell = ctx.master.tell + channel = ctx.master.channel # don't use master.add_log (which is not thread-safe). Instead, put on event queue. stdout_replacement = StreamLog( - lambda message: tell("log", log.LogEntry(message, "warn")) + lambda message: channel("log", log.LogEntry(message, "warn")) ) try: with contextlib.redirect_stdout(stdout_replacement): diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 372bb289..9dcad4d1 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -85,11 +85,6 @@ class Master: mitmproxy_ctx.log = None mitmproxy_ctx.options = None - # This is a vestigial function that will go away in a refactor very soon - def tell(self, mtype, m): # pragma: no cover - m.reply = controller.DummyReply() - self.event_queue.put((mtype, m)) - def add_log(self, e, level): """ level: debug, alert, info, warn, error diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 79fa22dc..5427c788 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -2,6 +2,7 @@ import os import sys import traceback from unittest import mock +import time import pytest @@ -49,17 +50,15 @@ def test_load_fullname(): assert not hasattr(ns2, "addons") -def test_script_print_stdout(): +@pytest.mark.asyncio +async def test_script_print_stdout(): with taddons.context() as tctx: - with mock.patch('mitmproxy.ctx.master.tell') as mock_warn: - with addonmanager.safecall(): - ns = script.load_script( - tutils.test_data.path( - "mitmproxy/data/addonscripts/print.py" - ) - ) - ns.load(addonmanager.Loader(tctx.master)) - mock_warn.assert_called_once_with("log", log.LogEntry("stdoutprint", "warn")) + with addonmanager.safecall(): + ns = script.load_script( + tutils.test_data.path("mitmproxy/data/addonscripts/print.py") + ) + ns.load(addonmanager.Loader(tctx.master)) + assert tctx.master.has_log("stdoutprint") class TestScript: |