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
c17a6cba
Commit
c17a6cba
authored
Aug 27, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for standard cypclass dict library
parent
75e66773
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
164 additions
and
0 deletions
+164
-0
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+164
-0
No files found.
tests/run/cypclass_builtin_dict.pyx
0 → 100644
View file @
c17a6cba
# mode: run
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
from
libcythonplus.dict
cimport
cypdict
cdef
cypclass
Value
:
int
value
__init__
(
self
,
int
i
):
self
.
value
=
i
cdef
cypclass
Index
:
int
index
__init__
(
self
,
int
i
):
self
.
index
=
i
def
test_comp_iteration
():
"""
>>> test_comp_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
return
[
key
.
index
for
key
in
d
]
def
test_nogil_iteration
():
"""
>>> test_nogil_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
indices
=
[]
with
nogil
:
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
key
in
d
:
with
gil
:
indices
.
append
(
key
.
index
)
return
indices
def
test_comp_keys_iteration
():
"""
>>> test_comp_keys_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
return
[
key
.
index
for
key
in
d
.
keys
()]
def
test_nogil_keys_iteration
():
"""
>>> test_nogil_keys_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
indices
=
[]
with
nogil
:
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
key
in
d
.
keys
():
with
gil
:
indices
.
append
(
key
.
index
)
return
indices
def
test_comp_values_iteration
():
"""
>>> test_comp_values_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
return
[
value
.
value
for
value
in
d
.
values
()]
def
test_nogil_values_iteration
():
"""
>>> test_nogil_values_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
values
=
[]
with
nogil
:
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
value
in
d
.
values
():
with
gil
:
values
.
append
(
value
.
value
)
return
values
def
test_comp_items_iteration
():
"""
>>> test_comp_items_iteration()
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
return
[(
key
.
index
,
value
.
value
)
for
(
key
,
value
)
in
d
.
items
()]
def
test_nogil_items_iteration
():
"""
>>> test_nogil_items_iteration()
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
"""
items
=
[]
with
nogil
:
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
item
in
d
.
items
():
with
gil
:
items
.
append
((
item
.
first
.
index
,
item
.
second
.
value
))
return
items
def
test_getitem_exception
():
"""
>>> test_getitem_exception()
'Getting nonexistent item'
1
"""
try
:
d
=
cypdict
[
Index
,
Value
]()
with
nogil
:
v
=
d
[
Index
()]
with
gil
:
return
0
except
KeyError
as
e
:
print
(
e
)
return
1
def
test_delitem_exception
():
"""
>>> test_delitem_exception()
'Deleting nonexistent item'
1
"""
try
:
d
=
cypdict
[
Index
,
Value
]()
with
nogil
:
del
d
[
Index
()]
with
gil
:
return
0
except
KeyError
as
e
:
print
(
e
)
return
1
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