~ubuntu-branches/ubuntu/precise/cython/precise

« back to all changes in this revision

Viewing changes to tests/run/size_t.pyx

  • Committer: Bazaar Package Importer
  • Author(s): Python Applications Packaging Team, Ryan Kavanagh, Jakub Wilk, Piotr Ożarowski
  • Date: 2009-08-10 23:18:51 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810231851-i6f7mr1ij1h2czkp
Tags: 0.11.2-1
[ Ryan Kavanagh ]
* New upstream release (Closes: #525620, #536213)

[ Jakub Wilk ]
* debian/rules: remove generated files.

[ Piotr Ożarowski ]
* Standards-Version bumped to 3.8.2 (no change needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__doc__ = u"""
 
2
>>> test(0)
 
3
0
 
4
>>> test(1)
 
5
1
 
6
>>> test(2)
 
7
2
 
8
>>> str(test((1<<32)-1))
 
9
'4294967295'
 
10
 
 
11
>>> try: test(-1)
 
12
... except (OverflowError, TypeError): print("ERROR")
 
13
ERROR
 
14
 
 
15
>>> test(1<<128) #doctest: +ELLIPSIS
 
16
Traceback (most recent call last):
 
17
    ...
 
18
OverflowError: ...
 
19
 
 
20
>>> a = A(1,2)
 
21
>>> a.a == 1
 
22
True
 
23
>>> a.b == 2
 
24
True
 
25
>>> a.foo(5)
 
26
5
 
27
>>> try: a.foo(-1)
 
28
... except (OverflowError, TypeError): print("ERROR")
 
29
ERROR
 
30
>>> a.foo(1 << 180) #doctest: +ELLIPSIS
 
31
Traceback (most recent call last):
 
32
    ...
 
33
OverflowError: ...
 
34
"""
 
35
 
 
36
# XXX This should generate a warning !!!
 
37
cdef extern from *:
 
38
    ctypedef unsigned long size_t
 
39
 
 
40
def test(size_t i):
 
41
    return i
 
42
 
 
43
cdef class A:
 
44
    cdef public size_t a
 
45
    cdef readonly size_t b
 
46
 
 
47
    def __init__(self, size_t a, object b):
 
48
        self.a = a
 
49
        self.b = b
 
50
 
 
51
    cpdef size_t foo(self, size_t x):
 
52
        cdef object o = x
 
53
        return o