Commit da602065 authored by Stefan Behnel's avatar Stefan Behnel

Separate functions in test for readability.

parent d283bd6c
# mode: run
# tag: listcomp, comprehension
cimport cython cimport cython
def smoketest(): def smoketest():
""" """
>>> smoketest() >>> smoketest()
...@@ -10,6 +14,7 @@ def smoketest(): ...@@ -10,6 +14,7 @@ def smoketest():
assert x != 'abc' assert x != 'abc'
return result return result
def list_genexp(): def list_genexp():
""" """
>>> list_genexp() >>> list_genexp()
...@@ -20,6 +25,7 @@ def list_genexp(): ...@@ -20,6 +25,7 @@ def list_genexp():
assert x == 'abc' assert x == 'abc'
return result return result
def int_runvar(): def int_runvar():
""" """
>>> int_runvar() >>> int_runvar()
...@@ -28,6 +34,7 @@ def int_runvar(): ...@@ -28,6 +34,7 @@ def int_runvar():
cdef int x cdef int x
print [x*2 for x in range(5) if x % 2 == 0] print [x*2 for x in range(5) if x % 2 == 0]
cdef class A: cdef class A:
def __repr__(self): return u"A" def __repr__(self): return u"A"
...@@ -39,6 +46,7 @@ def typed(): ...@@ -39,6 +46,7 @@ def typed():
cdef A obj cdef A obj
print [obj for obj in [A(), A(), A()]] print [obj for obj in [A(), A(), A()]]
def inferred_type(): def inferred_type():
""" """
>>> inferred_type() >>> inferred_type()
...@@ -46,6 +54,7 @@ def inferred_type(): ...@@ -46,6 +54,7 @@ def inferred_type():
""" """
print [cython.typeof(obj) for obj in [A(), A(), A()]] print [cython.typeof(obj) for obj in [A(), A(), A()]]
def not_inferred_type(): def not_inferred_type():
""" """
>>> not_inferred_type() >>> not_inferred_type()
...@@ -53,6 +62,7 @@ def not_inferred_type(): ...@@ -53,6 +62,7 @@ def not_inferred_type():
""" """
print [cython.typeof(obj) for obj in [1, A(), 'abc']] print [cython.typeof(obj) for obj in [1, A(), 'abc']]
def iterdict(): def iterdict():
""" """
>>> iterdict() >>> iterdict()
...@@ -63,6 +73,7 @@ def iterdict(): ...@@ -63,6 +73,7 @@ def iterdict():
l.sort() l.sort()
print l print l
listcomp_result = [ i*i for i in range(5) ] listcomp_result = [ i*i for i in range(5) ]
def global_listcomp(): def global_listcomp():
""" """
...@@ -72,6 +83,7 @@ def global_listcomp(): ...@@ -72,6 +83,7 @@ def global_listcomp():
[0, 1, 4, 9, 16] [0, 1, 4, 9, 16]
""" """
def nested_result(): def nested_result():
""" """
>>> nested_result() >>> nested_result()
...@@ -80,6 +92,7 @@ def nested_result(): ...@@ -80,6 +92,7 @@ def nested_result():
result = [[a-1 for a in range(b)] for b in range(4)] result = [[a-1 for a in range(b)] for b in range(4)]
return result return result
def listcomp_as_condition(sequence): def listcomp_as_condition(sequence):
""" """
>>> listcomp_as_condition(['a', 'b', '+']) >>> listcomp_as_condition(['a', 'b', '+'])
...@@ -93,6 +106,7 @@ def listcomp_as_condition(sequence): ...@@ -93,6 +106,7 @@ def listcomp_as_condition(sequence):
return True return True
return False return False
@cython.test_fail_if_path_exists("//SimpleCallNode//ComprehensionNode") @cython.test_fail_if_path_exists("//SimpleCallNode//ComprehensionNode")
@cython.test_assert_path_exists("//ComprehensionNode") @cython.test_assert_path_exists("//ComprehensionNode")
def sorted_listcomp(sequence): def sorted_listcomp(sequence):
...@@ -106,6 +120,7 @@ def sorted_listcomp(sequence): ...@@ -106,6 +120,7 @@ def sorted_listcomp(sequence):
""" """
return sorted([ n+1 for n in sequence ]) return sorted([ n+1 for n in sequence ])
@cython.test_fail_if_path_exists("//IfStatNode", @cython.test_fail_if_path_exists("//IfStatNode",
"//ComprehensionAppendNode") "//ComprehensionAppendNode")
@cython.test_assert_path_exists("//ComprehensionNode") @cython.test_assert_path_exists("//ComprehensionNode")
...@@ -116,6 +131,7 @@ def listcomp_const_condition_false(): ...@@ -116,6 +131,7 @@ def listcomp_const_condition_false():
""" """
return [x*2 for x in range(3) if False] return [x*2 for x in range(3) if False]
@cython.test_fail_if_path_exists("//IfStatNode") @cython.test_fail_if_path_exists("//IfStatNode")
@cython.test_assert_path_exists("//ComprehensionNode", @cython.test_assert_path_exists("//ComprehensionNode",
"//ComprehensionAppendNode") "//ComprehensionAppendNode")
......
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