[pypy-commit] pypy faster-rstruct: move strstorage tests into their own file, and refactor to avoid duplication
antocuni
noreply at buildbot.pypy.org
Wed Nov 18 02:17:26 EST 2015
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct
Changeset: r80737:f92d64d0ed7e
Date: 2015-11-18 07:54 +0100
http://bitbucket.org/pypy/pypy/changeset/f92d64d0ed7e/
Log: move strstorage tests into their own file, and refactor to avoid
duplication
diff --git a/rpython/rlib/rawstorage.py b/rpython/rlib/rawstorage.py
--- a/rpython/rlib/rawstorage.py
+++ b/rpython/rlib/rawstorage.py
@@ -6,7 +6,6 @@
from rpython.rlib import rgc
from rpython.rlib.rgc import lltype_is_gc
from rpython.rlib.objectmodel import specialize
-from rpython.rlib.strstorage import str_storage_getitem
RAW_STORAGE = rffi.CCHARP.TO
RAW_STORAGE_PTR = rffi.CCHARP
diff --git a/rpython/rlib/test/test_rawstorage.py b/rpython/rlib/test/test_rawstorage.py
--- a/rpython/rlib/test/test_rawstorage.py
+++ b/rpython/rlib/test/test_rawstorage.py
@@ -4,8 +4,7 @@
from rpython.rlib import rawstorage
from rpython.rlib.rawstorage import alloc_raw_storage, free_raw_storage,\
raw_storage_setitem, raw_storage_getitem, AlignmentError,\
- raw_storage_setitem_unaligned, raw_storage_getitem_unaligned,\
- str_storage_getitem
+ raw_storage_setitem_unaligned, raw_storage_getitem_unaligned
from rpython.rtyper.test.tool import BaseRtypingTest
from rpython.translator.c.test.test_genc import compile
@@ -33,17 +32,6 @@
assert res == 3.14
free_raw_storage(r)
-def test_untranslated_str_storage():
- import struct
- buf = struct.pack('@lld', 42, 43, 123.0)
- size = struct.calcsize('@l')
- res = str_storage_getitem(lltype.Signed, buf, 0)
- assert res == 42
- res = str_storage_getitem(lltype.Signed, buf, size)
- assert res == 43
- res = str_storage_getitem(lltype.Float, buf, size*2)
- assert res == 123.0
-
class TestRawStorage(BaseRtypingTest):
def test_storage_int(self):
@@ -57,21 +45,6 @@
x = self.interpret(f, [1<<30])
assert x == 1 << 30
- def test_str_storage_int(self):
- import struct
- buf = struct.pack('@ll', 42, 43)
- size = struct.calcsize('@l')
-
- def f(i):
- res = str_storage_getitem(lltype.Signed, buf, i)
- return res
-
- x = self.interpret(f, [0])
- assert x == 42
- x = self.interpret(f, [8])
- assert x == 43
-
-
def test_storage_float_unaligned(self, monkeypatch):
def f(v):
r = alloc_raw_storage(24)
diff --git a/rpython/rlib/test/test_strstorage.py b/rpython/rlib/test/test_strstorage.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/test/test_strstorage.py
@@ -0,0 +1,33 @@
+import py
+import struct
+from rpython.rtyper.lltypesystem import lltype
+from rpython.rlib.strstorage import str_storage_getitem
+from rpython.rtyper.test.tool import BaseRtypingTest
+
+class BaseStrStorageTest:
+
+ def test_signed(self):
+ buf = struct.pack('@ll', 42, 43)
+ size = struct.calcsize('@l')
+ assert self.str_storage_getitem(lltype.Signed, buf, 0) == 42
+ assert self.str_storage_getitem(lltype.Signed, buf, size) == 43
+
+ def test_float(self):
+ buf = struct.pack('@dd', 12.3, 45.6)
+ size = struct.calcsize('@d')
+ assert self.str_storage_getitem(lltype.Float, buf, 0) == 12.3
+ assert self.str_storage_getitem(lltype.Float, buf, size) == 45.6
+
+
+class TestDirect(BaseStrStorageTest):
+
+ def str_storage_getitem(self, TYPE, buf, offset):
+ return str_storage_getitem(TYPE, buf, offset)
+
+
+class TestRTyping(BaseStrStorageTest, BaseRtypingTest):
+
+ def str_storage_getitem(self, TYPE, buf, offset):
+ def fn(offset):
+ return str_storage_getitem(TYPE, buf, offset)
+ return self.interpret(fn, [offset])
More information about the pypy-commit
mailing list