import StringIO, sys, os import libpry from libpathod import rparse rparse.TESTING = True class DummyRequest(StringIO.StringIO): def write(self, d, callback=None): StringIO.StringIO.write(self, d) if callback: callback() def finish(self): return class uMisc(libpry.AutoTree): def test_generators(self): v = rparse.Value.parseString("'val'")[0] g = v.get_generator({}) assert g[:] == "val" def test_randomgenerator(self): g = rparse.RandomGenerator("one", 100) 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(self): g = rparse.LiteralGenerator("one") assert g == "one" assert g[:] == "one" assert g[1] == "n" def test_filegenerator(self): t = self.tmpdir() path = os.path.join(t, "foo") f = open(path, "w") f.write("x"*10000) f.close() g = rparse.FileGenerator(path) assert len(g) == 10000 assert g[0] == "x" assert g[-1] == "x" assert g[0:5] == "xxxxx" def test_valueliteral(self): v = rparse.ValueLiteral("foo") assert v.expr() assert str(v) def test_file_value(self): v = rparse.Value.parseString("<'one two'")[0] assert v.path == "one two" v = rparse.Value.parseString("