[pypy-commit] cffi buffer_richcompare: Add tests for buffer comparisons
coronafire
pypy.commits at gmail.com
Mon Feb 6 03:24:48 EST 2017
Author: Andrew Leech <andrew at alelec.net>
Branch: buffer_richcompare
Changeset: r2882:84ec6d83b6fe
Date: 2017-02-03 13:03 +1100
http://bitbucket.org/cffi/cffi/changeset/84ec6d83b6fe/
Log: Add tests for buffer comparisons
diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py
--- a/testing/cffi0/backend_tests.py
+++ b/testing/cffi0/backend_tests.py
@@ -1225,6 +1225,23 @@
assert list(a)[:1000] + [0] * (len(a)-1000) == list(b)
f.close()
+ def test_ffi_buffer_comparisons(self):
+ ffi = FFI(backend=self.Backend())
+ ba = bytearray(range(100, 110))
+ a = ffi.new("uint8_t[]", list(ba))
+ try:
+ b_full = ffi.buffer(a)
+ b_short = ffi.buffer(a, 3)
+ b_mid = ffi.buffer(a, 6)
+ except NotImplementedError as e:
+ py.test.skip(str(e))
+ else:
+ content = b_full[:]
+ assert content == b_full == ba
+ assert b_short < b_mid < b_full
+ assert ba > b_mid > ba[0:2]
+ assert b_short != ba[1:4]
+
def test_array_in_struct(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("struct foo_s { int len; short data[5]; };")
diff --git a/testing/cffi0/test_ffi_backend.py b/testing/cffi0/test_ffi_backend.py
--- a/testing/cffi0/test_ffi_backend.py
+++ b/testing/cffi0/test_ffi_backend.py
@@ -191,10 +191,10 @@
s = ffi.new("struct s1 *")
setattr(s, name, value)
assert getattr(s, name) == value
- raw1 = ffi.buffer(s)[:]
+ buff1 = ffi.buffer(s)
t = lib.try_with_value(fnames.index(name), value)
- raw2 = ffi.buffer(t, len(raw1))[:]
- assert raw1 == raw2
+ buff2 = ffi.buffer(t, len(buff1))
+ assert buff1 == buff2
def test_bitfield_basic(self):
self.check("int a; int b:9; int c:20; int y;", 8, 4, 12)
More information about the pypy-commit
mailing list