Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
582f2f67
Commit
582f2f67
authored
Jul 18, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffer testcase fix
parent
8b25abbb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
13 deletions
+30
-13
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+30
-13
No files found.
tests/run/bufaccess.pyx
View file @
582f2f67
...
@@ -4,21 +4,29 @@ __doc__ = u"""
...
@@ -4,21 +4,29 @@ __doc__ = u"""
>>> A = MockBuffer("i", range(10), label="A")
>>> A = MockBuffer("i", range(10), label="A")
>>> B = MockBuffer("i", range(10), label="B")
>>> B = MockBuffer("i", range(10), label="B")
>>> E = ErrorBuffer("E")
>>> E = ErrorBuffer("E")
>>> acquire_release(A, B)
>>> acquire_release(A, B)
acquired A
acquired A
released A
released A
acquired B
acquired B
released B
released B
Apparently, doctest won't handle mixed exceptions and print
stats, so need to circumvent this.
>>> A.resetlog()
>>> acquire_raise(A)
>>> acquire_raise(A)
acquired A
released A
Traceback (most recent call last):
Traceback (most recent call last):
...
...
Exception: on purpose
Exception: on purpose
>>> A.printlog()
acquired A
released A
>>> printbuf_float(MockBuffer("f", [1.0, 1.25, 0.75, 1.0]), (4,))
>>> printbuf_float(MockBuffer("f", [1.0, 1.25, 0.75, 1.0]), (4,))
acquired
acquired
1.0 1.25 0.75 1.0
1.0 1.25 0.75 1.0
released
released
>>> printbuf_int_2d(MockBuffer("i", range(6), (2,3)), (2,3))
>>> printbuf_int_2d(MockBuffer("i", range(6), (2,3)), (2,3))
acquired
acquired
0 1 2
0 1 2
...
@@ -26,6 +34,7 @@ __doc__ = u"""
...
@@ -26,6 +34,7 @@ __doc__ = u"""
released
released
"""
"""
def
acquire_release
(
o1
,
o2
):
def
acquire_release
(
o1
,
o2
):
cdef
object
[
int
]
buf
cdef
object
[
int
]
buf
buf
=
o1
buf
=
o1
...
@@ -34,6 +43,7 @@ def acquire_release(o1, o2):
...
@@ -34,6 +43,7 @@ def acquire_release(o1, o2):
def
acquire_raise
(
o
):
def
acquire_raise
(
o
):
cdef
object
[
int
]
buf
cdef
object
[
int
]
buf
buf
=
o
buf
=
o
print
"a"
raise
Exception
(
"on purpose"
)
raise
Exception
(
"on purpose"
)
def
printbuf_float
(
o
,
shape
):
def
printbuf_float
(
o
,
shape
):
...
@@ -82,10 +92,11 @@ cdef class MockBuffer:
...
@@ -82,10 +92,11 @@ cdef class MockBuffer:
cdef
Py_ssize_t
*
strides
cdef
Py_ssize_t
*
strides
cdef
Py_ssize_t
*
shape
cdef
Py_ssize_t
*
shape
cdef
write_func_ptr
wfunc
cdef
write_func_ptr
wfunc
cdef
object
label
cdef
object
label
,
log
def
__init__
(
self
,
typechar
,
data
,
shape
=
None
,
strides
=
None
,
format
=
None
,
label
=
None
):
def
__init__
(
self
,
typechar
,
data
,
shape
=
None
,
strides
=
None
,
format
=
None
,
label
=
None
):
self
.
label
=
label
self
.
label
=
label
self
.
log
=
""
if
format
is
None
:
format
=
"=%s"
%
typechar
if
format
is
None
:
format
=
"=%s"
%
typechar
self
.
itemsize
,
x
=
typemap
[
typechar
]
self
.
itemsize
,
x
=
typemap
[
typechar
]
self
.
wfunc
=
<
write_func_ptr
><
unsigned
long
>
x
self
.
wfunc
=
<
write_func_ptr
><
unsigned
long
>
x
...
@@ -111,6 +122,7 @@ cdef class MockBuffer:
...
@@ -111,6 +122,7 @@ cdef class MockBuffer:
self
.
shape
=
<
Py_ssize_t
*>
stdlib
.
malloc
(
self
.
ndim
*
sizeof
(
Py_ssize_t
))
self
.
shape
=
<
Py_ssize_t
*>
stdlib
.
malloc
(
self
.
ndim
*
sizeof
(
Py_ssize_t
))
def
__getbuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
,
int
flags
):
def
__getbuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
,
int
flags
):
global
log
if
buffer
is
NULL
:
if
buffer
is
NULL
:
print
u"locking!"
print
u"locking!"
return
return
...
@@ -124,24 +136,29 @@ cdef class MockBuffer:
...
@@ -124,24 +136,29 @@ cdef class MockBuffer:
buffer
.
suboffsets
=
NULL
buffer
.
suboffsets
=
NULL
buffer
.
itemsize
=
self
.
itemsize
buffer
.
itemsize
=
self
.
itemsize
buffer
.
internal
=
NULL
buffer
.
internal
=
NULL
print
"acquired"
,
msg
=
"acquired"
if
self
.
label
:
if
self
.
label
:
msg
+=
" "
+
self
.
label
print
self
.
label
print
msg
else
:
self
.
log
+=
msg
+
"
\
n
"
print
def
__releasebuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
):
def
__releasebuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
):
print
"released"
,
global
log
if
self
.
label
:
msg
=
"released"
print
self
.
label
if
self
.
label
:
msg
+=
" "
+
self
.
label
else
:
print
msg
print
self
.
log
+=
msg
+
"
\
n
"
cdef
fill_buffer
(
self
,
typechar
,
object
data
):
cdef
fill_buffer
(
self
,
typechar
,
object
data
):
cdef
char
*
it
=
self
.
buffer
cdef
char
*
it
=
self
.
buffer
for
value
in
data
:
for
value
in
data
:
it
=
self
.
wfunc
(
it
,
value
)
it
=
self
.
wfunc
(
it
,
value
)
def
printlog
(
self
):
print
self
.
log
,
def
resetlog
(
self
):
self
.
log
=
""
cdef
class
ErrorBuffer
:
cdef
class
ErrorBuffer
:
cdef
object
label
cdef
object
label
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment