tests: minor cleanup for tests/mitmproxy/tutils.py

This commit is contained in:
Aldo Cortesi 2016-11-02 08:51:26 +13:00
parent ba09b8bff3
commit fc7606bd98
2 changed files with 13 additions and 17 deletions

View File

@ -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)

View File

@ -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