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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9db9509f
Commit
9db9509f
authored
May 01, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up some test code.
parent
4736e009
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
18 deletions
+16
-18
tests/buffers/mockbuffers.pxi
tests/buffers/mockbuffers.pxi
+16
-18
No files found.
tests/buffers/mockbuffers.pxi
View file @
9db9509f
from
libc
cimport
stdlib
from
libc
cimport
stdlib
from
libc
cimport
stdio
cimport
cpython.buffer
cimport
cpython.buffer
import
sys
import
sys
...
@@ -34,7 +33,7 @@ cdef class MockBuffer:
...
@@ -34,7 +33,7 @@ cdef class MockBuffer:
cdef
Py_ssize_t
x
,
s
,
cumprod
,
itemsize
cdef
Py_ssize_t
x
,
s
,
cumprod
,
itemsize
self
.
label
=
label
self
.
label
=
label
self
.
release_ok
=
True
self
.
release_ok
=
True
self
.
log
=
""
self
.
log
=
u
""
self
.
offset
=
offset
self
.
offset
=
offset
self
.
itemsize
=
itemsize
=
self
.
get_itemsize
()
self
.
itemsize
=
itemsize
=
self
.
get_itemsize
()
self
.
writable
=
writable
self
.
writable
=
writable
...
@@ -138,7 +137,7 @@ cdef class MockBuffer:
...
@@ -138,7 +137,7 @@ cdef class MockBuffer:
self
.
received_flags
.
append
(
name
)
self
.
received_flags
.
append
(
name
)
if
flags
&
cpython
.
buffer
.
PyBUF_WRITABLE
and
not
self
.
writable
:
if
flags
&
cpython
.
buffer
.
PyBUF_WRITABLE
and
not
self
.
writable
:
raise
BufferError
(
"Writable buffer requested from read-only mock: %s"
%
' | '
.
join
(
self
.
received_flags
)
)
raise
BufferError
(
f"Writable buffer requested from read-only mock:
{
' | '
.
join
(
self
.
received_flags
)
}
"
)
buffer
.
buf
=
<
void
*>
(
<
char
*>
self
.
buffer
+
(
<
int
>
self
.
offset
*
self
.
itemsize
))
buffer
.
buf
=
<
void
*>
(
<
char
*>
self
.
buffer
+
(
<
int
>
self
.
offset
*
self
.
itemsize
))
buffer
.
obj
=
self
buffer
.
obj
=
self
...
@@ -152,29 +151,29 @@ cdef class MockBuffer:
...
@@ -152,29 +151,29 @@ cdef class MockBuffer:
buffer
.
itemsize
=
self
.
itemsize
buffer
.
itemsize
=
self
.
itemsize
buffer
.
internal
=
NULL
buffer
.
internal
=
NULL
if
self
.
label
:
if
self
.
label
:
msg
=
"acquired %s"
%
self
.
label
msg
=
f"acquired
{
self
.
label
}
"
print
msg
print
(
msg
)
self
.
log
+=
msg
+
"
\
n
"
self
.
log
+=
msg
+
u
"
\
n
"
def
__releasebuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
):
def
__releasebuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
):
if
buffer
.
suboffsets
!=
self
.
suboffsets
:
if
buffer
.
suboffsets
!=
self
.
suboffsets
:
self
.
release_ok
=
False
self
.
release_ok
=
False
if
self
.
label
:
if
self
.
label
:
msg
=
"released %s"
%
self
.
label
msg
=
f"released
{
self
.
label
}
"
print
msg
print
(
msg
)
self
.
log
+=
msg
+
"
\
n
"
self
.
log
+=
msg
+
u
"
\
n
"
def
printlog
(
self
):
def
printlog
(
self
):
print
self
.
log
[:
-
1
]
print
(
self
.
log
[:
-
1
])
def
resetlog
(
self
):
def
resetlog
(
self
):
self
.
log
=
""
self
.
log
=
u
""
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
raise
Exception
()
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
raise
Exception
()
cdef
get_itemsize
(
self
):
cdef
get_itemsize
(
self
):
print
"ERROR, not subclassed"
,
self
.
__class__
print
(
f"ERROR, not subclassed:
{
self
.
__class__
}
"
)
cdef
get_default_format
(
self
):
cdef
get_default_format
(
self
):
print
"ERROR, not subclassed"
,
self
.
__class__
print
(
f"ERROR, not subclassed
{
self
.
__class__
}
"
)
cdef
class
CharMockBuffer
(
MockBuffer
):
cdef
class
CharMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
...
@@ -246,10 +245,10 @@ cdef class ErrorBuffer:
...
@@ -246,10 +245,10 @@ cdef class ErrorBuffer:
self
.
label
=
label
self
.
label
=
label
def
__getbuffer__
(
ErrorBuffer
self
,
Py_buffer
*
buffer
,
int
flags
):
def
__getbuffer__
(
ErrorBuffer
self
,
Py_buffer
*
buffer
,
int
flags
):
raise
Exception
(
"acquiring %s"
%
self
.
label
)
raise
Exception
(
f"acquiring
{
self
.
label
}
"
)
def
__releasebuffer__
(
ErrorBuffer
self
,
Py_buffer
*
buffer
):
def
__releasebuffer__
(
ErrorBuffer
self
,
Py_buffer
*
buffer
):
raise
Exception
(
"releasing %s"
%
self
.
label
)
raise
Exception
(
f"releasing
{
self
.
label
}
"
)
#
#
# Structs
# Structs
...
@@ -336,13 +335,12 @@ cdef class LongComplexMockBuffer(MockBuffer):
...
@@ -336,13 +335,12 @@ cdef class LongComplexMockBuffer(MockBuffer):
def
print_offsets
(
*
args
,
size
,
newline
=
True
):
def
print_offsets
(
*
args
,
size
,
newline
=
True
):
sys
.
stdout
.
write
(
' '
.
join
([
str
(
item
//
size
)
for
item
in
args
]))
sys
.
stdout
.
write
(
' '
.
join
([
str
(
item
//
size
)
for
item
in
args
])
+
(
'
\
n
'
if
newline
else
''
))
if
newline
:
sys
.
stdout
.
write
(
'
\
n
'
)
def
print_int_offsets
(
*
args
,
newline
=
True
):
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
shape_5_3_4_list
=
[[
list
(
range
(
k
*
12
+
j
*
4
,
k
*
12
+
j
*
4
+
4
))
shape_5_3_4_list
=
[[
list
(
range
(
k
*
12
+
j
*
4
,
k
*
12
+
j
*
4
+
4
))
for
j
in
range
(
3
)]
for
j
in
range
(
3
)]
for
k
in
range
(
5
)]
for
k
in
range
(
5
)]
...
...
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