mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
pytest: raise on malformed test fixtures
and unbreak test depending on backslash escape
This commit is contained in:
parent
26aba9ed9d
commit
559caf9205
@ -51,7 +51,9 @@ class request(object):
|
||||
with open(self.fname, 'rb') as handle:
|
||||
self.data = handle.read()
|
||||
self.data = self.data.replace(b"\n", b"").replace(b"\\r\\n", b"\r\n")
|
||||
self.data = self.data.replace(b"\\0", b"\000")
|
||||
self.data = self.data.replace(b"\\0", b"\000").replace(b"\\n", b"\n").replace(b"\\t", b"\t")
|
||||
if b"\\" in self.data:
|
||||
raise AssertionError("Unexpected backslash in test data - only handling HTAB, NUL and CRLF")
|
||||
|
||||
# Functions for sending data to the parser.
|
||||
# These functions mock out reading from a
|
||||
@ -262,7 +264,8 @@ class request(object):
|
||||
assert req.trailers == exp.get("trailers", [])
|
||||
|
||||
|
||||
class badrequest(object):
|
||||
class badrequest:
|
||||
# FIXME: no good reason why this cannot match what the more extensive mechanism above
|
||||
def __init__(self, fname):
|
||||
self.fname = fname
|
||||
self.name = os.path.basename(fname)
|
||||
@ -270,7 +273,9 @@ class badrequest(object):
|
||||
with open(self.fname) as handle:
|
||||
self.data = handle.read()
|
||||
self.data = self.data.replace("\n", "").replace("\\r\\n", "\r\n")
|
||||
self.data = self.data.replace("\\0", "\000")
|
||||
self.data = self.data.replace("\\0", "\000").replace("\\n", "\n").replace("\\t", "\t")
|
||||
if "\\" in self.data:
|
||||
raise AssertionError("Unexpected backslash in test data - only handling HTAB, NUL and CRLF")
|
||||
self.data = self.data.encode('latin1')
|
||||
|
||||
def send(self):
|
||||
@ -283,4 +288,6 @@ class badrequest(object):
|
||||
|
||||
def check(self, cfg):
|
||||
p = RequestParser(cfg, self.send(), None)
|
||||
next(p)
|
||||
# must fully consume iterator, otherwise EOF errors could go unnoticed
|
||||
for _ in p:
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user