def test_fixedlengthvalue(self): class TT(base.FixedLengthValue): preamble = "m" length = 4 e = TT.expr() assert e.parseString("m@4") with pytest.raises("invalid value length"): e.parseString("m@100") with pytest.raises("invalid value length"): e.parseString("m@1") with tutils.tmpdir() as t: p = os.path.join(t, "path") s = base.Settings(staticdir=t) with open(p, "wb") as f: f.write(b"a" * 20) v = e.parseString("m<path")[0] with pytest.raises("invalid value length"): v.values(s) p = os.path.join(t, "path") with open(p, "wb") as f: f.write(b"a" * 4) v = e.parseString("m<path")[0] assert v.values(s)
def test_fixedlengthvalue(self, tmpdir): class TT(base.FixedLengthValue): preamble = "m" length = 4 e = TT.expr() assert e.parseString("m@4") with pytest.raises(Exception, match="Invalid value length"): e.parseString("m@100") with pytest.raises(Exception, match="Invalid value length"): e.parseString("m@1") s = base.Settings(staticdir=str(tmpdir)) tmpdir.join("path").write_binary(b"a" * 20, ensure=True) v = e.parseString("m<path")[0] with pytest.raises(Exception, match="Invalid value length"): v.values(s) tmpdir.join("path2").write_binary(b"a" * 4, ensure=True) v = e.parseString("m<path2")[0] assert v.values(s)