From 88375ad64aa2f53b9447df1ccd7aa7ee77cb04ef Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 21 Sep 2015 02:26:47 +0200 Subject: fix minor bugs, add py.test compatibility --- test/tutils.py | 52 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) (limited to 'test/tutils.py') diff --git a/test/tutils.py b/test/tutils.py index 229b51a8..f1db7842 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -18,7 +18,7 @@ from libmproxy.console.flowview import FlowView from libmproxy.console import ConsoleState -def _SkipWindows(): +def _SkipWindows(*args): raise SkipTest("Skipped on Windows.") @@ -96,18 +96,6 @@ def terr(content="error"): return err -def tflowview(request_contents=None): - m = Mock() - cs = ConsoleState() - if request_contents is None: - flow = tflow() - else: - flow = tflow(req=netlib.tutils.treq(body=request_contents)) - - fv = FlowView(m, cs, flow) - return fv - - def get_body_line(last_displayed_body, line_nb): return last_displayed_body.contents()[line_nb + 2] @@ -134,43 +122,7 @@ class MockParser(argparse.ArgumentParser): raise Exception(message) -def raises(exc, obj, *args, **kwargs): - """ - Assert that a callable raises a specified exception. - - :exc An exception class or a string. If a class, assert that an - exception of this type is raised. If a string, assert that the string - occurs in the string representation of the exception, based on a - case-insenstivie match. - - :obj A callable object. - - :args Arguments to be passsed to the callable. - - :kwargs Arguments to be passed to the callable. - """ - try: - obj(*args, **kwargs) - except Exception as v: - if isinstance(exc, basestring): - if exc.lower() in str(v).lower(): - return - else: - raise AssertionError( - "Expected %s, but caught %s" % ( - repr(str(exc)), v - ) - ) - else: - if isinstance(v, exc): - return - else: - raise AssertionError( - "Expected %s, but caught %s %s" % ( - exc.__name__, v.__class__.__name__, str(v) - ) - ) - raise AssertionError("No exception raised.") +raises = netlib.tutils.raises @contextmanager -- cgit v1.2.3