mitmproxy/test/pathod/language/test_generators.py

36 lines
878 B
Python
Raw Normal View History

2016-02-16 19:59:33 +00:00
from pathod.language import generators
def test_randomgenerator():
g = generators.RandomGenerator("bytes", 100)
assert repr(g)
assert g[0]
assert len(g[0]) == 1
assert len(g[:10]) == 10
assert len(g[1:10]) == 9
assert len(g[:1000]) == 100
assert len(g[1000:1001]) == 0
2017-03-12 21:55:22 +00:00
def test_filegenerator(tmpdir):
f = tmpdir.join("foo")
2017-05-24 15:25:12 +00:00
f.write(b"abcdefghijklmnopqrstuvwxyz" * 1000)
2017-03-12 21:55:22 +00:00
g = generators.FileGenerator(str(f))
2017-05-24 15:25:12 +00:00
assert len(g) == 26000
assert g[0] == b"a"
assert g[2:7] == b"cdefg"
2017-03-12 21:55:22 +00:00
assert len(g[1:10]) == 9
2017-05-24 15:25:12 +00:00
assert len(g[26000:26001]) == 0
2017-03-12 21:55:22 +00:00
assert repr(g)
def test_transform_generator():
def trans(offset, data):
return "a" * len(data)
g = "one"
t = generators.TransformGenerator(g, trans)
assert len(t) == len(g)
assert t[0] == "a"
assert t[:] == "a" * len(g)
assert repr(t)