mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 10:26:23 +00:00
test coverage: generators and websockets to 100%
This commit is contained in:
parent
a6dbb82936
commit
2091d16387
@ -11,14 +11,6 @@ from . import generators, exceptions
|
||||
|
||||
TRUNCATE = 1024
|
||||
|
||||
|
||||
def quote(s):
|
||||
quotechar = s[0]
|
||||
s = s[1:-1]
|
||||
s = s.replace(quotechar, "\\" + quotechar)
|
||||
return quotechar + s + quotechar
|
||||
|
||||
|
||||
v_integer = pp.Word(pp.nums)\
|
||||
.setName("integer")\
|
||||
.setParseAction(lambda toks: int(toks[0]))
|
||||
|
@ -40,7 +40,7 @@ class TransformGenerator:
|
||||
return self.transform(a, d)
|
||||
|
||||
def __repr__(self):
|
||||
return "'%s'"%self.gen
|
||||
return "'transform(%s)'"%self.gen
|
||||
|
||||
|
||||
class LiteralGenerator:
|
||||
|
@ -36,3 +36,14 @@ def test_filegenerator():
|
||||
# remove all references to FileGenerator instance to close the file
|
||||
# handle.
|
||||
del g
|
||||
|
||||
|
||||
def test_transform_generator():
|
||||
def trans(offset, data):
|
||||
return "a" * len(data)
|
||||
g = generators.LiteralGenerator("one")
|
||||
t = generators.TransformGenerator(g, trans)
|
||||
assert len(t) == len(g)
|
||||
assert t[0] == "a"
|
||||
assert t[:] == "a" * len(g)
|
||||
assert repr(t)
|
||||
|
@ -8,13 +8,18 @@ def parse_request(s):
|
||||
|
||||
|
||||
class TestWebsocketFrame:
|
||||
def test_spec(self):
|
||||
e = websockets.WebsocketFrame.expr()
|
||||
wf = e.parseString("wf:b'foo'")
|
||||
assert wf
|
||||
|
||||
assert parse_request("wf:b'foo'")
|
||||
|
||||
def test_values(self):
|
||||
r = parse_request("wf:b'foo'")
|
||||
assert r.values(language.Settings())
|
||||
specs = [
|
||||
"wf",
|
||||
"wf:b'foo'"
|
||||
]
|
||||
for i in specs:
|
||||
wf = parse_request(i)
|
||||
assert isinstance(wf, websockets.WebsocketFrame)
|
||||
assert wf
|
||||
assert wf.values(language.Settings())
|
||||
assert wf.resolve(language.Settings())
|
||||
|
||||
spec = wf.spec()
|
||||
wf2 = parse_request(spec)
|
||||
assert wf2.spec() == spec
|
||||
|
Loading…
Reference in New Issue
Block a user