mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
tests: minor cleanup for tests/mitmproxy/tutils.py
This commit is contained in:
parent
ba09b8bff3
commit
fc7606bd98
@ -1,6 +1,7 @@
|
|||||||
from mitmproxy.test import tflow
|
from mitmproxy.test import tflow
|
||||||
import os
|
import os
|
||||||
import mock
|
import mock
|
||||||
|
import argparse
|
||||||
from OpenSSL import SSL
|
from OpenSSL import SSL
|
||||||
|
|
||||||
from mitmproxy.tools import cmdline
|
from mitmproxy.tools import cmdline
|
||||||
@ -55,10 +56,21 @@ class TestServerConnection:
|
|||||||
assert "foo" in repr(sc)
|
assert "foo" in repr(sc)
|
||||||
|
|
||||||
|
|
||||||
|
class MockParser(argparse.ArgumentParser):
|
||||||
|
|
||||||
|
"""
|
||||||
|
argparse.ArgumentParser sys.exits() by default.
|
||||||
|
Make it more testable by throwing an exception instead.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def error(self, message):
|
||||||
|
raise Exception(message)
|
||||||
|
|
||||||
|
|
||||||
class TestProcessProxyOptions:
|
class TestProcessProxyOptions:
|
||||||
|
|
||||||
def p(self, *args):
|
def p(self, *args):
|
||||||
parser = tutils.MockParser()
|
parser = MockParser()
|
||||||
cmdline.common_options(parser)
|
cmdline.common_options(parser)
|
||||||
args = parser.parse_args(args=args)
|
args = parser.parse_args(args=args)
|
||||||
opts = cmdline.get_common_options(args)
|
opts = cmdline.get_common_options(args)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import argparse
|
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from unittest.case import SkipTest
|
from unittest.case import SkipTest
|
||||||
@ -64,10 +63,6 @@ def tdummyflow(client_conn=True, server_conn=True, err=None):
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
def get_body_line(last_displayed_body, line_nb):
|
|
||||||
return last_displayed_body.contents()[line_nb + 2]
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def chdir(dir):
|
def chdir(dir):
|
||||||
orig_dir = os.getcwd()
|
orig_dir = os.getcwd()
|
||||||
@ -84,17 +79,6 @@ def tmpdir(*args, **kwargs):
|
|||||||
shutil.rmtree(temp_workdir)
|
shutil.rmtree(temp_workdir)
|
||||||
|
|
||||||
|
|
||||||
class MockParser(argparse.ArgumentParser):
|
|
||||||
|
|
||||||
"""
|
|
||||||
argparse.ArgumentParser sys.exits() by default.
|
|
||||||
Make it more testable by throwing an exception instead.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def error(self, message):
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
raises = mitmproxy.test.tutils.raises
|
raises = mitmproxy.test.tutils.raises
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user