Author: Antonio Cuni <anto.c...@gmail.com> Branch: faster-rstruct-2 Changeset: r91331:ce82d5756ddd Date: 2017-05-18 11:56 +0200 http://bitbucket.org/pypy/pypy/changeset/ce82d5756ddd/
Log: write tests to check that USE_FASTPATH and ALLOW_SLOWPATH actually do what they are supposed to do diff --git a/rpython/rlib/rstruct/test/test_pack.py b/rpython/rlib/rstruct/test/test_pack.py --- a/rpython/rlib/rstruct/test/test_pack.py +++ b/rpython/rlib/rstruct/test/test_pack.py @@ -31,7 +31,7 @@ raise AttributeError(name) -class BaseTestPack(object): +class PackSupport(object): """ These test tests only the various pack_* functions, individually. There is no RPython interface to them, as for now they are used only to @@ -71,6 +71,32 @@ got = self.mypack(fmt, value) assert got == expected + +class TestAllowSlowpath(PackSupport): + ALLOW_SLOWPATH = False + bigendian = not nativefmttable.native_is_bigendian + fmttable = standardfmttable.standard_fmttable + + def test_slowpath_not_allowed(self): + # we are using a non-native endianess and ALLOW_SLOWPATH is False, so + # the following MUST raise + pytest.raises(ValueError, "self.mypack('i', 42)") + + +class TestUseFastpath(PackSupport): + ALLOW_SLOWPATH = False + bigendian = nativefmttable.native_is_bigendian + fmttable = standardfmttable.standard_fmttable + + def test_fastpath_taken(self): + # we are using native endianess and slowpath is not allowed, so the + # following MUST succeed + expected = struct.pack('i', 42) + assert self.mypack('i', 42) == expected + + +class BaseTestPack(PackSupport): + def test_pack_int(self): self.check('b', 42) self.check('B', 242) @@ -153,3 +179,4 @@ bigendian = nativefmttable.native_is_bigendian fmt_prefix = '@' fmttable = nativefmttable.native_fmttable + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit