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
Xavier Thompson
cython
Commits
305a445f
Commit
305a445f
authored
Sep 02, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some py3 doctests
parent
de9757c2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
65 deletions
+69
-65
tests/errors/cdef_members_T517.pyx
tests/errors/cdef_members_T517.pyx
+0
-2
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+9
-24
tests/run/memslice.pyx
tests/run/memslice.pyx
+19
-35
tests/run/mockbuffers.pxi
tests/run/mockbuffers.pxi
+34
-0
tests/run/struct_conversion.pyx
tests/run/struct_conversion.pyx
+7
-4
No files found.
tests/errors/cdef_members_T517.pyx
View file @
305a445f
...
...
@@ -23,7 +23,5 @@ _ERRORS = u"""
9:24: C attribute of type 'VoidP' cannot be accessed from Python
9:24: Cannot convert 'VoidP' to Python object
9:24: Cannot convert Python object to 'VoidP'
17:22: C attribute of type 'Foo' cannot be accessed from Python
17:22: Cannot convert Python object to 'Foo'
"""
tests/run/memoryview.pyx
View file @
305a445f
...
...
@@ -133,12 +133,12 @@ def basic_struct(MyStruct[:] mslice):
See also buffmt.pyx
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
[('a', 1), ('b', 2), ('c', 3
L
), ('d', 4), ('e', 5)]
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="bbqii"))
[('a', 1), ('b', 2), ('c', 3
L
), ('d', 4), ('e', 5)]
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
"""
buf
=
mslice
print
sorted
(
buf
[
0
].
items
()
)
print
sorted
(
[(
k
,
int
(
v
))
for
k
,
v
in
buf
[
0
].
items
()]
)
def
nested_struct
(
NestedStruct
[:]
mslice
):
"""
...
...
@@ -588,15 +588,6 @@ def assign_temporary_to_object(object[:] mslice):
buf
=
mslice
buf
[
1
]
=
{
3
-
2
:
2
+
(
2
*
4
)
-
2
}
def
print_offsets
(
*
args
,
size
=
0
,
newline
=
True
):
for
item
in
args
:
print
item
//
size
,
if
newline
:
print
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
def
test_generic_slicing
(
arg
,
indirect
=
False
):
"""
Test simple slicing
...
...
@@ -616,8 +607,7 @@ def test_generic_slicing(arg, indirect=False):
released A
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)), indirect=True)
>>> test_generic_slicing(IntMockBuffer("A", shape_5_3_4_list, shape=(5, 3, 4)), indirect=True)
acquired A
(2, 0, 2)
0 1 -1
...
...
@@ -625,8 +615,7 @@ def test_generic_slicing(arg, indirect=False):
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)), indirect=True)
>>> test_generic_slicing(IntMockBuffer("A", shape_9_14_21_list, shape=(9, 14, 21)), indirect=True)
acquired A
(3, 9, 2)
10 1 -1
...
...
@@ -640,8 +629,8 @@ def test_generic_slicing(arg, indirect=False):
print
b
.
shape
if
indirect
:
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
0
]
/
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
else
:
print_int_offsets
(
b
.
strides
[
0
],
b
.
strides
[
1
],
b
.
strides
[
2
])
...
...
@@ -658,18 +647,14 @@ def test_generic_slicing(arg, indirect=False):
def
test_indirect_slicing
(
arg
):
"""
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_indirect_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)))
>>> test_indirect_slicing(IntMockBuffer("A", shape_5_3_4_list, shape=(5, 3, 4)))
acquired A
(5, 3, 2)
0 0 -1
58
released A
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_indirect_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)))
>>> test_indirect_slicing(IntMockBuffer("A", shape_9_14_21_list, shape=(9, 14, 21)))
acquired A
(5, 14, 3)
0 16 -1
...
...
tests/run/memslice.pyx
View file @
305a445f
# mode: run
# Note: see also bufaccess.pyx
from
__future__
import
unicode_literals
...
...
@@ -5,20 +7,22 @@ from __future__ import unicode_literals
cimport
cython
from
cython
cimport
view
__test__
=
{}
import
sys
import
re
exclude
=
[]
#re.compile('object').search]
__test__
=
{}
def
testcase
(
func
):
for
e
in
exclude
:
if
e
(
func
.
__name__
):
return
func
doctest
=
func
.
__doc__
if
sys
.
version_info
>=
(
3
,
1
,
1
):
doctest
=
doctest
.
replace
(
'does not have the buffer interface'
,
'does not support the buffer interface'
)
if
sys
.
version_info
>=
(
3
,
0
):
_u
=
str
else
:
_u
=
unicode
if
not
isinstance
(
doctest
,
_u
):
doctest
=
doctest
.
decode
(
'UTF-8'
)
__test__
[
func
.
__name__
]
=
doctest
return
func
...
...
@@ -129,7 +133,6 @@ def acquire_failure3():
except
Exception
:
print
buf
[
0
],
buf
[
3
]
@
testcase
def
acquire_nonbuffer1
(
first
,
second
=
None
):
"""
...
...
@@ -171,7 +174,6 @@ def acquire_nonbuffer2():
except
Exception
:
print
buf
[
0
],
buf
[
3
]
@
testcase
def
as_argument
(
int
[:]
bufarg
,
int
n
):
"""
...
...
@@ -545,7 +547,6 @@ def generic(int[::view.generic, ::view.generic] buf1,
# Note: disabled. generic_contiguous isn't very useful (you have to check suboffsets,
# might as well multiply with strides)
# @testcase
# def generic_contig(int[::view.generic_contiguous, :] buf1,
# int[::view.generic_contiguous, :] buf2):
# """
...
...
@@ -1068,6 +1069,7 @@ def complex_struct_inplace(LongComplex[:] buf):
#
# Nogil
#
@
testcase
@
cython
.
boundscheck
(
False
)
def
buffer_nogil
():
...
...
@@ -1173,16 +1175,6 @@ def test_cdef_function2():
cdef
_function2
(
global_A
,
global_B
)
def
print_offsets
(
*
args
,
size
=
0
,
newline
=
True
):
for
item
in
args
:
print
item
//
size
,
if
newline
:
print
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
@
testcase
def
test_generic_slicing
(
arg
,
indirect
=
False
):
"""
...
...
@@ -1203,17 +1195,13 @@ def test_generic_slicing(arg, indirect=False):
released A
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)), indirect=True)
>>> test_generic_slicing(IntMockBuffer("A", shape_5_3_4_list, shape=(5, 3, 4)), indirect=True)
acquired A
2 0 2
0 1 -1
released A
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)), indirect=True)
>>> test_generic_slicing(IntMockBuffer("A", shape_9_14_21_list, shape=(9, 14, 21)), indirect=True)
acquired A
3 9 2
10 1 -1
...
...
@@ -1226,8 +1214,8 @@ def test_generic_slicing(arg, indirect=False):
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
if
indirect
:
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
0
]
/
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
else
:
print_int_offsets
(
b
.
strides
[
0
],
b
.
strides
[
1
],
b
.
strides
[
2
])
...
...
@@ -1245,8 +1233,7 @@ def test_generic_slicing(arg, indirect=False):
def
test_indirect_slicing
(
arg
):
"""
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_indirect_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)))
>>> test_indirect_slicing(IntMockBuffer("A", shape_5_3_4_list, shape=(5, 3, 4)))
acquired A
5 3 2
0 0 -1
...
...
@@ -1254,10 +1241,7 @@ def test_indirect_slicing(arg):
56
released A
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_indirect_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)))
>>> test_indirect_slicing(IntMockBuffer("A", shape_9_14_21_list, shape=(9, 14, 21)))
acquired A
5 14 3
0 16 -1
...
...
@@ -1270,8 +1254,8 @@ def test_indirect_slicing(arg):
cdef
int
[::
view
.
indirect
,
::
view
.
indirect
]
c
=
b
[...,
0
]
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
0
]
/
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
print
b
[
4
,
2
,
1
]
...
...
tests/run/mockbuffers.pxi
View file @
305a445f
...
...
@@ -5,6 +5,7 @@ cimport cython
from
cpython
cimport
PyObject
,
Py_INCREF
,
Py_DECREF
import
sys
available_flags
=
(
(
'FORMAT'
,
cpython
.
buffer
.
PyBUF_FORMAT
),
...
...
@@ -328,3 +329,36 @@ cdef class LongComplexMockBuffer(MockBuffer):
cdef
get_itemsize
(
self
):
return
sizeof
(
LongComplex
)
cdef
get_default_format
(
self
):
return
b"Zg"
def
print_offsets
(
*
args
,
size
=
0
,
newline
=
True
):
"""
print with a trailing comma does not have the same semantics in python 3.
Use sys.stdout.write instead.
# python 2
->> print 'foo',; sys.stdout.write('bar
\
n
') # no space between foo and bar
foobar
In python 3 you get trailing spaces from the last ','
"""
for
idx
,
item
in
enumerate
(
args
):
if
idx
==
len
(
args
)
-
1
:
sys
.
stdout
.
write
(
str
(
item
//
size
))
else
:
sys
.
stdout
.
write
(
'%s '
%
(
item
//
size
))
if
newline
:
sys
.
stdout
.
write
(
'
\
n
'
)
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
shape_5_3_4_list
=
[[
list
(
range
(
k
*
12
+
j
*
4
,
k
*
12
+
j
*
4
+
4
))
for
j
in
range
(
3
)]
for
k
in
range
(
5
)]
stride1
=
21
*
14
stride2
=
21
shape_9_14_21_list
=
[[
list
(
range
(
k
*
stride1
+
j
*
stride2
,
k
*
stride1
+
j
*
stride2
+
21
))
for
j
in
range
(
14
)]
for
k
in
range
(
9
)]
tests/run/struct_conversion.pyx
View file @
305a445f
...
...
@@ -84,7 +84,7 @@ def test_obj_to_struct(MyStruct mystruct):
...
TypeError: an integer is required
"""
print
'c=%d i=%d f=%.2f s=%s'
%
(
mystruct
.
c
,
mystruct
.
i
,
mystruct
.
f
,
mystruct
.
s
)
print
'c=%d i=%d f=%.2f s=%s'
%
(
mystruct
.
c
,
mystruct
.
i
,
mystruct
.
f
,
mystruct
.
s
.
decode
(
'UTF-8'
)
)
cdef
struct
NestedStruct
:
MyStruct
mystruct
...
...
@@ -92,7 +92,7 @@ cdef struct NestedStruct:
def
test_nested_obj_to_struct
(
NestedStruct
nested
):
"""
>>> test_nested_obj_to_struct(dict(mystruct=dict(c=10, i=20, f=6.7, s="hello"), d=4.5))
>>> test_nested_obj_to_struct(dict(mystruct=dict(c=10, i=20, f=6.7, s=
b
"hello"), d=4.5))
c=10 i=20 f=6.70 s=hello d=4.50
>>> test_nested_obj_to_struct(dict(d=7.6))
Traceback (most recent call last):
...
...
@@ -103,6 +103,9 @@ def test_nested_obj_to_struct(NestedStruct nested):
...
ValueError: No value specified for struct attribute 'c'
"""
print
'c=%d i=%d f=%.2f s=%s d=%.2f'
%
(
nested
.
mystruct
.
c
,
nested
.
mystruct
.
i
,
nested
.
mystruct
.
f
,
nested
.
mystruct
.
s
,
nested
.
d
)
print
'c=%d i=%d f=%.2f s=%s d=%.2f'
%
(
nested
.
mystruct
.
c
,
nested
.
mystruct
.
i
,
nested
.
mystruct
.
f
,
nested
.
mystruct
.
s
.
decode
(
'UTF-8'
),
nested
.
d
)
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