import StringIO, sys import libpry from libpathod import rparse rparse.TESTING = True 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_valueliteral(self): v = rparse.ValueLiteral("foo") assert v.expr() assert str(v) def test_generated_value(self): v = rparse.Value.parseString("!10b")[0] assert v.usize == 10 assert v.unit == "b" assert v.bytes() == 10 v = rparse.Value.parseString("!10")[0] assert v.unit == "b" v = rparse.Value.parseString("!10k")[0] assert v.bytes() == 10240 v = rparse.Value.parseString("!10g")[0] assert v.bytes() == 1024**3 * 10 v = rparse.Value.parseString("!10g:digits")[0] assert v.datatype == "digits" g = v.get_generator({}) assert g[:100] v = rparse.Value.parseString("!10:digits")[0] assert v.unit == "b" assert v.datatype == "digits" def test_value(self): assert rparse.Value.parseString("val")[0].val == "val" assert rparse.Value.parseString("'val'")[0].val == "val" assert rparse.Value.parseString('"val"')[0].val == "val" assert rparse.Value.parseString('"\'val\'"')[0].val == "'val'" v = rparse.Value.parseString("