From 5b48c69a6a0f1eeac9e8981d59d556e565163fba Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 2 May 2015 16:53:48 +1200 Subject: Split language test suite: generators Also remove some unused code --- test/test_language_generators.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/test_language_generators.py (limited to 'test/test_language_generators.py') diff --git a/test/test_language_generators.py b/test/test_language_generators.py new file mode 100644 index 00000000..3db1ac91 --- /dev/null +++ b/test/test_language_generators.py @@ -0,0 +1,38 @@ +import os + +from libpathod.language import generators +import tutils + + +def test_randomgenerator(): + g = generators.RandomGenerator("bytes", 100) + assert repr(g) + assert len(g[:10]) == 10 + assert len(g[1:10]) == 9 + assert len(g[:1000]) == 100 + assert len(g[1000:1001]) == 0 + assert g[0] + + +def test_literalgenerator(): + g = generators.LiteralGenerator("one") + assert repr(g) + assert g[:] == "one" + assert g[1] == "n" + + +def test_filegenerator(): + with tutils.tmpdir() as t: + path = os.path.join(t, "foo") + f = open(path, "wb") + f.write("x" * 10000) + f.close() + g = generators.FileGenerator(path) + assert len(g) == 10000 + assert g[0] == "x" + assert g[-1] == "x" + assert g[0:5] == "xxxxx" + assert repr(g) + # remove all references to FileGenerator instance to close the file + # handle. + del g -- cgit v1.2.3