Cython has moved to github.

cython-devel

view tests/run/typetest_T417.pyx @ 2571:9f4f888a2b4e

additional test for type casts (ticket #417)
author Lisandro Dalcin <dalcinl@gmail.com>
date Fri Oct 23 16:41:24 2009 -0200 (2 years ago)
parents 294a197230dd
children
line source
1 #cython: autotestdict=True
3 cdef class Foo:
4 pass
6 cdef class SubFoo(Foo):
7 pass
9 cdef class Bar:
10 pass
12 def foo1(arg):
13 """
14 >>> foo1(Foo())
15 >>> foo1(SubFoo())
16 >>> foo1(None)
17 >>> foo1(123)
18 >>> foo1(Bar())
19 """
20 cdef Foo val = <Foo>arg
22 def foo2(arg):
23 """
24 >>> foo2(Foo())
25 >>> foo2(SubFoo())
26 >>> foo2(None)
27 >>> foo2(123)
28 Traceback (most recent call last):
29 ...
30 TypeError: Cannot convert int to typetest_T417.Foo
31 >>> foo2(Bar())
32 Traceback (most recent call last):
33 ...
34 TypeError: Cannot convert typetest_T417.Bar to typetest_T417.Foo
35 """
36 cdef Foo val = arg
38 def foo3(arg):
39 """
40 >>> foo3(Foo())
41 >>> foo3(SubFoo())
42 >>> foo3(None)
43 Traceback (most recent call last):
44 ...
45 TypeError: Cannot convert NoneType to typetest_T417.Foo
46 >>> foo3(123)
47 Traceback (most recent call last):
48 ...
49 TypeError: Cannot convert int to typetest_T417.Foo
50 >>> foo2(Bar())
51 Traceback (most recent call last):
52 ...
53 TypeError: Cannot convert typetest_T417.Bar to typetest_T417.Foo
54 """
55 cdef val = <Foo?>arg
58 cdef int count = 0
60 cdef object getFoo():
61 global count
62 count += 1
63 return Foo()
65 def test_getFoo():
66 """
67 >>> test_getFoo()
68 1
69 """
70 cdef int old_count = count
71 cdef Foo x = getFoo()
72 return count - old_count
74 def test_getFooCast():
75 """
76 >>> test_getFooCast()
77 1
78 """
79 cdef int old_count = count
80 cdef Foo x = <Foo?>getFoo()
81 return count - old_count