Commit baac4846 authored by Stefan Behnel's avatar Stefan Behnel

extend tests to cover some more internal signature cases of CPython builtins...

extend tests to cover some more internal signature cases of CPython builtins (METH_FASTCALL with and without keywords in P3.7)
parent 84d6bd15
......@@ -349,6 +349,7 @@ VER_DEP_MODULES = {
(3,4): (operator.lt, lambda x: x in ['run.py34_signature',
]),
(3,5): (operator.lt, lambda x: x in ['run.py35_pep492_interop',
'run.fastcall', # uses new deque features
]),
}
......
cimport cython
def generator():
yield 2
yield 1
yield 3
def returns_set():
return {"foo", "bar", "baz"}
def returns_tuple():
return (1, 2, 3, 0)
@cython.test_fail_if_path_exists("//SimpleCallNode")
def sorted_arg(x):
"""
......@@ -31,6 +35,26 @@ def sorted_arg(x):
"""
return sorted(x)
@cython.test_assert_path_exists("//GeneralCallNode")
def sorted_arg_with_key(x):
"""
>>> a = [3, 2, 1]
>>> sorted_arg_with_key(a)
[3, 2, 1]
>>> a
[3, 2, 1]
>>> sorted_arg_with_key(generator())
[3, 2, 1]
>>> sorted_arg_with_key(returns_tuple())
[3, 2, 1, 0]
>>> sorted_arg_with_key(object())
Traceback (most recent call last):
TypeError: 'object' object is not iterable
"""
return sorted(x, key=lambda x: -x)
@cython.test_fail_if_path_exists("//YieldExprNode",
"//NoneCheckNode")
@cython.test_assert_path_exists("//InlinedGeneratorExpressionNode")
......@@ -41,6 +65,7 @@ def sorted_genexp():
"""
return sorted(i*i for i in range(10,0,-1))
@cython.test_fail_if_path_exists("//SimpleCallNode//SimpleCallNode")
@cython.test_assert_path_exists("//SimpleCallNode/NameNode[@name = 'range']")
def sorted_list_of_range():
......@@ -50,6 +75,7 @@ def sorted_list_of_range():
"""
return sorted(list(range(10,0,-1)))
@cython.test_fail_if_path_exists("//SimpleCallNode")
def sorted_list_literal():
"""
......@@ -58,6 +84,7 @@ def sorted_list_literal():
"""
return sorted([3, 1, 2] * 2)
@cython.test_fail_if_path_exists("//SimpleCallNode")
def sorted_tuple_literal():
"""
......
# mode: run
# tag: METH_FASTCALL
from collections import deque
def deque_methods(v):
"""
>>> deque_methods(2)
[1, 2, 3, 4]
"""
d = deque([1, 3, 4])
assert list(d) == [1,3,4]
d.insert(1, v)
assert list(d) == [1,2,3,4]
d.rotate(len(d) // 2)
assert list(d) == [3,4,1,2]
d.rotate(len(d) // 2)
assert list(d) == [1,2,3,4]
return list(d)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment