From: Dag Sverre Seljebotn Date: Tue, 29 Jul 2008 08:55:36 +0000 (+0200) Subject: Buffer setting testcase X-Git-Tag: 0.9.8.1~49^2~55 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=437fcb17307c807484db074160fed895f3a76496;p=cython.git Buffer setting testcase --- diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index dc830277..3c005133 100755 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -313,11 +313,12 @@ def explicitly_release_buffer(): @testcase def get_int_2d(object[int, 2] buf, int i, int j): """ - Check negative indexing: >>> get_int_2d(C, 1, 1) acquired C released C 4 + + Check negative indexing: >>> get_int_2d(C, -1, 0) acquired C released C @@ -361,6 +362,57 @@ def get_int_2d_uintindex(object[int, 2] buf, unsigned int i, unsigned int j): # generated. return buf[i, j] +@testcase +def set_int_2d(object[int, 2] buf, int i, int j, int value): + """ + Uses get_int_2d to read back the value afterwards. For pure + unit test, one should support reading in MockBuffer instead. + + >>> set_int_2d(C, 1, 1, 10) + acquired C + released C + >>> get_int_2d(C, 1, 1) + acquired C + released C + 10 + + Check negative indexing: + >>> set_int_2d(C, -1, 0, 3) + acquired C + released C + >>> get_int_2d(C, -1, 0) + acquired C + released C + 3 + + >>> set_int_2d(C, -1, -2, 8) + acquired C + released C + >>> get_int_2d(C, -1, -2) + acquired C + released C + 8 + + >>> set_int_2d(C, -2, -3, 9) + acquired C + released C + >>> get_int_2d(C, -2, -3) + acquired C + released C + 9 + + Out-of-bounds errors: + >>> set_int_2d(C, 2, 0, 19) + Traceback (most recent call last): + ... + IndexError: Out of bounds on buffer access (axis 0) + >>> set_int_2d(C, 0, -4, 19) + Traceback (most recent call last): + ... + IndexError: Out of bounds on buffer access (axis 1) + + """ + buf[i, j] = value # # Buffer type mismatch examples. Varying the type and access