2016-02-16 19:59:33 +00:00
|
|
|
from pathod.language import generators
|
2015-05-02 04:53:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_randomgenerator():
|
|
|
|
g = generators.RandomGenerator("bytes", 100)
|
|
|
|
assert repr(g)
|
2016-06-02 07:29:14 +00:00
|
|
|
assert g[0]
|
|
|
|
assert len(g[0]) == 1
|
2015-05-02 04:53:48 +00:00
|
|
|
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")
|
|
|
|
f.write(b"x" * 10000)
|
|
|
|
g = generators.FileGenerator(str(f))
|
|
|
|
assert len(g) == 10000
|
|
|
|
assert g[0] == b"x"
|
|
|
|
assert g[-1] == b"x"
|
|
|
|
assert g[0:5] == b"xxxxx"
|
|
|
|
assert len(g[1:10]) == 9
|
|
|
|
assert len(g[10000:10001]) == 0
|
|
|
|
assert repr(g)
|
2017-05-24 12:09:41 +00:00
|
|
|
g.close()
|
2015-05-02 05:19:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_transform_generator():
|
|
|
|
def trans(offset, data):
|
|
|
|
return "a" * len(data)
|
2015-05-02 20:51:57 +00:00
|
|
|
g = "one"
|
2015-05-02 05:19:48 +00:00
|
|
|
t = generators.TransformGenerator(g, trans)
|
|
|
|
assert len(t) == len(g)
|
|
|
|
assert t[0] == "a"
|
|
|
|
assert t[:] == "a" * len(g)
|
|
|
|
assert repr(t)
|