import os, cStringIO from libpathod import language, utils import tutils language.TESTING = True class TestValueNakedLiteral: def test_expr(self): v = language.ValueNakedLiteral("foo") assert v.expr() def test_spec(self): v = language.ValueNakedLiteral("foo") assert v.spec() == repr(v) == "foo" v = language.ValueNakedLiteral("f\x00oo") assert v.spec() == repr(v) == r"f\x00oo" class TestValueLiteral: def test_espr(self): v = language.ValueLiteral("foo") assert v.expr() assert v.val == "foo" v = language.ValueLiteral(r"foo\n") assert v.expr() assert v.val == "foo\n" assert repr(v) def test_spec(self): v = language.ValueLiteral("foo") assert v.spec() == r'"foo"' v = language.ValueLiteral("f\x00oo") assert v.spec() == repr(v) == r'"f\x00oo"' class TestValueGenerate: def test_basic(self): v = language.Value.parseString("@10b")[0] assert v.usize == 10 assert v.unit == "b" assert v.bytes() == 10 v = language.Value.parseString("@10")[0] assert v.unit == "b" v = language.Value.parseString("@10k")[0] assert v.bytes() == 10240 v = language.Value.parseString("@10g")[0] assert v.bytes() == 1024**3 * 10 v = language.Value.parseString("@10g,digits")[0] assert v.datatype == "digits" g = v.get_generator({}) assert g[:100] v = language.Value.parseString("@10,digits")[0] assert v.unit == "b" assert v.datatype == "digits" def test_spec(self): v = language.ValueGenerate(1, "b", "bytes") assert v.spec() == repr(v) == "@1" v = language.ValueGenerate(1, "k", "bytes") assert v.spec() == repr(v) == "@1k" v = language.ValueGenerate(1, "k", "ascii") assert v.spec() == repr(v) == "@1k,ascii" v = language.ValueGenerate(1, "b", "ascii") assert v.spec() == repr(v) == "@1,ascii" class TestValueFile: def test_file_value(self): v = language.Value.parseString("<'one two'")[0] assert str(v) assert v.path == "one two" v = language.Value.parseString("