From 07d5b90ebf190c4419f6b3f3d3cea1cf116ceecb Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 4 Jun 2015 20:36:50 +1200 Subject: [PATCH] Shore up test suite. --- libpathod/cmdline.py | 5 ++--- test/test_cmdline.py | 10 ++++++++++ test/test_language_websocket.py | 4 ++++ test/test_log.py | 22 ++++++++++++++++++++++ test/test_pathod.py | 9 +++++++++ test/tutils.py | 2 ++ 6 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/test_log.py diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py index af1b1c3d1..ac03a5d49 100644 --- a/libpathod/cmdline.py +++ b/libpathod/cmdline.py @@ -8,7 +8,6 @@ from netlib import http_uastrings from . import pathoc, pathod, version, utils, language - def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): preparser = argparse.ArgumentParser(add_help=False) preparser.add_argument( @@ -43,8 +42,8 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): "-m", dest='memo', action="store_true", default=False, help=""" Remember specs, and never play the same one twice. Note that this - means requests have to be rendered in memory, which means that large - generated data can cause issues. + means requests have to be rendered in memory, which means that + large generated data can cause issues. """ ) parser.add_argument( diff --git a/test/test_cmdline.py b/test/test_cmdline.py index 5a9ee242f..b9607029b 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -137,6 +137,16 @@ def test_pathoc(perror): ) assert len(a.requests) == 1 + a = cmdline.args_pathod( + [ + "pathod", + "-c", + "?" + ] + ) + assert perror.called + perror.reset_mock() + tutils.raises( SystemExit, cmdline.args_pathoc, diff --git a/test/test_language_websocket.py b/test/test_language_websocket.py index 70a626e6a..f75562c9c 100644 --- a/test/test_language_websocket.py +++ b/test/test_language_websocket.py @@ -45,6 +45,10 @@ class TestWebsocketFrame: ] self._test_messages(specs, websockets.WebsocketClientFrame) + def test_nested_frame(self): + wf = parse_request("wf:f'wf'") + assert wf.nested_frame + def test_flags(self): wf = parse_request("wf:fin:mask:rsv1:rsv2:rsv3") frm = netlib.websockets.Frame.from_bytes(tutils.render(wf)) diff --git a/test/test_log.py b/test/test_log.py new file mode 100644 index 000000000..5473236e3 --- /dev/null +++ b/test/test_log.py @@ -0,0 +1,22 @@ +import StringIO +from libpathod import log +import netlib.tcp + + +class DummyIO(StringIO.StringIO): + def start_log(self, *args, **kwargs): + pass + + def get_log(self, *args, **kwargs): + return "" + + +def test_disconnect(): + outf = DummyIO() + rw = DummyIO() + try: + with log.Log(outf, False, rw, rw) as lg: + raise netlib.tcp.NetLibDisconnect() + except netlib.tcp.NetLibDisconnect: + pass + assert "Disconnected" in outf.getvalue() diff --git a/test/test_pathod.py b/test/test_pathod.py index 2adcae401..f27f4d383 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -109,6 +109,15 @@ class TestHexdump(tutils.DaemonTests): r = self.get(r"200:b'\xf0'") +class TestNocraft(tutils.DaemonTests): + nocraft = True + + def test_nocraft(self): + r = self.get(r"200:b'\xf0'") + assert r.status_code == 800 + assert "Crafting disabled" in r.content + + class CommonTests(tutils.DaemonTests): def test_binarydata(self): r = self.get(r"200:b'\xf0'") diff --git a/test/tutils.py b/test/tutils.py index 778ad7909..dc118bbef 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -16,6 +16,7 @@ class DaemonTests(object): timeout = None hexdump = False ssloptions = None + nocraft = False @classmethod def setUpAll(klass): @@ -36,6 +37,7 @@ class DaemonTests(object): nohang = klass.nohang, timeout = klass.timeout, hexdump = klass.hexdump, + nocraft = klass.nocraft, logreq = True, logresp = True, explain = True