diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2018-04-02 17:53:28 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-07 08:59:08 +1200 |
commit | cdbe6f97af6ae86f80080b7a279c8d3734662c5c (patch) | |
tree | cdbe781e417e7a049ec05be644013842535f3c66 | |
parent | 506ccc5693284a66ff186306509217282868e48b (diff) | |
download | mitmproxy-cdbe6f97af6ae86f80080b7a279c8d3734662c5c.tar.gz mitmproxy-cdbe6f97af6ae86f80080b7a279c8d3734662c5c.tar.bz2 mitmproxy-cdbe6f97af6ae86f80080b7a279c8d3734662c5c.zip |
asyncio: remove last vestiage of channel input from master
-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: |