mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +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
|
||||
import os
|
||||
import mock
|
||||
import argparse
|
||||
from OpenSSL import SSL
|
||||
|
||||
from mitmproxy.tools import cmdline
|
||||
@ -55,10 +56,21 @@ class TestServerConnection:
|
||||
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:
|
||||
|
||||
def p(self, *args):
|
||||
parser = tutils.MockParser()
|
||||
parser = MockParser()
|
||||
cmdline.common_options(parser)
|
||||
args = parser.parse_args(args=args)
|
||||
opts = cmdline.get_common_options(args)
|
||||
|
@ -1,4 +1,3 @@
|
||||
import argparse
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from unittest.case import SkipTest
|
||||
@ -64,10 +63,6 @@ def tdummyflow(client_conn=True, server_conn=True, err=None):
|
||||
return f
|
||||
|
||||
|
||||
def get_body_line(last_displayed_body, line_nb):
|
||||
return last_displayed_body.contents()[line_nb + 2]
|
||||
|
||||
|
||||
@contextmanager
|
||||
def chdir(dir):
|
||||
orig_dir = os.getcwd()
|
||||
@ -84,17 +79,6 @@ def tmpdir(*args, **kwargs):
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user