aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_language_actions.py4
-rw-r--r--test/test_language_base.py6
-rw-r--r--test/test_language_http.py4
-rw-r--r--test/test_language_http2.py10
-rw-r--r--test/test_language_websocket.py1
-rw-r--r--test/test_log.py1
-rw-r--r--test/test_pathoc.py73
-rw-r--r--test/test_pathod.py13
-rw-r--r--test/test_test.py7
-rw-r--r--test/tutils.py31
10 files changed, 87 insertions, 63 deletions
diff --git a/test/test_language_actions.py b/test/test_language_actions.py
index 9f36805f..755f0d85 100644
--- a/test/test_language_actions.py
+++ b/test/test_language_actions.py
@@ -14,6 +14,7 @@ def test_unique_name():
class TestDisconnects:
+
def test_parse_pathod(self):
a = language.parse_pathod("400:d0").next().actions[0]
assert a.spec() == "d0"
@@ -39,6 +40,7 @@ class TestDisconnects:
class TestInject:
+
def test_parse_pathod(self):
a = language.parse_pathod("400:ir,@100").next().actions[0]
assert a.offset == "r"
@@ -77,6 +79,7 @@ class TestInject:
class TestPauses:
+
def test_parse_pathod(self):
e = actions.PauseAt.expr()
v = e.parseString("p10,10")[0]
@@ -107,6 +110,7 @@ class TestPauses:
class Test_Action:
+
def test_cmp(self):
a = actions.DisconnectAt(0)
b = actions.DisconnectAt(1)
diff --git a/test/test_language_base.py b/test/test_language_base.py
index b2296e3a..7a9d2a54 100644
--- a/test/test_language_base.py
+++ b/test/test_language_base.py
@@ -24,6 +24,7 @@ def test_caseless_literal():
class TestTokValueNakedLiteral:
+
def test_expr(self):
v = base.TokValueNakedLiteral("foo")
assert v.expr()
@@ -37,6 +38,7 @@ class TestTokValueNakedLiteral:
class TestTokValueLiteral:
+
def test_espr(self):
v = base.TokValueLiteral("foo")
assert v.expr()
@@ -75,6 +77,7 @@ class TestTokValueLiteral:
class TestTokValueGenerate:
+
def test_basic(self):
v = base.TokValue.parseString("@10b")[0]
assert v.usize == 10
@@ -116,6 +119,7 @@ class TestTokValueGenerate:
class TestTokValueFile:
+
def test_file_value(self):
v = base.TokValue.parseString("<'one two'")[0]
assert str(v)
@@ -164,6 +168,7 @@ class TestTokValueFile:
class TestMisc:
+
def test_generators(self):
v = base.TokValue.parseString("'val'")[0]
g = v.get_generator({})
@@ -227,6 +232,7 @@ class TKeyValue(base.KeyValue):
class TestKeyValue:
+
def test_simple(self):
e = TKeyValue.expr()
v = e.parseString("h'foo'='bar'")[0]
diff --git a/test/test_language_http.py b/test/test_language_http.py
index 02f0f998..ae2906bd 100644
--- a/test/test_language_http.py
+++ b/test/test_language_http.py
@@ -16,6 +16,7 @@ def test_make_error_response():
class TestRequest:
+
def test_nonascii(self):
tutils.raises("ascii", parse_request, "get:\xf0")
@@ -80,7 +81,7 @@ class TestRequest:
assert language.serve(
r,
s,
- language.Settings(request_host = "foo.com")
+ language.Settings(request_host="foo.com")
)
def test_multiline(self):
@@ -142,6 +143,7 @@ class TestRequest:
class TestResponse:
+
def dummy_response(self):
return language.parse_pathod("400'msg'").next()
diff --git a/test/test_language_http2.py b/test/test_language_http2.py
index 0be42253..a78c2bee 100644
--- a/test/test_language_http2.py
+++ b/test/test_language_http2.py
@@ -10,13 +10,15 @@ import tutils
def parse_request(s):
return language.parse_pathoc(s, True).next()
+
def parse_response(s):
return language.parse_pathod(s, True).next()
+
def default_settings():
return language.Settings(
- request_host = "foo.com",
- protocol = netlib.http2.HTTP2Protocol(tcp.TCPClient(('localhost', 1234)))
+ request_host="foo.com",
+ protocol=netlib.http2.HTTP2Protocol(tcp.TCPClient(('localhost', 1234)))
)
@@ -27,6 +29,7 @@ def test_make_error_response():
class TestRequest:
+
def test_cached_values(self):
req = parse_request("get:/")
req_id = id(req)
@@ -113,6 +116,7 @@ class TestRequest:
class TestResponse:
+
def test_cached_values(self):
res = parse_response("200")
res_id = id(res)
@@ -134,7 +138,7 @@ class TestResponse:
assert r.code.string() == "200"
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("foo", "bar")
- assert r.body == None
+ assert r.body is None
r = parse_response('200:h"foo"="bar":bfoobar:h"bla"="fasel"')
assert r.code.string() == "200"
diff --git a/test/test_language_websocket.py b/test/test_language_websocket.py
index 107f3427..8878f355 100644
--- a/test/test_language_websocket.py
+++ b/test/test_language_websocket.py
@@ -10,6 +10,7 @@ def parse_request(s):
class TestWebsocketFrame:
+
def _test_messages(self, specs, message_klass):
for i in specs:
wf = parse_request(i)
diff --git a/test/test_log.py b/test/test_log.py
index 9850654c..0d5c6c61 100644
--- a/test/test_log.py
+++ b/test/test_log.py
@@ -4,6 +4,7 @@ import netlib.tcp
class DummyIO(StringIO.StringIO):
+
def start_log(self, *args, **kwargs):
pass
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 9b1ed8b4..cf12332c 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -20,10 +20,10 @@ class _TestDaemon:
@classmethod
def setUpAll(self):
self.d = test.Daemon(
- ssl = self.ssl,
- ssloptions = self.ssloptions,
- staticdir = tutils.test_data.path("data"),
- anchors = [
+ ssl=self.ssl,
+ ssloptions=self.ssloptions,
+ staticdir=tutils.test_data.path("data"),
+ anchors=[
(re.compile("/anchor/.*"), "202")
]
)
@@ -38,8 +38,8 @@ class _TestDaemon:
def test_info(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = self.ssl,
- fp = None
+ ssl=self.ssl,
+ fp=None
)
c.connect()
resp = c.request("get:/api/info")
@@ -61,15 +61,15 @@ class _TestDaemon:
s = cStringIO.StringIO()
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = self.ssl,
- showreq = showreq,
- showresp = showresp,
- explain = explain,
- hexdump = hexdump,
- ignorecodes = ignorecodes,
- ignoretimeout = ignoretimeout,
- showsummary = showsummary,
- fp = s
+ ssl=self.ssl,
+ showreq=showreq,
+ showresp=showresp,
+ explain=explain,
+ hexdump=hexdump,
+ ignorecodes=ignorecodes,
+ ignoretimeout=ignoretimeout,
+ showsummary=showsummary,
+ fp=s
)
c.connect(showssl=showssl, fp=s)
if timeout:
@@ -88,17 +88,17 @@ class _TestDaemon:
class TestDaemonSSL(_TestDaemon):
ssl = True
ssloptions = pathod.SSLOptions(
- request_client_cert = True,
- sans = ["test1.com", "test2.com"],
- alpn_select = http2.HTTP2Protocol.ALPN_PROTO_H2,
+ request_client_cert=True,
+ sans=["test1.com", "test2.com"],
+ alpn_select=http2.HTTP2Protocol.ALPN_PROTO_H2,
)
def test_sni(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = True,
- sni = "foobar.com",
- fp = None
+ ssl=True,
+ sni="foobar.com",
+ fp=None
)
c.connect()
c.request("get:/p/200")
@@ -112,9 +112,9 @@ class TestDaemonSSL(_TestDaemon):
def test_clientcert(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = True,
- clientcert = tutils.test_data.path("data/clientcert/client.pem"),
- fp = None
+ ssl=True,
+ clientcert=tutils.test_data.path("data/clientcert/client.pem"),
+ fp=None
)
c.connect()
c.request("get:/p/200")
@@ -125,8 +125,8 @@ class TestDaemonSSL(_TestDaemon):
def test_http2_without_ssl(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- use_http2 = True,
- ssl = False,
+ use_http2=True,
+ ssl=False,
)
tutils.raises(NotImplementedError, c.connect)
@@ -135,7 +135,7 @@ class TestDaemon(_TestDaemon):
ssl = False
def test_ssl_error(self):
- c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl = True, fp=None)
+ c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=True, fp=None)
tutils.raises("ssl handshake", c.connect)
def test_showssl(self):
@@ -206,7 +206,7 @@ class TestDaemon(_TestDaemon):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
fp=None,
- ws_read_limit = 1
+ ws_read_limit=1
)
c.connect()
c.request("ws:/")
@@ -237,22 +237,23 @@ class TestDaemonHTTP2(_TestDaemon):
def test_http2(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- use_http2 = True,
- ssl = True,
+ use_http2=True,
+ ssl=True,
)
assert isinstance(c.protocol, http2.HTTP2Protocol)
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
)
- assert c.protocol == None # TODO: change if other protocols get implemented
+ # TODO: change if other protocols get implemented
+ assert c.protocol is None
def test_http2_alpn(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = True,
- use_http2 = True,
- http2_skip_connection_preface = True,
+ ssl=True,
+ use_http2=True,
+ http2_skip_connection_preface=True,
)
tmp_convert_to_ssl = c.convert_to_ssl
@@ -266,8 +267,8 @@ class TestDaemonHTTP2(_TestDaemon):
def test_request(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
- ssl = True,
- use_http2 = True,
+ ssl=True,
+ use_http2=True,
)
c.connect()
resp = c.request("get:/p/200")
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 7cd2fccc..12f7bac0 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -8,6 +8,7 @@ import tutils
class TestPathod(object):
+
def test_logging(self):
s = cStringIO.StringIO()
p = pathod.Pathod(("127.0.0.1", 0), logfp=s)
@@ -56,7 +57,7 @@ class TestNoApi(tutils.DaemonTests):
class TestNotAfterConnect(tutils.DaemonTests):
ssl = False
ssloptions = dict(
- not_after_connect = True
+ not_after_connect=True
)
def test_connect(self):
@@ -70,7 +71,7 @@ class TestNotAfterConnect(tutils.DaemonTests):
class TestCustomCert(tutils.DaemonTests):
ssl = True
ssloptions = dict(
- certs = [("*", tutils.test_data.path("data/testkey.pem"))],
+ certs=[("*", tutils.test_data.path("data/testkey.pem"))],
)
def test_connect(self):
@@ -84,7 +85,7 @@ class TestCustomCert(tutils.DaemonTests):
class TestSSLCN(tutils.DaemonTests):
ssl = True
ssloptions = dict(
- cn = "foo.com"
+ cn="foo.com"
)
def test_connect(self):
@@ -122,6 +123,7 @@ class TestNocraft(tutils.DaemonTests):
class CommonTests(tutils.DaemonTests):
+
def test_binarydata(self):
r = self.get(r"200:b'\xf0'")
l = self.d.last_log()
@@ -222,8 +224,8 @@ class CommonTests(tutils.DaemonTests):
def test_websocket_frame_reflect_error(self):
r, _ = self.pathoc(
["ws:/p/", "wf:-mask:knone:f'wf:b@10':i13,'a'"],
- ws_read_limit = 1,
- timeout = 1
+ ws_read_limit=1,
+ timeout=1
)
assert "Parse error" in self.d.text_log()
@@ -271,6 +273,7 @@ class TestDaemonSSL(CommonTests):
assert r[0].status_code == 202
assert self.d.last_log()["cipher"][1] > 0
+
class TestHTTP2(tutils.DaemonTests):
ssl = True
noweb = True
diff --git a/test/test_test.py b/test/test_test.py
index 681aa290..eaaf83d3 100644
--- a/test/test_test.py
+++ b/test/test_test.py
@@ -6,6 +6,7 @@ logging.disable(logging.CRITICAL)
class TestDaemonManual:
+
def test_simple(self):
with test.Daemon() as d:
rsp = requests.get("http://localhost:%s/p/202:da" % d.port)
@@ -34,9 +35,9 @@ class TestDaemonManual:
def test_startstop_ssl_explicit(self):
ssloptions = dict(
- certfile = tutils.test_data.path("data/testkey.pem"),
- cacert = tutils.test_data.path("data/testkey.pem"),
- ssl_after_connect = False
+ certfile=tutils.test_data.path("data/testkey.pem"),
+ cacert=tutils.test_data.path("data/testkey.pem"),
+ ssl_after_connect=False
)
d = test.Daemon(ssl=ssloptions)
rsp = requests.get(
diff --git a/test/tutils.py b/test/tutils.py
index 2184ade5..050fa108 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -29,18 +29,18 @@ class DaemonTests(object):
anchors=[
(re.compile("/anchor/.*"), "202:da")
],
- ssl = klass.ssl,
- ssloptions = so,
- sizelimit = 1 * 1024 * 1024,
- noweb = klass.noweb,
- noapi = klass.noapi,
- nohang = klass.nohang,
- timeout = klass.timeout,
- hexdump = klass.hexdump,
- nocraft = klass.nocraft,
- logreq = True,
- logresp = True,
- explain = True
+ ssl=klass.ssl,
+ ssloptions=so,
+ sizelimit=1 * 1024 * 1024,
+ noweb=klass.noweb,
+ noapi=klass.noapi,
+ nohang=klass.nohang,
+ timeout=klass.timeout,
+ hexdump=klass.hexdump,
+ nocraft=klass.nocraft,
+ logreq=True,
+ logresp=True,
+ explain=True
)
@classmethod
@@ -86,9 +86,9 @@ class DaemonTests(object):
("localhost", self.d.port),
ssl=ssl,
ws_read_limit=ws_read_limit,
- timeout = timeout,
- fp = logfp,
- use_http2 = use_http2,
+ timeout=timeout,
+ fp=logfp,
+ use_http2=use_http2,
)
c.connect(connect_to)
ret = []
@@ -100,6 +100,7 @@ class DaemonTests(object):
ret.append(frm)
return ret, logfp.getvalue()
+
@contextmanager
def tmpdir(*args, **kwargs):
orig_workdir = os.getcwd()