import os from libpathod import language from libpathod.language import base, exceptions import tutils import nose.tools as nt def parse_request(s): return language.parse_requests(s)[0] def test_caseless_literal(): class CL(base.CaselessLiteral): TOK = "foo" v = CL("foo") assert v.expr() assert v.values(language.Settings()) class TestValueNakedLiteral: def test_expr(self): v = base.ValueNakedLiteral("foo") assert v.expr() def test_spec(self): v = base.ValueNakedLiteral("foo") assert v.spec() == repr(v) == "foo" v = base.ValueNakedLiteral("f\x00oo") assert v.spec() == repr(v) == r"f\x00oo" class TestValueLiteral: def test_espr(self): v = base.ValueLiteral("foo") assert v.expr() assert v.val == "foo" v = base.ValueLiteral("foo\n") assert v.expr() assert v.val == "foo\n" assert repr(v) def test_spec(self): v = base.ValueLiteral("foo") assert v.spec() == r"'foo'" v = base.ValueLiteral("f\x00oo") assert v.spec() == repr(v) == r"'f\x00oo'" v = base.ValueLiteral("\"") assert v.spec() == repr(v) == '\'"\'' def roundtrip(self, spec): e = base.ValueLiteral.expr() v = base.ValueLiteral(spec) v2 = e.parseString(v.spec()) nt.assert_equal(v.val, v2[0].val) nt.assert_equal(v.spec(), v2[0].spec()) def test_roundtrip(self): self.roundtrip("'") self.roundtrip('\'') self.roundtrip("a") self.roundtrip("\"") #self.roundtrip("\\") self.roundtrip("200:b'foo':i23,'\\''") self.roundtrip("\a") class TestValueGenerate: def test_basic(self): v = base.Value.parseString("@10b")[0] assert v.usize == 10 assert v.unit == "b" assert v.bytes() == 10 v = base.Value.parseString("@10")[0] assert v.unit == "b" v = base.Value.parseString("@10k")[0] assert v.bytes() == 10240 v = base.Value.parseString("@10g")[0] assert v.bytes() == 1024**3 * 10 v = base.Value.parseString("@10g,digits")[0] assert v.datatype == "digits" g = v.get_generator({}) assert g[:100] v = base.Value.parseString("@10,digits")[0] assert v.unit == "b" assert v.datatype == "digits" def test_spec(self): v = base.ValueGenerate(1, "b", "bytes") assert v.spec() == repr(v) == "@1" v = base.ValueGenerate(1, "k", "bytes") assert v.spec() == repr(v) == "@1k" v = base.ValueGenerate(1, "k", "ascii") assert v.spec() == repr(v) == "@1k,ascii" v = base.ValueGenerate(1, "b", "ascii") assert v.spec() == repr(v) == "@1,ascii" def test_freeze(self): v = base.ValueGenerate(100, "b", "ascii") f = v.freeze(language.Settings()) assert len(f.val) == 100 class TestValueFile: def test_file_value(self): v = base.Value.parseString("<'one two'")[0] assert str(v) assert v.path == "one two" v = base.Value.parseString("