|
7 | 7 |
|
8 | 8 | """ |
9 | 9 | >>> from opaque_ext import * |
10 | | ->>> # |
11 | | ->>> # Check for correct conversion |
| 10 | +
|
| 11 | +
|
| 12 | + Check for correct conversion |
| 13 | + |
12 | 14 | >>> use(get()) |
13 | 15 |
|
14 | | -# Check that None is converted to a NULL opaque pointer |
| 16 | + Check that None is converted to a NULL opaque pointer |
| 17 | + |
15 | 18 | >>> useany(get()) |
16 | 19 | 1 |
17 | 20 | >>> useany(None) |
18 | 21 | 0 |
19 | 22 |
|
20 | | -# check that we don't lose type information by converting NULL opaque |
21 | | -# pointers to None |
| 23 | + Check that we don't lose type information by converting NULL |
| 24 | + opaque pointers to None |
| 25 | + |
22 | 26 | >>> assert getnull() is None |
23 | 27 | >>> useany(getnull()) |
24 | 28 | 0 |
|
27 | 31 | Traceback (most recent call last): |
28 | 32 | ... |
29 | 33 | RuntimeError: success |
30 | | ->>> # |
31 | | ->>> # Check that there is no conversion from integers ... |
32 | | ->>> use(0) |
33 | | -Traceback (most recent call last): |
34 | | - ... |
35 | | -TypeError: bad argument type for built-in operation |
36 | | ->>> # |
37 | | ->>> # ... and from strings to opaque objects |
38 | | ->>> use("") |
39 | | -Traceback (most recent call last): |
40 | | - ... |
41 | | -TypeError: bad argument type for built-in operation |
42 | | ->>> # |
43 | | ->>> # Now check the same for another opaque pointer type |
| 34 | +
|
| 35 | + Check that there is no conversion from integers ... |
| 36 | + |
| 37 | +>>> try: use(0) |
| 38 | +... except TypeError: pass |
| 39 | +... else: print 'expected a TypeError' |
| 40 | +
|
| 41 | + ... and from strings to opaque objects |
| 42 | + |
| 43 | +>>> try: use("") |
| 44 | +... except TypeError: pass |
| 45 | +... else: print 'expected a TypeError' |
| 46 | +
|
| 47 | + Now check the same for another opaque pointer type |
| 48 | + |
44 | 49 | >>> use2(get2()) |
45 | 50 | >>> failuse2(get2()) |
46 | 51 | Traceback (most recent call last): |
47 | 52 | ... |
48 | 53 | RuntimeError: success |
49 | | ->>> use2(0) |
50 | | -Traceback (most recent call last): |
51 | | - ... |
52 | | -TypeError: bad argument type for built-in operation |
53 | | ->>> use2("") |
54 | | -Traceback (most recent call last): |
55 | | - ... |
56 | | -TypeError: bad argument type for built-in operation |
57 | | ->>> # |
58 | | ->>> # Check that opaque types are distinct |
59 | | ->>> use(get2()) |
60 | | -Traceback (most recent call last): |
61 | | - ... |
62 | | -TypeError: bad argument type for built-in operation |
63 | | ->>> use2(get()) |
64 | | -Traceback (most recent call last): |
65 | | - ... |
66 | | -TypeError: bad argument type for built-in operation |
| 54 | +>>> try: use2(0) |
| 55 | +... except TypeError: pass |
| 56 | +... else: print 'expected a TypeError' |
| 57 | +>>> try: use2("") |
| 58 | +... except TypeError: pass |
| 59 | +... else: print 'expected a TypeError' |
| 60 | +
|
| 61 | + Check that opaque types are distinct |
| 62 | +
|
| 63 | +>>> try: use(get2()) |
| 64 | +... except TypeError: pass |
| 65 | +... else: print 'expected a TypeError' |
| 66 | +>>> try: use2(get()) |
| 67 | +... except TypeError: pass |
| 68 | +... else: print 'expected a TypeError' |
67 | 69 | """ |
68 | 70 | def run(args = None): |
69 | 71 | import sys |
|
0 commit comments