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
a90dae5c
Commit
a90dae5c
authored
May 16, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy cypclass tests to cython test suite
parent
dbe290c4
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
351 additions
and
0 deletions
+351
-0
tests/run/cypclass_test___new__.pyx
tests/run/cypclass_test___new__.pyx
+83
-0
tests/run/cypclass_test_basic.pyx
tests/run/cypclass_test_basic.pyx
+19
-0
tests/run/cypclass_test_constructor.pyx
tests/run/cypclass_test_constructor.pyx
+26
-0
tests/run/cypclass_test_constructor_optional_arguments.pyx
tests/run/cypclass_test_constructor_optional_arguments.pyx
+24
-0
tests/run/cypclass_test_inheritance.pyx
tests/run/cypclass_test_inheritance.pyx
+38
-0
tests/run/cypclass_test_keywordnew.pyx
tests/run/cypclass_test_keywordnew.pyx
+19
-0
tests/run/cypclass_test_multiple_inheritance.pyx
tests/run/cypclass_test_multiple_inheritance.pyx
+43
-0
tests/run/cypclass_test_templates.pyx
tests/run/cypclass_test_templates.pyx
+27
-0
tests/run/cypclass_test_type_inference.pyx
tests/run/cypclass_test_type_inference.pyx
+35
-0
tests/run/cypclass_test_typecast.pyx
tests/run/cypclass_test_typecast.pyx
+37
-0
No files found.
tests/run/cypclass_test___new__.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
# This is extremely hacky
cdef
extern
from
"Python.h"
:
struct
CyObject
"CyObject"
void
Cy_INCREF
(
CyObject
*
o
)
nogil
cdef
cypclass
SomeMemory
:
int
a
SomeMemory
__new__
(
f
):
o
=
f
()
o
.
a
=
-
2
return
o
void
__init__
(
self
):
this
.
a
+=
1
void
__init__
(
self
,
int
a
):
pass
void
__init__
(
self
,
int
a
,
int
b
,
int
c
,
int
d
=
21
,
int
e
=
31
):
self
.
a
=
e
cdef
cypclass
SomeArgUnpacking
:
int
a
SomeArgUnpacking
__new__
(
f
,
int
a
,
int
b
,
int
c
,
int
d
=
21
,
int
e
=
31
):
o
=
f
()
return
o
void
__init__
(
self
,
int
a
,
int
b
,
int
c
=
2
,
int
d
=
4
,
int
e
=
32
,
int
g
=
65
):
self
.
a
=
e
cdef
cypclass
SomeNewTrick
:
int
a
void
*
__new__
(
f
,
int
a
):
o
=
f
()
o
.
a
=
a
# As we are returning a non-reference counted variable (void*),
# Cython will decref o (as it is reference-counted).
# To avoid premature memory deallocation, we have to keep a reference here
Cy_INCREF
(
<
CyObject
*>
o
)
return
<
void
*>
o
void
__init__
(
self
,
int
a
,
int
b
,
int
c
,
int
d
=
21
,
int
e
=
31
):
self
.
a
=
e
cdef
cypclass
SomeNotInstanciable
:
double
__new__
(
unused
,
int
a
,
double
b
):
return
a
*
b
cdef
int
foo
():
o
=
SomeMemory
()
return
o
.
a
cdef
int
bar
():
o
=
<
SomeNewTrick
>
SomeNewTrick
(
3
)
return
o
.
a
cdef
int
baz
():
o
=
SomeArgUnpacking
(
3
,
2
,
1
,
0
)
return
o
.
a
cdef
double
baa
():
o
=
SomeNotInstanciable
.
__new__
(
SomeNotInstanciable
.
__alloc__
,
2
,
3.4
)
o
=
SomeNotInstanciable
.
__new__
(
NULL
,
2
,
3.4
)
return
o
cpdef
bag
():
"""
>>> bag()
-1
\
n
3
\
n
32
\
n
6.8
"""
return
str
(
foo
())
+
'
\
n
'
+
str
(
bar
())
+
'
\
n
'
+
str
(
baz
())
+
'
\
n
'
+
str
(
baa
())
tests/run/cypclass_test_basic.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
cpdef
foo
():
cdef
SomeMemory
o
=
SomeMemory
()
o
.
a
=
3
return
o
.
a
def
bag
():
"""
>>> bag()
3
"""
return
str
(
foo
())
\ No newline at end of file
tests/run/cypclass_test_constructor.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
void
__init__
(
self
,
int
a
):
this
.
a
=
a
void
__init__
(
self
,
int
a
,
int
b
):
this
.
a
=
a
*
b
cpdef
foo
():
cdef
SomeMemory
o1
=
SomeMemory
(
3
)
return
o1
.
a
cpdef
bar
():
cdef
SomeMemory
o2
=
SomeMemory
(
2
,
7
)
return
o2
.
a
def
bag
():
"""
>>> bag()
3
\
n
14
"""
return
str
(
foo
())
+
'
\
n
'
+
str
(
bar
())
tests/run/cypclass_test_constructor_optional_arguments.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
void
__init__
(
self
,
int
a
,
int
b
=
1
):
this
.
a
=
a
*
b
cpdef
foo
():
cdef
SomeMemory
o1
=
SomeMemory
(
3
)
return
o1
.
a
cpdef
bar
():
cdef
SomeMemory
o2
=
SomeMemory
(
2
,
7
)
return
o2
.
a
def
bag
():
"""
>>> bag()
3
\
n
14
"""
return
str
(
foo
())
+
'
\
n
'
+
str
(
bar
())
tests/run/cypclass_test_inheritance.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
void
__init__
(
self
,
int
a
):
this
.
a
=
a
void
__init__
(
self
,
int
a
,
int
b
):
this
.
a
=
a
*
b
cdef
cypclass
SomeSubMemory
(
SomeMemory
):
void
__init__
(
self
,
int
a
,
int
b
):
this
.
a
=
a
+
b
int
getter
(
self
):
return
this
.
a
cpdef
foo
():
cdef
SomeMemory
o1
=
SomeMemory
(
2
,
7
)
return
o1
.
a
cpdef
bar
():
cdef
SomeSubMemory
o2
=
SomeSubMemory
(
2
,
7
)
return
o2
.
getter
()
cpdef
baz
():
cdef
SomeSubMemory
o3
=
SomeSubMemory
(
2
)
return
o3
.
getter
()
def
bag
():
"""
>>> bag()
14
\
n
9
\
n
2
"""
return
str
(
foo
())
+
'
\
n
'
+
str
(
bar
())
+
'
\
n
'
+
str
(
baz
())
tests/run/cypclass_test_keywordnew.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
cpdef
foo
():
cdef
SomeMemory
o
=
new
SomeMemory
()
o
.
a
=
3
return
o
.
a
def
bag
():
"""
>>> bag()
3
"""
return
str
(
foo
())
\ No newline at end of file
tests/run/cypclass_test_multiple_inheritance.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
A
:
int
a
void
__init__
(
self
,
int
arg
=
0
):
self
.
a
=
arg
A
__iadd__
(
self
,
A
other
):
self
.
a
+=
other
.
a
int
getter
(
self
):
return
self
.
a
cdef
cypclass
B
:
int
b
void
__init__
(
self
,
int
arg
=
0
):
self
.
b
=
arg
B
__isub__
(
self
,
B
other
):
self
.
b
-=
other
.
b
int
getter
(
self
):
return
self
.
b
cdef
cypclass
C
(
A
,
B
):
void
__init__
(
self
,
int
arg
=
0
):
self
.
a
=
self
.
b
=
arg
cpdef
bag
():
"""
>>> bag()
3
\
n
4
\
n
8
\
n
1
\
n
8
\
n
1
"""
a
=
A
(
3
)
b
=
B
(
4
)
c
=
C
(
5
)
c
+=
a
c
-=
b
return
str
(
a
.
a
)
+
'
\
n
'
+
str
(
b
.
b
)
+
'
\
n
'
+
str
(
c
.
a
)
+
'
\
n
'
+
str
(
c
.
b
)
\
+
'
\
n
'
+
str
(
A
.
getter
(
c
))
+
'
\
n
'
+
str
(
B
.
getter
(
c
))
tests/run/cypclass_test_templates.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
[
T
,
U
]:
T
a
U
b
void
__init__
(
self
,
T
a
,
U
b
):
self
.
a
=
a
self
.
b
=
b
T
first
(
self
):
return
self
.
a
U
second
(
self
):
return
self
.
b
cpdef
bag
():
"""
>>> bag()
1
\
n
2.3
\
n
1
\
n
2.3
"""
cdef
SomeMemory
[
int
,
double
]
o
=
SomeMemory
[
int
,
double
](
1
,
2.3
)
cdef
SomeMemory
[
int
,
int
]
b
=
new
SomeMemory
[
int
,
int
]()
del
b
return
str
(
o
.
a
)
+
'
\
n
'
+
str
(
o
.
b
)
+
'
\
n
'
+
str
(
o
.
first
())
+
'
\
n
'
+
str
(
o
.
second
())
tests/run/cypclass_test_type_inference.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
void
__init__
(
self
,
int
a
=
0
):
self
.
a
=
a
SomeMemory
__add__
(
self
,
SomeMemory
other
):
return
SomeMemory
(
self
.
a
+
other
.
a
)
SomeMemory
__iadd__
(
self
,
SomeMemory
other
):
self
.
a
+=
other
.
a
SomeMemory
__mul__
(
self
,
SomeMemory
other
):
return
SomeMemory
(
self
.
a
*
other
.
a
)
cdef
cypclass
SomeSubMemory
(
SomeMemory
):
int
b
cpdef
bag
():
"""
>>> bag()
28
\
n
4
\
n
7
"""
o1
=
SomeMemory
()
o2
=
SomeMemory
(
4
)
o3
=
SomeSubMemory
(
3
)
o3
+=
o2
o1
=
o2
*
o3
return
str
(
o1
.
a
)
+
'
\
n
'
+
str
(
o2
.
a
)
+
'
\
n
'
+
str
(
o3
.
a
)
tests/run/cypclass_test_typecast.pyx
0 → 100644
View file @
a90dae5c
# mode: run
# distutils: language=c++
# distutils: extra_compile_args=-std=c++11
# tag: cpp
cdef
cypclass
SomeMemory
:
int
a
unsigned
int
__unsigned_int__
(
self
):
return
<
unsigned
int
>
self
.
a
int
__int__
(
self
):
return
self
.
a
bint
__bool__
(
self
):
return
self
.
a
<
0
cdef
cypclass
SomeWrapper
:
SomeMemory
m
void
__init__
(
self
,
int
a
=
0
):
self
.
m
=
SomeMemory
()
self
.
m
.
a
=
a
SomeMemory
__SomeMemory__
(
self
):
return
self
.
m
cpdef
bag
():
"""
>>> bag()
-1
\
n
4294967295
\
n
True
\
n
3
\
n
False
"""
cdef
SomeMemory
o
=
SomeMemory
()
o
.
a
=
-
1
cdef
SomeWrapper
w
=
SomeWrapper
(
3
)
return
str
(
<
int
>
o
)
+
'
\
n
'
+
str
(
<
unsigned
int
>
o
)
+
'
\
n
'
+
str
(
<
bint
>
o
)
\
+
'
\
n
'
+
str
(
<
int
>
<
SomeMemory
>
w
)
+
'
\
n
'
+
str
(
<
bint
>
<
SomeMemory
>
w
)
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