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
84e0507e
Commit
84e0507e
authored
Sep 01, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify cypclass builtin unit tests
parent
fc5bba37
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
103 deletions
+107
-103
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+107
-103
No files found.
tests/run/cypclass_builtin_dict.pyx
View file @
84e0507e
...
...
@@ -14,9 +14,9 @@ cdef cypclass Index:
__init__
(
self
,
int
i
):
self
.
index
=
i
def
test_
comp
_iteration
():
def
test_
setitem_and
_iteration
():
"""
>>> test_
comp
_iteration()
>>> test_
setitem_and
_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
...
...
@@ -25,9 +25,9 @@ def test_comp_iteration():
return
[
key
.
index
for
key
in
d
]
def
test_nogil_iteration
():
def
test_nogil_
setitem_and_
iteration
():
"""
>>> test_nogil_iteration()
>>> test_nogil_
setitem_and_
iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
indices
=
[]
...
...
@@ -43,9 +43,9 @@ def test_nogil_iteration():
return
indices
def
test_
comp
_keys_iteration
():
def
test_
setitem_and
_keys_iteration
():
"""
>>> test_
comp
_keys_iteration()
>>> test_
setitem_and
_keys_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
...
...
@@ -54,9 +54,9 @@ def test_comp_keys_iteration():
return
[
key
.
index
for
key
in
d
.
keys
()]
def
test_nogil_keys_iteration
():
def
test_nogil_
setitem_and_
keys_iteration
():
"""
>>> test_nogil_keys_iteration()
>>> test_nogil_
setitem_and_
keys_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
indices
=
[]
...
...
@@ -72,9 +72,9 @@ def test_nogil_keys_iteration():
return
indices
def
test_
comp
_values_iteration
():
def
test_
setitem_and
_values_iteration
():
"""
>>> test_
comp
_values_iteration()
>>> test_
setitem_and
_values_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
d
=
cypdict
[
Index
,
Value
]()
...
...
@@ -83,9 +83,9 @@ def test_comp_values_iteration():
return
[
value
.
value
for
value
in
d
.
values
()]
def
test_nogil_values_iteration
():
def
test_nogil_
setitem_and_
values_iteration
():
"""
>>> test_nogil_values_iteration()
>>> test_nogil_
setitem_and_
values_iteration()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
values
=
[]
...
...
@@ -101,9 +101,9 @@ def test_nogil_values_iteration():
return
values
def
test_
comp
_items_iteration
():
def
test_
setitem_and
_items_iteration
():
"""
>>> test_
comp
_items_iteration()
>>> test_
setitem_and
_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
]()
...
...
@@ -112,9 +112,9 @@ def test_comp_items_iteration():
return
[(
key
.
index
,
value
.
value
)
for
(
key
,
value
)
in
d
.
items
()]
def
test_nogil_items_iteration
():
def
test_nogil_
setitem_and_
items_iteration
():
"""
>>> test_nogil_items_iteration()
>>> test_nogil_
setitem_and_
items_iteration()
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
"""
items
=
[]
...
...
@@ -130,9 +130,62 @@ def test_nogil_items_iteration():
return
items
def
test_getitem_exception
():
def
test_len
():
"""
>>> test_len()
1
"""
d
=
cypdict
[
Index
,
Value
]()
cdef
long
unsigned
int
nb_elements
=
0
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
k
in
d
:
nb_elements
+=
1
if
d
.
__len__
()
!=
nb_elements
:
return
0
if
nb_elements
!=
10
:
return
0
return
1
def
test_clear
():
"""
>>> test_getitem_exception()
>>> test_clear()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
if
d
.
__len__
()
!=
10
:
return
-
1
d
.
clear
()
if
d
.
__len__
()
!=
0
:
return
0
return
1
def
test_update
():
"""
>>> test_update()
1
"""
d1
=
cypdict
[
Index
,
Value
]()
d2
=
cypdict
[
Index
,
Value
]()
d1
[
Index
(
1
)]
=
Value
(
10
)
d1
[
Index
(
3
)]
=
Value
(
30
)
d2
[
Index
(
4
)]
=
Value
(
40
)
d2
[
Index
(
2
)]
=
Value
(
20
)
d1
.
update
(
d2
)
if
d1
.
__len__
()
!=
4
:
return
0
for
key
in
d2
:
if
not
key
in
d1
:
return
0
if
d2
[
key
]
is
not
d1
[
key
]:
return
0
return
1
def
test_nonexistent_getitem_exception
():
"""
>>> test_nonexistent_getitem_exception()
'Getting nonexistent item'
1
"""
...
...
@@ -146,9 +199,9 @@ def test_getitem_exception():
print
(
e
)
return
1
def
test_delitem_exception
():
def
test_
nonexistent_
delitem_exception
():
"""
>>> test_delitem_exception()
>>> test_
nonexistent_
delitem_exception()
'Deleting nonexistent item'
1
"""
...
...
@@ -162,9 +215,9 @@ def test_delitem_exception():
print
(
e
)
return
1
def
test_setitem_
exception_dict_iterator
():
def
test_setitem_
iterator_invalidation
():
"""
>>> test_setitem_
exception_dict_iterator
()
>>> test_setitem_
iterator_invalidation
()
Modifying a dictionary with active iterators
1
"""
...
...
@@ -179,9 +232,9 @@ def test_setitem_exception_dict_iterator():
print
(
e
)
return
1
def
test_setitem_
exception_dict_keys_iterator
():
def
test_setitem_
keys_iterator_invalidation
():
"""
>>> test_setitem_
exception_dict_keys_iterator
()
>>> test_setitem_
keys_iterator_invalidation
()
Modifying a dictionary with active iterators
1
"""
...
...
@@ -196,9 +249,9 @@ def test_setitem_exception_dict_keys_iterator():
print
(
e
)
return
1
def
test_setitem_
exception_dict_values_iterator
():
def
test_setitem_
values_iterator_invalidation
():
"""
>>> test_setitem_
exception_dict_values_iterator
()
>>> test_setitem_
values_iterator_invalidation
()
Modifying a dictionary with active iterators
1
"""
...
...
@@ -213,9 +266,9 @@ def test_setitem_exception_dict_values_iterator():
print
(
e
)
return
1
def
test_setitem_
exception_dict_items_iterator
():
def
test_setitem_
items_iterator_invalidation
():
"""
>>> test_setitem_
exception_dict_items_iterator
()
>>> test_setitem_
items_iterator_invalidation
()
Modifying a dictionary with active iterators
1
"""
...
...
@@ -230,122 +283,94 @@ def test_setitem_exception_dict_items_iterator():
print
(
e
)
return
1
def
test_
setitem_after_dict_iterator
():
def
test_
clear_iterator_invalidation
():
"""
>>> test_setitem_after_dict_iterator()
>>> test_clear_iterator_invalidation()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
key
in
d
:
pass
iterator
=
d
.
begin
()
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
d
.
clear
()
with
gil
:
return
1
return
0
except
RuntimeError
as
e
:
print
(
e
)
return
0
return
1
def
test_
setitem_after_dict_keys
_iterator
():
def
test_
modification_after_dict
_iterator
():
"""
>>> test_
setitem_after_dict_keys
_iterator()
>>> test_
modification_after_dict
_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
key
in
d
.
keys
()
:
for
key
in
d
:
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
d
.
clear
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_
setitem_after_dict_value
s_iterator
():
def
test_
modification_after_dict_key
s_iterator
():
"""
>>> test_
setitem_after_dict_value
s_iterator()
>>> test_
modification_after_dict_key
s_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
value
in
d
.
value
s
():
for
key
in
d
.
key
s
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
d
.
clear
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_
setitem_after_dict_item
s_iterator
():
def
test_
modification_after_dict_value
s_iterator
():
"""
>>> test_
setitem_after_dict_item
s_iterator()
>>> test_
modification_after_dict_value
s_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
item
in
d
.
item
s
():
for
value
in
d
.
value
s
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
d
.
clear
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_len
():
"""
>>> test_len()
1
"""
d
=
cypdict
[
Index
,
Value
]()
cdef
long
unsigned
int
nb_elements
=
0
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
for
k
in
d
:
nb_elements
+=
1
if
d
.
__len__
()
!=
nb_elements
:
return
0
if
nb_elements
!=
10
:
return
0
return
1
def
test_clear
():
def
test_modification_after_dict_items_iterator
():
"""
>>> test_
clea
r()
>>> test_
modification_after_dict_items_iterato
r()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
i
in
range
(
10
):
d
[
Index
(
i
)]
=
Value
(
i
)
if
d
.
__len__
()
!=
10
:
return
-
1
d
.
clear
()
if
d
.
__len__
()
!=
0
:
return
0
return
1
def
test_clear_exception_dict_iterator
():
"""
>>> test_clear_exception_dict_iterator()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
iterator
=
d
.
begin
()
for
item
in
d
.
items
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
d
.
clear
()
with
gil
:
return
0
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
1
return
0
def
test_scalar_types_dict
():
"""
...
...
@@ -439,27 +464,6 @@ def test_items_refcount():
return
0
return
1
def
test_update
():
"""
>>> test_update()
1
"""
d1
=
cypdict
[
Index
,
Value
]()
d2
=
cypdict
[
Index
,
Value
]()
d1
[
Index
(
1
)]
=
Value
(
10
)
d1
[
Index
(
3
)]
=
Value
(
30
)
d2
[
Index
(
4
)]
=
Value
(
40
)
d2
[
Index
(
2
)]
=
Value
(
20
)
d1
.
update
(
d2
)
if
d1
.
__len__
()
!=
4
:
return
0
for
key
in
d2
:
if
not
key
in
d1
:
return
0
if
d2
[
key
]
is
not
d1
[
key
]:
return
0
return
1
def
test_update_refcount
():
"""
>>> test_update_refcount()
...
...
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