mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Merge pull request #4288 from felixonmars/drop-asynctest
Replace asynctest with stdlib mock
This commit is contained in:
commit
f61f48c392
1
setup.py
1
setup.py
@ -102,7 +102,6 @@ setup(
|
|||||||
"dataclasses>=0.7",
|
"dataclasses>=0.7",
|
||||||
],
|
],
|
||||||
'dev': [
|
'dev': [
|
||||||
"asynctest>=0.12.0",
|
|
||||||
"Flask>=1.0,<1.2",
|
"Flask>=1.0,<1.2",
|
||||||
"hypothesis>=5.8,<6",
|
"hypothesis>=5.8,<6",
|
||||||
"parver>=0.1,<2.0",
|
"parver>=0.1,<2.0",
|
||||||
|
@ -2,7 +2,7 @@ import asyncio
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import asynctest
|
from unittest import mock
|
||||||
|
|
||||||
import mitmproxy.io
|
import mitmproxy.io
|
||||||
from mitmproxy import exceptions
|
from mitmproxy import exceptions
|
||||||
@ -54,17 +54,17 @@ class TestReadFile:
|
|||||||
|
|
||||||
tf = tmpdir.join("tfile")
|
tf = tmpdir.join("tfile")
|
||||||
|
|
||||||
with asynctest.patch('mitmproxy.master.Master.load_flow') as mck:
|
with mock.patch('mitmproxy.master.Master.load_flow') as mck:
|
||||||
tf.write(data.getvalue())
|
tf.write(data.getvalue())
|
||||||
tctx.configure(
|
tctx.configure(
|
||||||
rf,
|
rf,
|
||||||
rfile = str(tf),
|
rfile = str(tf),
|
||||||
readfile_filter = ".*"
|
readfile_filter = ".*"
|
||||||
)
|
)
|
||||||
assert not mck.awaited
|
mck.assert_not_awaited()
|
||||||
rf.running()
|
rf.running()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
assert mck.awaited
|
mck.assert_awaited()
|
||||||
|
|
||||||
tf.write(corrupt_data.getvalue())
|
tf.write(corrupt_data.getvalue())
|
||||||
tctx.configure(rf, rfile=str(tf))
|
tctx.configure(rf, rfile=str(tf))
|
||||||
@ -93,16 +93,16 @@ class TestReadFile:
|
|||||||
|
|
||||||
|
|
||||||
class TestReadFileStdin:
|
class TestReadFileStdin:
|
||||||
@asynctest.patch('sys.stdin')
|
@mock.patch('sys.stdin')
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_stdin(self, stdin, data, corrupt_data):
|
async def test_stdin(self, stdin, data, corrupt_data):
|
||||||
rf = readfile.ReadFileStdin()
|
rf = readfile.ReadFileStdin()
|
||||||
with taddons.context(rf):
|
with taddons.context(rf):
|
||||||
with asynctest.patch('mitmproxy.master.Master.load_flow') as mck:
|
with mock.patch('mitmproxy.master.Master.load_flow') as mck:
|
||||||
stdin.buffer = data
|
stdin.buffer = data
|
||||||
assert not mck.awaited
|
mck.assert_not_awaited()
|
||||||
await rf.load_flows(stdin.buffer)
|
await rf.load_flows(stdin.buffer)
|
||||||
assert mck.awaited
|
mck.assert_awaited()
|
||||||
|
|
||||||
stdin.buffer = corrupt_data
|
stdin.buffer = corrupt_data
|
||||||
with pytest.raises(exceptions.FlowReadException):
|
with pytest.raises(exceptions.FlowReadException):
|
||||||
@ -113,10 +113,10 @@ class TestReadFileStdin:
|
|||||||
rf = readfile.ReadFileStdin()
|
rf = readfile.ReadFileStdin()
|
||||||
with taddons.context(rf) as tctx:
|
with taddons.context(rf) as tctx:
|
||||||
tf = tmpdir.join("tfile")
|
tf = tmpdir.join("tfile")
|
||||||
with asynctest.patch('mitmproxy.master.Master.load_flow') as mck:
|
with mock.patch('mitmproxy.master.Master.load_flow') as mck:
|
||||||
tf.write(data.getvalue())
|
tf.write(data.getvalue())
|
||||||
tctx.configure(rf, rfile=str(tf))
|
tctx.configure(rf, rfile=str(tf))
|
||||||
assert not mck.awaited
|
mck.assert_not_awaited()
|
||||||
rf.running()
|
rf.running()
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
assert mck.awaited
|
mck.assert_awaited()
|
||||||
|
Loading…
Reference in New Issue
Block a user