diff options
author | Sergey Vorfolomeev <sergey.vorfolomeev@vmssoftware.com> | 2021-04-09 08:29:05 +0500 |
---|---|---|
committer | Sergey Vorfolomeev <sergey.vorfolomeev@vmssoftware.com> | 2021-04-09 08:29:05 +0500 |
commit | c48fc339035511967023aa9783ce8afc1c00a492 (patch) | |
tree | a59352e46c3497219973c15158cd1231876099a9 /c/test_c.py | |
parent | 836a60368633def79b7fe439be845f5272f4bc9e (diff) | |
parent | f17762f93b1f882554b6fe12c8271f907aebf6ad (diff) | |
download | cffi-openvms.tar.gz |
merge default to 'openvms'openvms
changed:
.hgtags
c/_cffi_backend.c
c/ffi_obj.c
c/test_c.py
cffi/__init__.py
cffi/_embedding.h
cffi/recompiler.py
cffi/verifier.py
doc/source/conf.py
doc/source/installation.rst
doc/source/whatsnew.rst
setup.py
setup_base.py
testing/cffi0/test_ffi_backend.py
testing/cffi0/test_version.py
testing/cffi1/test_re_python.py
Diffstat (limited to 'c/test_c.py')
-rw-r--r-- | c/test_c.py | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/c/test_c.py b/c/test_c.py index 95ca812..788500e 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -17,7 +17,7 @@ from _cffi_backend import __version__ # ____________________________________________________________ import sys -assert __version__ == "1.14.3", ("This test_c.py file is for testing a version" +assert __version__ == "1.14.5", ("This test_c.py file is for testing a version" " of cffi that differs from the one that we" " get from 'import _cffi_backend'") if sys.version_info < (3,): @@ -1331,7 +1331,9 @@ def test_callback_exception(): except ImportError: import io as cStringIO # Python 3 import linecache - def matches(istr, ipattern): + def matches(istr, ipattern, ipattern38): + if sys.version_info >= (3, 8): + ipattern = ipattern38 str, pattern = istr, ipattern while '$' in pattern: i = pattern.index('$') @@ -1375,6 +1377,14 @@ Traceback (most recent call last): File "$", line $, in check_value $ ValueError: 42 +""", """\ +Exception ignored from cffi callback <function$Zcb1 at 0x$>: +Traceback (most recent call last): + File "$", line $, in Zcb1 + $ + File "$", line $, in check_value + $ +ValueError: 42 """) sys.stderr = cStringIO.StringIO() bigvalue = 20000 @@ -1383,6 +1393,12 @@ ValueError: 42 From cffi callback <function$Zcb1 at 0x$>: Trying to convert the result back to C: OverflowError: integer 60000 does not fit 'short' +""", """\ +Exception ignored from cffi callback <function$Zcb1 at 0x$>, trying to convert the result back to C: +Traceback (most recent call last): + File "$", line $, in test_callback_exception + $ +OverflowError: integer 60000 does not fit 'short' """) sys.stderr = cStringIO.StringIO() bigvalue = 20000 @@ -1420,6 +1436,17 @@ OverflowError: integer 60000 does not fit 'short' During the call to 'onerror', another exception occurred: TypeError: $integer$ +""", """\ +Exception ignored from cffi callback <function$Zcb1 at 0x$>, trying to convert the result back to C: +Traceback (most recent call last): + File "$", line $, in test_callback_exception + $ +OverflowError: integer 60000 does not fit 'short' +Exception ignored during handling of the above exception by 'onerror': +Traceback (most recent call last): + File "$", line $, in test_callback_exception + $ +TypeError: $integer$ """) # sys.stderr = cStringIO.StringIO() @@ -1436,6 +1463,17 @@ Traceback (most recent call last): File "$", line $, in oops $ AttributeError: 'str' object has no attribute 'append' +""", """\ +Exception ignored from cffi callback <function$Zcb1 at 0x$>, trying to convert the result back to C: +Traceback (most recent call last): + File "$", line $, in test_callback_exception + $ +OverflowError: integer 60000 does not fit 'short' +Exception ignored during handling of the above exception by 'onerror': +Traceback (most recent call last): + File "$", line $, in oops + $ +AttributeError: 'str' object has no attribute 'append' """) finally: sys.stderr = orig_stderr @@ -1470,7 +1508,7 @@ def test_a_lot_of_callbacks(): def make_callback(m): def cb(n): return n + m - return callback(BFunc, cb, 42) # 'cb' and 'BFunc' go out of scope + return callback(BFunc, cb, 42) # 'cb' goes out of scope # flist = [make_callback(i) for i in range(BIGNUM)] for i, f in enumerate(flist): @@ -3974,6 +4012,20 @@ def test_from_buffer_types(): with pytest.raises(ValueError): release(pv[0]) +def test_issue483(): + BInt = new_primitive_type("int") + BIntP = new_pointer_type(BInt) + BIntA = new_array_type(BIntP, None) + lst = list(range(25)) + bytestring = bytearray(buffer(newp(BIntA, lst))[:] + b'XYZ') + p1 = from_buffer(BIntA, bytestring) # int[] + assert len(buffer(p1)) == 25 * size_of_int() + assert sizeof(p1) == 25 * size_of_int() + # + p2 = from_buffer(BIntP, bytestring) + assert sizeof(p2) == size_of_ptr() + assert len(buffer(p2)) == size_of_int() # first element only, by default + def test_memmove(): Short = new_primitive_type("short") ShortA = new_array_type(new_pointer_type(Short), None) @@ -4515,5 +4567,5 @@ def test_unaligned_types(): pbuf1 = cast(new_pointer_type(p), pbuf + 1) pbuf1[0] = num assert pbuf1[0] == num - assert buf[0] == '\x00' - assert buf[1 + size] == '\x00' + assert buf[0] == b'\x00' + assert buf[1 + size] == b'\x00' |