Shore up test suite.

This commit is contained in:
Aldo Cortesi 2015-06-04 20:36:50 +12:00
parent 182b79ab9e
commit 07d5b90ebf
6 changed files with 49 additions and 3 deletions

View File

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

View File

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

View File

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

22
test/test_log.py Normal file
View File

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

View File

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

View File

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