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
Gwenaël Samain
cython
Commits
9a8c817d
Commit
9a8c817d
authored
Jan 01, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loads of doctests
parent
b355d4c9
Changes
35
Hide whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
639 additions
and
55 deletions
+639
-55
tests/compile/getattr3ref.pyx
tests/compile/getattr3ref.pyx
+6
-1
tests/compile/nogil.pyx
tests/compile/nogil.pyx
+1
-1
tests/run/addressof.pyx
tests/run/addressof.pyx
+10
-2
tests/run/ass2global.pyx
tests/run/ass2global.pyx
+15
-3
tests/run/assert.pyx
tests/run/assert.pyx
+19
-2
tests/run/attr.pyx
tests/run/attr.pyx
+63
-2
tests/run/baas3.pyx
tests/run/baas3.pyx
+6
-0
tests/run/behnel1.pyx
tests/run/behnel1.pyx
+10
-5
tests/run/bishop2.pyx
tests/run/bishop2.pyx
+8
-0
tests/run/cfuncdef.pyx
tests/run/cfuncdef.pyx
+9
-0
tests/run/cintop.pyx
tests/run/cintop.pyx
+10
-2
tests/run/cstruct.pyx
tests/run/cstruct.pyx
+41
-1
tests/run/cunion.pyx
tests/run/cunion.pyx
+30
-1
tests/run/dict.pyx
tests/run/dict.pyx
+39
-7
tests/run/dietachmayer1.pyx
tests/run/dietachmayer1.pyx
+6
-1
tests/run/extinherit.pyx
tests/run/extinherit.pyx
+21
-2
tests/run/extlen.pyx
tests/run/extlen.pyx
+5
-0
tests/run/extstarargs.pyx
tests/run/extstarargs.pyx
+42
-0
tests/run/ishimoto2.pyx
tests/run/ishimoto2.pyx
+12
-1
tests/run/kwonlyargs.pyx
tests/run/kwonlyargs.pyx
+65
-0
tests/run/modbody.pyx
tests/run/modbody.pyx
+12
-0
tests/run/modop.pyx
tests/run/modop.pyx
+25
-8
tests/run/naanou_1.pyx
tests/run/naanou_1.pyx
+0
-2
tests/run/new_style_exceptions.pyx
tests/run/new_style_exceptions.pyx
+6
-0
tests/run/pinard5.pyx
tests/run/pinard5.pyx
+15
-3
tests/run/pinard7.pyx
tests/run/pinard7.pyx
+13
-0
tests/run/pyextattrref.pyx
tests/run/pyextattrref.pyx
+4
-0
tests/run/r_mang1.pyx
tests/run/r_mang1.pyx
+10
-0
tests/run/ref2local.pyx
tests/run/ref2local.pyx
+6
-0
tests/run/return.pyx
tests/run/return.pyx
+14
-1
tests/run/slice3.pyx
tests/run/slice3.pyx
+43
-5
tests/run/starargs.pyx
tests/run/starargs.pyx
+40
-1
tests/run/subop.pyx
tests/run/subop.pyx
+22
-3
tests/run/varargcall.pyx
tests/run/varargcall.pyx
+5
-1
tests/run/wundram1.pyx
tests/run/wundram1.pyx
+6
-0
No files found.
tests/compile/getattr3ref.pyx
View file @
9a8c817d
cdef
int
f
()
except
-
1
:
__doc__
=
"""
>>> print f()
"""
def
f
():
g
=
getattr3
g
=
getattr3
return
g
.
__name__
tests/compile/nogil.pyx
View file @
9a8c817d
cdef
extern
object
g
(
objec
t
x
)
nogil
cdef
extern
object
g
(
in
t
x
)
nogil
cdef
void
f
(
int
x
)
nogil
:
cdef
void
f
(
int
x
)
nogil
:
cdef
int
y
cdef
int
y
...
...
tests/run/addressof.pyx
View file @
9a8c817d
def
f
():
__doc__
=
"""
cdef
int
i
>>> f(5)
5
"""
def
f
(
int
a
):
cdef
int
i
,
j
cdef
int
*
p
cdef
int
*
p
i
=
a
p
=
&
i
p
=
&
i
j
=
p
[
0
]
return
j
tests/run/ass2global.pyx
View file @
9a8c817d
__doc__
=
"""
>>> getg()
5
>>> f(42)
>>> getg()
42
"""
g
=
5
def
f
(
a
):
def
f
(
a
):
global
f
global
g
f
=
a
g
=
a
f
=
42
def
getg
():
return
g
tests/run/assert.pyx
View file @
9a8c817d
def
f
(
a
,
b
):
__doc__
=
"""
cdef
int
i
>>> f(1, 2, 1)
>>> f(0, 2, 1)
Traceback (most recent call last):
AssertionError
>>> f(1, -1, 1)
Traceback (most recent call last):
AssertionError
>>> f(1, 2, 0)
Traceback (most recent call last):
AssertionError
>>> g(1, "works")
>>> g(0, "fails")
Traceback (most recent call last):
AssertionError: fails
"""
def
f
(
a
,
b
,
int
i
):
assert
a
assert
a
assert
a
+
b
assert
a
+
b
assert
i
assert
i
...
...
tests/run/attr.pyx
View file @
9a8c817d
def
f
(
a
,
b
):
__doc__
=
"""
>>> class Test:
... def __init__(self, i):
... self.i = i
>>> b = Test(1)
>>> b.spam = Test(2)
>>> b.spam.eggs = Test(3)
>>> b.spam.eggs.spam = Test(4)
>>> b.spam.eggs.spam.eggs = Test(5)
>>> a = f(b)
>>> print a.i
2
>>> print b.i
1
>>> print a.spam.i
1
>>> print b.spam.i
2
>>> print a.spam.eggs.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'eggs'
>>> print b.spam.eggs.i
3
>>> print a.spam.spam.i
2
>>> print b.spam.spam.i
1
>>> print a.spam.eggs.spam.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'eggs'
>>> print b.spam.eggs.spam.i
4
>>> a = g(b)
>>> print a.i
3
>>> print b.i
1
>>> print a.spam.i
4
>>> print b.spam.i
2
>>> print a.spam.eggs.i
1
>>> print b.spam.eggs.i
3
>>> print a.spam.spam.i
Traceback (most recent call last):
AttributeError: Test instance has no attribute 'spam'
>>> print b.spam.spam.i
1
>>> print a.spam.eggs.spam.i
2
>>> print b.spam.eggs.spam.i
4
"""
def
f
(
b
):
a
=
b
.
spam
a
=
b
.
spam
a
.
spam
=
b
a
.
spam
=
b
return
a
def
g
(
b
):
a
=
b
.
spam
.
eggs
a
=
b
.
spam
.
eggs
a
.
spam
.
eggs
=
b
a
.
spam
.
eggs
=
b
return
a
\ No newline at end of file
tests/run/baas3.pyx
View file @
9a8c817d
__doc__
=
"""
>>> m = MyClass()
>>> m is foo(m)
True
"""
cdef
class
MyClass
:
cdef
class
MyClass
:
pass
pass
...
...
tests/run/behnel1.pyx
View file @
9a8c817d
__doc__
=
"""
>>> viking(5)
5
"""
cdef
class
Spam
:
cdef
class
Spam
:
cdef
eggs
(
self
):
cdef
eggs
(
self
,
a
):
pass
return
a
cdef
Spam
spam
():
cdef
Spam
spam
():
pass
return
Spam
()
def
viking
():
def
viking
(
a
):
return
spam
().
eggs
()
return
spam
().
eggs
(
a
)
tests/run/bishop2.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f = foo()
>>> 'a' in f
True
>>> 1 in f
True
"""
cdef
class
foo
:
cdef
class
foo
:
def
__contains__
(
self
,
key
):
def
__contains__
(
self
,
key
):
...
...
tests/run/cfuncdef.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test()
"""
cdef
void
ftang
():
cdef
void
ftang
():
cdef
int
x
cdef
int
x
x
=
0
x
=
0
...
@@ -10,3 +14,8 @@ cdef int foo(int i, char c):
...
@@ -10,3 +14,8 @@ cdef int foo(int i, char c):
cdef
spam
(
int
i
,
obj
,
object
object
):
cdef
spam
(
int
i
,
obj
,
object
object
):
cdef
char
c
cdef
char
c
c
=
0
c
=
0
def
test
():
ftang
()
foo
(
0
,
c
'f'
)
spam
(
25
,
None
,
None
)
tests/run/cintop.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f()
(5376, 67)
"""
def
f
():
def
f
():
cdef
int
int1
,
int2
,
int3
cdef
int
int1
,
int2
,
int3
cdef
char
char1
cdef
char
char1
cdef
long
long1
,
long2
cdef
long
long1
,
long2
int2
=
42
int3
=
7
char1
=
c
'C'
int1
=
int2
|
int3
int1
=
int2
|
int3
int1
=
int2
^
int3
int1
=
int2
^
int3
int1
=
int2
&
int3
int1
=
int2
&
int3
...
@@ -9,5 +18,4 @@ def f():
...
@@ -9,5 +18,4 @@ def f():
int1
=
int2
>>
int3
int1
=
int2
>>
int3
int1
=
int2
<<
int3
|
int2
>>
int3
int1
=
int2
<<
int3
|
int2
>>
int3
long1
=
char1
|
long2
long1
=
char1
|
long2
return
int1
,
long1
\ No newline at end of file
tests/run/cstruct.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test_i()
>>> test_c()
>>> test_p()
>>> test_g()
"""
cdef
struct
Grail
cdef
struct
Grail
cdef
struct
Spam
:
cdef
struct
Spam
:
...
@@ -11,9 +18,42 @@ cdef struct Grail:
...
@@ -11,9 +18,42 @@ cdef struct Grail:
cdef
Spam
spam
,
ham
cdef
Spam
spam
,
ham
cdef
void
eggs
(
Spam
s
):
cdef
void
eggs
_i
(
Spam
s
):
cdef
int
j
cdef
int
j
j
=
s
.
i
j
=
s
.
i
s
.
i
=
j
s
.
i
=
j
cdef
void
eggs_c
(
Spam
s
):
cdef
char
c
c
=
s
.
c
s
.
c
=
c
cdef
void
eggs_p
(
Spam
s
):
cdef
float
*
p
p
=
s
.
p
[
0
]
s
.
p
[
0
]
=
p
cdef
void
eggs_g
(
Spam
s
):
cdef
float
*
p
p
=
s
.
p
[
0
]
s
.
p
[
0
]
=
p
spam
=
ham
spam
=
ham
def
test_i
():
spam
.
i
=
1
eggs_i
(
spam
)
def
test_c
():
spam
.
c
=
c
'a'
eggs_c
(
spam
)
def
test_p
():
cdef
float
f
spam
.
p
[
0
]
=
&
f
eggs_p
(
spam
)
def
test_g
():
cdef
Grail
l
spam
.
g
=
&
l
eggs_g
(
spam
)
tests/run/cunion.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test_i()
>>> test_c()
>>> test_p()
"""
cdef
union
Spam
:
cdef
union
Spam
:
int
i
int
i
char
c
char
c
...
@@ -5,9 +11,32 @@ cdef union Spam:
...
@@ -5,9 +11,32 @@ cdef union Spam:
cdef
Spam
spam
,
ham
cdef
Spam
spam
,
ham
cdef
void
eggs
(
Spam
s
):
cdef
void
eggs
_i
(
Spam
s
):
cdef
int
j
cdef
int
j
j
=
s
.
i
j
=
s
.
i
s
.
i
=
j
s
.
i
=
j
cdef
void
eggs_c
(
Spam
s
):
cdef
char
c
c
=
s
.
c
s
.
c
=
c
cdef
void
eggs_p
(
Spam
s
):
cdef
float
*
p
p
=
s
.
p
[
0
]
s
.
p
[
0
]
=
p
spam
=
ham
spam
=
ham
def
test_i
():
spam
.
i
=
1
eggs_i
(
spam
)
def
test_c
():
spam
.
c
=
c
'a'
eggs_c
(
spam
)
def
test_p
():
cdef
float
f
spam
.
p
[
0
]
=
&
f
eggs_p
(
spam
)
tests/run/dict.pyx
View file @
9a8c817d
def
f
(
adict
,
key1
,
value1
,
key2
,
value2
):
__doc__
=
"""
adict
=
{}
>>> empty()
adict
=
{
key1
:
value1
}
{}
adict
=
{
key1
:
value1
,
key2
:
value2
}
>>> keyvalue(1, 2)
adict
=
{
key1
:
value1
,
key2
:
value2
,}
{1: 2}
adict
=
{
"parrot"
:
"resting"
,
"answer"
:
42
}
>>> keyvalues(1, 2, 3, 4)
\ No newline at end of file
{1: 2, 3: 4}
>>> keyvalues2(1, 2, 3, 4)
{1: 2, 3: 4}
>>> len(constant())
2
>>> constant()['parrot']
'resting'
>>> constant()['answer']
42
"""
def
empty
():
d
=
{}
return
d
def
keyvalue
(
key
,
value
):
d
=
{
key
:
value
}
return
d
def
keyvalues
(
key1
,
value1
,
key2
,
value2
):
d
=
{
key1
:
value1
,
key2
:
value2
}
return
d
def
keyvalues2
(
key1
,
value1
,
key2
,
value2
):
d
=
{
key1
:
value1
,
key2
:
value2
,}
return
d
def
constant
():
d
=
{
"parrot"
:
"resting"
,
"answer"
:
42
}
return
d
tests/run/dietachmayer1.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test()
1.0
"""
def
test
():
def
test
():
cdef
float
v
[
10
][
10
]
cdef
float
v
[
10
][
10
]
v
[
1
][
2
]
=
1.0
v
[
1
][
2
]
=
1.0
print
v
[
1
][
2
]
return
v
[
1
][
2
]
tests/run/extinherit.pyx
View file @
9a8c817d
__doc__
=
"""
>>> p = create()
>>> rest(p)
0
"""
cdef
class
Parrot
:
cdef
class
Parrot
:
cdef
object
name
cdef
object
name
cdef
int
alive
cdef
int
alive
...
@@ -5,11 +11,24 @@ cdef class Parrot:
...
@@ -5,11 +11,24 @@ cdef class Parrot:
cdef
class
Norwegian
(
Parrot
):
cdef
class
Norwegian
(
Parrot
):
cdef
object
plumage_colour
cdef
object
plumage_colour
cdef
void
rest
(
Norwegian
polly
):
def
create
():
cdef
Parrot
p
p
=
Norwegian
()
p
.
alive
=
1
return
p
def
rest
(
Norwegian
polly
):
cdef
Parrot
fred
cdef
Parrot
fred
cdef
object
spam
cdef
object
spam
spam
=
None
fred
=
polly
fred
=
polly
polly
=
fred
polly
=
fred
polly
=
spam
polly
=
spam
assert
polly
is
None
assert
fred
.
alive
spam
=
polly
spam
=
polly
polly
.
alive
=
0
fred
.
alive
=
0
return
fred
.
alive
tests/run/extlen.pyx
View file @
9a8c817d
__doc__
=
"""
>>> len(Spam())
0
"""
cdef
class
Spam
:
cdef
class
Spam
:
def
__len__
(
self
):
def
__len__
(
self
):
...
...
tests/run/extstarargs.pyx
View file @
9a8c817d
__doc__
=
"""
>>> s = Silly(1,2,3, 'test')
>>> s.spam(1,2,3)
>>> s.spam(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> s.spam(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (4 given)
>>> s.spam(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> s.grail(1,2,3)
>>> s.grail(1,2,3,4)
>>> s.grail(1,2,3,4,5,6,7,8,9)
>>> s.grail(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> s.grail(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> s.swallow(1,2,3)
>>> s.swallow(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> s.swallow(1,2,3, a=1, b=2)
>>> s.swallow(1,2,3, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> s.creosote(1,2,3)
>>> s.creosote(1,2,3,4)
>>> s.creosote(1,2,3, a=1)
>>> s.creosote(1,2,3,4, a=1, b=2)
>>> s.creosote(1,2,3,4, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
"""
cdef
class
Silly
:
cdef
class
Silly
:
def
__init__
(
self
,
*
a
):
def
__init__
(
self
,
*
a
):
...
...
tests/run/ishimoto2.pyx
View file @
9a8c817d
__doc__
=
"""
>>> C().xxx(5)
5
>>> C().xxx()
'a b'
>>> C().xxx(42)
42
>>> C().xxx()
'a b'
"""
class
C
:
class
C
:
def
xxx
(
self
,
p
=
"a b"
):
def
xxx
(
self
,
p
=
"a b"
):
pass
return
p
tests/run/kwonlyargs.pyx
View file @
9a8c817d
__doc__
=
"""
>>> c(1,2,3)
>>> c(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (4 given)
>>> d(1,2)
>>> d(1,2, c=1)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError: 'd' is an invalid keyword argument for this function
>>> e(1,2)
>>> e(1,2, c=1)
>>> e(1,2, d=1)
>>> e(1,2, c=1, d=2, e=3)
>>> e(1,2,3)
>>> e(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> f(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError: 'e' is an invalid keyword argument for this function
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
>>> g(1,2, c=1, f=2, e=0, x=25)
>>> g(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> g(1,2, c=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> h(1,2, c=1, f=2)
>>> h(1,2, c=1, f=2, e=3)
>>> h(1,2,3,4,5,6, c=1, f=2)
>>> h(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11)
>>> h(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> h(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
"""
def
c
(
a
,
b
,
c
):
def
c
(
a
,
b
,
c
):
z
=
33
z
=
33
...
...
tests/run/modbody.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f()
>>> g
42
>>> x
'spam'
>>> y
'eggs'
>>> z
'spameggs'
"""
def
f
():
def
f
():
pass
pass
...
...
tests/run/modop.pyx
View file @
9a8c817d
def
f
():
__doc__
=
"""
cdef
int
int1
,
int2
,
int3
>>> modobj(9,2)
cdef
char
*
str2
,
*
str3
1
obj1
=
1
>>> modobj('%d', 5)
obj2
=
2
'5'
obj3
=
3
>>> modint(9,2)
1
"""
def
modobj
(
obj2
,
obj3
):
obj1
=
obj2
%
obj3
return
obj1
def
modint
(
int
int2
,
int
int3
):
cdef
int
int1
int1
=
int2
%
int3
int1
=
int2
%
int3
return
int1
cdef
modptr
():
# FIXME!!!
cdef
char
*
str2
,
*
str3
str2
=
"spam"
str3
=
"eggs"
obj1
=
str2
%
str3
obj1
=
str2
%
str3
obj1
=
obj2
%
obj3
return
obj1
\ No newline at end of file
tests/run/naanou_1.pyx
deleted
100644 → 0
View file @
b355d4c9
def
f
(
a
,
*
p
,
**
n
):
pass
tests/run/new_style_exceptions.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test(Exception('hi'))
Raising: Exception('hi',)
Caught: <type 'exceptions.Exception'> Exception('hi',)
"""
import
sys
import
sys
def
test
(
obj
):
def
test
(
obj
):
...
...
tests/run/pinard5.pyx
View file @
9a8c817d
__doc__
=
"""
>>> test()
1
"""
cdef
class
Tri
:
cdef
class
Tri
:
pass
def
test
(
self
):
return
1
cdef
class
Curseur
:
cdef
class
Curseur
:
cdef
Tri
tri
cdef
Tri
tri
def
detail
(
self
):
def
detail
(
self
):
produire_fiches
(
self
.
tri
)
return
produire_fiches
(
self
.
tri
)
cdef
produire_fiches
(
Tri
tri
):
cdef
produire_fiches
(
Tri
tri
):
pass
return
tri
.
test
()
def
test
():
cdef
Curseur
c
c
=
Curseur
()
c
.
tri
=
Tri
()
return
c
.
detail
()
tests/run/pinard7.pyx
View file @
9a8c817d
__doc__
=
"""
>>> c = build()
>>> c.method()
Traceback (most recent call last):
AssertionError: 1
"""
cdef
enum
Mode
:
cdef
enum
Mode
:
a
=
1
a
=
1
b
=
2
b
=
2
...
@@ -7,3 +14,9 @@ cdef class Curseur:
...
@@ -7,3 +14,9 @@ cdef class Curseur:
def
method
(
self
):
def
method
(
self
):
assert
False
,
self
.
mode
assert
False
,
self
.
mode
def
build
():
cdef
Curseur
c
c
=
Curseur
()
c
.
mode
=
a
return
c
tests/run/pyextattrref.pyx
View file @
9a8c817d
__doc__
=
"""
>>>
"""
cdef
class
Eggs
:
cdef
class
Eggs
:
cdef
object
ham
cdef
object
ham
...
...
tests/run/r_mang1.pyx
View file @
9a8c817d
__doc__
=
"""
>>> import re
>>> t
('2',)
>>> t == re.search('(
\
\
d+)', '-2.80 98
\
\
n').groups()
True
"""
# this is a string constant test, not a test for 're'
import
re
import
re
t
=
re
.
search
(
'(
\
d+)
'
, '
-
2.80
98
\
n
').groups()
t
=
re
.
search
(
'(
\
d+)
'
, '
-
2.80
98
\
n
').groups()
tests/run/ref2local.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f()
42
"""
def
f
():
def
f
():
a
=
42
a
=
42
b
=
a
b
=
a
return
b
tests/run/return.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f('test')
>>> test_g()
>>> test_h(5)
5
"""
def
f
(
a
):
def
f
(
a
):
return
return
return
a
return
a
...
@@ -8,5 +15,11 @@ cdef void g():
...
@@ -8,5 +15,11 @@ cdef void g():
cdef
int
h
(
a
):
cdef
int
h
(
a
):
cdef
int
i
cdef
int
i
i
=
a
return
i
return
i
\ No newline at end of file
def
test_g
():
g
()
def
test_h
(
i
):
return
h
(
i
)
tests/run/slice3.pyx
View file @
9a8c817d
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
__doc__
=
"""
>>> class Test(object):
... def __setitem__(self, key, value):
... print key, value
... def __getitem__(self, key):
... print key
... return self
>>> ellipsis(Test())
Ellipsis
>>> full(Test())
slice(None, None, None)
>>> select(0, Test(), 10, 20, 30)
slice(10, None, None)
slice(None, 20, None)
slice(None, None, 30)
slice(10, 20, None)
slice(10, None, 30)
slice(None, 20, 30)
slice(10, 20, 30)
slice(1, 2, 3)
>>> set(Test(), -11)
slice(1, 2, 3) -11
"""
def
ellipsis
(
o
):
obj1
=
o
[...]
def
full
(
o
):
obj1
=
o
[::]
def
set
(
o
,
v
):
cdef
int
int3
,
int4
,
int5
cdef
int
int3
,
int4
,
int5
obj1
=
obj2
[...]
int3
,
int4
,
int5
=
1
,
2
,
3
obj1
=
obj2
[::]
o
[
int3
:
int4
:
int5
]
=
v
def
select
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
cdef
int
int3
,
int4
,
int5
int3
,
int4
,
int5
=
1
,
2
,
3
obj1
=
obj2
[
obj3
::]
obj1
=
obj2
[
obj3
::]
obj1
=
obj2
[:
obj4
:]
obj1
=
obj2
[:
obj4
:]
obj1
=
obj2
[::
obj5
]
obj1
=
obj2
[::
obj5
]
...
@@ -10,5 +49,4 @@ def f(obj1, obj2, obj3, obj4, obj5):
...
@@ -10,5 +49,4 @@ def f(obj1, obj2, obj3, obj4, obj5):
obj1
=
obj2
[:
obj4
:
obj5
]
obj1
=
obj2
[:
obj4
:
obj5
]
obj1
=
obj2
[
obj3
:
obj4
:
obj5
]
obj1
=
obj2
[
obj3
:
obj4
:
obj5
]
obj1
=
obj2
[
int3
:
int4
:
int5
]
obj1
=
obj2
[
int3
:
int4
:
int5
]
obj1
[
int3
:
int4
:
int5
]
=
obj2
\ No newline at end of file
tests/run/starargs.pyx
View file @
9a8c817d
__doc__
=
"""
>>> spam(1,2,3)
>>> spam(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> spam(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (4 given)
>>> spam(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> grail(1,2,3)
>>> grail(1,2,3,4)
>>> grail(1,2,3,4,5,6,7,8,9)
>>> grail(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> grail(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> swallow(1,2,3)
>>> swallow(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> swallow(1,2,3, a=1, b=2)
>>> swallow(1,2,3, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> creosote(1,2,3)
>>> creosote(1,2,3,4)
>>> creosote(1,2,3, a=1)
>>> creosote(1,2,3,4, a=1, b=2)
>>> creosote(1,2,3,4, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
"""
def
spam
(
x
,
y
,
z
):
def
spam
(
x
,
y
,
z
):
pass
pass
...
@@ -9,4 +49,3 @@ def swallow(x, y, z, **k):
...
@@ -9,4 +49,3 @@ def swallow(x, y, z, **k):
def
creosote
(
x
,
y
,
z
,
*
a
,
**
k
):
def
creosote
(
x
,
y
,
z
,
*
a
,
**
k
):
pass
pass
tests/run/subop.pyx
View file @
9a8c817d
__doc__
=
"""
>>> f()
(-1, -1)
>>> p()
0
"""
def
f
():
def
f
():
cdef
int
int1
,
int2
,
int3
cdef
int
int1
,
int2
,
int3
cdef
char
*
ptr1
,
*
ptr2
,
*
ptr3
obj1
=
1
obj1
=
1
obj2
=
2
obj2
=
2
obj3
=
3
obj3
=
3
int2
=
2
int3
=
3
int1
=
int2
-
int3
int1
=
int2
-
int3
obj1
=
obj2
-
int3
return
int1
,
obj1
def
p
():
cdef
int
int1
,
int2
,
int3
cdef
char
*
ptr1
,
*
ptr2
,
*
ptr3
int2
=
2
int3
=
3
ptr2
=
"test"
ptr3
=
ptr2
ptr1
=
ptr2
-
int3
ptr1
=
ptr2
-
int3
int1
=
ptr2
-
ptr3
int1
=
ptr2
-
ptr3
obj1
=
obj2
-
int3
return
int1
\ No newline at end of file
tests/run/varargcall.pyx
View file @
9a8c817d
__doc__
=
"""
>>> swallow()
"""
cdef
grail
(
char
*
blarg
,
...):
cdef
grail
(
char
*
blarg
,
...):
pass
pass
c
def
swallow
():
def
swallow
():
grail
(
"spam"
)
grail
(
"spam"
)
grail
(
"spam"
,
42
)
grail
(
"spam"
,
42
)
tests/run/wundram1.pyx
View file @
9a8c817d
__doc__
=
"""
>>> x
5L
"""
cdef
unsigned
int
ui
cdef
unsigned
int
ui
ui
=
5
x
=
ui
x
=
ui
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