aboutsummaryrefslogtreecommitdiffstats
path: root/test/pathod
diff options
context:
space:
mode:
Diffstat (limited to 'test/pathod')
-rw-r--r--test/pathod/test_language_base.py37
-rw-r--r--test/pathod/test_language_http.py8
-rw-r--r--test/pathod/test_language_http2.py4
-rw-r--r--test/pathod/test_language_websocket.py4
-rw-r--r--test/pathod/test_pathoc.py8
-rw-r--r--test/pathod/test_pathod.py2
6 files changed, 29 insertions, 34 deletions
diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py
index 190c39b3..85e9e53b 100644
--- a/test/pathod/test_language_base.py
+++ b/test/pathod/test_language_base.py
@@ -149,11 +149,11 @@ class TestTokValueFile:
v = base.TokValue.parseString("<path2")[0]
with pytest.raises(exceptions.FileAccessDenied):
v.get_generator(language.Settings(staticdir=t))
- with pytest.raises("access disabled"):
+ with pytest.raises(Exception, match="access disabled"):
v.get_generator(language.Settings())
v = base.TokValue.parseString("</outside")[0]
- with pytest.raises("outside"):
+ with pytest.raises(Exception, match="outside"):
v.get_generator(language.Settings(staticdir=t))
def test_spec(self):
@@ -194,32 +194,27 @@ class TestMisc:
v3 = v2.freeze({})
assert v2.value.val == v3.value.val
- def test_fixedlengthvalue(self):
+ def test_fixedlengthvalue(self, tmpdir):
class TT(base.FixedLengthValue):
preamble = "m"
length = 4
e = TT.expr()
assert e.parseString("m@4")
- with pytest.raises("invalid value length"):
+ with pytest.raises(Exception, match="Invalid value length"):
e.parseString("m@100")
- with pytest.raises("invalid value length"):
+ with pytest.raises(Exception, match="Invalid value length"):
e.parseString("m@1")
- with tutils.tmpdir() as t:
- p = os.path.join(t, "path")
- s = base.Settings(staticdir=t)
- with open(p, "wb") as f:
- f.write(b"a" * 20)
- v = e.parseString("m<path")[0]
- with pytest.raises("invalid value length"):
- v.values(s)
+ s = base.Settings(staticdir=str(tmpdir))
+ tmpdir.join("path").write_binary(b"a" * 20, ensure=True)
+ v = e.parseString("m<path")[0]
+ with pytest.raises(Exception, match="Invalid value length"):
+ v.values(s)
- p = os.path.join(t, "path")
- with open(p, "wb") as f:
- f.write(b"a" * 4)
- v = e.parseString("m<path")[0]
- assert v.values(s)
+ tmpdir.join("path2").write_binary(b"a" * 4, ensure=True)
+ v = e.parseString("m<path2")[0]
+ assert v.values(s)
class TKeyValue(base.KeyValue):
@@ -282,7 +277,7 @@ def test_intfield():
assert v.value == 4
assert v.spec() == "t4"
- with pytest.raises("can't exceed"):
+ with pytest.raises(Exception, match="can't exceed"):
e.parseString("t5")
@@ -324,9 +319,9 @@ def test_integer():
class BInt(base.Integer):
bounds = (1, 5)
- with pytest.raises("must be between"):
+ with pytest.raises(Exception, match="must be between"):
BInt(0)
- with pytest.raises("must be between"):
+ with pytest.raises(Exception, match="must be between"):
BInt(6)
assert BInt(5)
assert BInt(1)
diff --git a/test/pathod/test_language_http.py b/test/pathod/test_language_http.py
index 199fdf64..6ab43fe0 100644
--- a/test/pathod/test_language_http.py
+++ b/test/pathod/test_language_http.py
@@ -20,7 +20,7 @@ def test_make_error_response():
class TestRequest:
def test_nonascii(self):
- with pytest.raises("ascii"):
+ with pytest.raises(Exception, match="ASCII"):
parse_request("get:\xf0")
def test_err(self):
@@ -226,7 +226,7 @@ class TestResponse:
assert str(v)
def test_nonascii(self):
- with pytest.raises("ascii"):
+ with pytest.raises(Exception, match="ASCII"):
language.parse_pathod("foo:b\xf0")
def test_parse_header(self):
@@ -263,7 +263,7 @@ class TestResponse:
def test_websockets(self):
r = next(language.parse_pathod("ws"))
- with pytest.raises("no websocket key"):
+ with pytest.raises(Exception, match="No websocket key"):
r.resolve(language.Settings())
res = r.resolve(language.Settings(websocket_key=b"foo"))
assert res.status_code.string() == b"101"
@@ -351,5 +351,5 @@ def test_nested_response_freeze():
def test_unique_components():
- with pytest.raises("multiple body clauses"):
+ with pytest.raises(Exception, match="multiple body clauses"):
language.parse_pathod("400:b@1:b@1")
diff --git a/test/pathod/test_language_http2.py b/test/pathod/test_language_http2.py
index fdb65a63..4f89adb8 100644
--- a/test/pathod/test_language_http2.py
+++ b/test/pathod/test_language_http2.py
@@ -39,7 +39,7 @@ class TestRequest:
assert req.values(default_settings()) == req.values(default_settings())
def test_nonascii(self):
- with pytest.raises("ascii"):
+ with pytest.raises(Exception, match="ASCII"):
parse_request("get:\xf0")
def test_err(self):
@@ -168,7 +168,7 @@ class TestResponse:
assert res.values(default_settings()) == res.values(default_settings())
def test_nonascii(self):
- with pytest.raises("ascii"):
+ with pytest.raises(Exception, match="ASCII"):
parse_response("200:\xf0")
def test_err(self):
diff --git a/test/pathod/test_language_websocket.py b/test/pathod/test_language_websocket.py
index 20f6a3a6..e5046591 100644
--- a/test/pathod/test_language_websocket.py
+++ b/test/pathod/test_language_websocket.py
@@ -130,7 +130,7 @@ class TestWebsocketFrame:
assert frm.payload == b"abc"
def test_knone(self):
- with pytest.raises("expected 4 bytes"):
+ with pytest.raises(Exception, match="Expected 4 bytes"):
self.fr("wf:b'foo':mask:knone")
def test_length(self):
@@ -138,5 +138,5 @@ class TestWebsocketFrame:
frm = self.fr("wf:l2:b'foo'")
assert frm.header.payload_length == 2
assert frm.payload == b"fo"
- with pytest.raises("expected 1024 bytes"):
+ with pytest.raises(Exception, match="Expected 1024 bytes"):
self.fr("wf:l1024:b'foo'")
diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py
index a8f79e67..2dd29e20 100644
--- a/test/pathod/test_pathoc.py
+++ b/test/pathod/test_pathoc.py
@@ -173,12 +173,12 @@ class TestDaemon(PathocTestDaemon):
to = ("foobar", 80)
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
c.rfile, c.wfile = io.BytesIO(), io.BytesIO()
- with pytest.raises("connect failed"):
+ with pytest.raises(Exception, match="CONNECT failed"):
c.http_connect(to)
c.rfile = io.BytesIO(
b"HTTP/1.1 500 OK\r\n"
)
- with pytest.raises("connect failed"):
+ with pytest.raises(Exception, match="CONNECT failed"):
c.http_connect(to)
c.rfile = io.BytesIO(
b"HTTP/1.1 200 OK\r\n"
@@ -195,14 +195,14 @@ class TestDaemon(PathocTestDaemon):
c.rfile = tutils.treader(
b"\x05\xEE"
)
- with pytest.raises("SOCKS without authentication"):
+ with pytest.raises(Exception, match="SOCKS without authentication"):
c.socks_connect(("example.com", 0xDEAD))
c.rfile = tutils.treader(
b"\x05\x00" +
b"\x05\xEE\x00\x03\x0bexample.com\xDE\xAD"
)
- with pytest.raises("SOCKS server error"):
+ with pytest.raises(Exception, match="SOCKS server error"):
c.socks_connect(("example.com", 0xDEAD))
c.rfile = tutils.treader(
diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py
index 60ac8072..88480a59 100644
--- a/test/pathod/test_pathod.py
+++ b/test/pathod/test_pathod.py
@@ -134,7 +134,7 @@ class CommonTests(tservers.DaemonTests):
assert len(self.d.log()) == 0
def test_disconnect(self):
- with pytest.raises("unexpected eof"):
+ with pytest.raises(Exception, match="Unexpected EOF"):
self.get("202:b@100k:d200")
def test_parserr(self):