1 | # Copyright David Abrahams 2004. Distributed under the Boost |
---|
2 | # Software License, Version 1.0. (See accompanying |
---|
3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
4 | """ |
---|
5 | >>> from slice_ext import * |
---|
6 | >>> accept_slice(slice(1, None, (1,2))) |
---|
7 | 1 |
---|
8 | >>> try: |
---|
9 | ... accept_slice(list((1,2))) |
---|
10 | ... print "test failed" |
---|
11 | ... except: |
---|
12 | ... print "test passed" |
---|
13 | ... |
---|
14 | test passed |
---|
15 | >>> have_numeric = 0 |
---|
16 | >>> try: |
---|
17 | ... from Numeric import array |
---|
18 | ... have_numeric = 1 |
---|
19 | ... except: |
---|
20 | ... pass |
---|
21 | ... |
---|
22 | >>> try: |
---|
23 | ... from numarray import array |
---|
24 | ... have_numeric = 1 |
---|
25 | ... except: |
---|
26 | ... pass |
---|
27 | ... |
---|
28 | >>> if have_numeric: |
---|
29 | ... check_numeric_array_rich_slice() |
---|
30 | ... else: |
---|
31 | ... print 1 |
---|
32 | ... |
---|
33 | 1 |
---|
34 | >>> import sys |
---|
35 | >>> if sys.version_info[0] == 2 and sys.version_info[1] >= 3: |
---|
36 | ... check_string_rich_slice() |
---|
37 | ... elif sys.version_info[0] > 2: |
---|
38 | ... check_string_rich_slice() |
---|
39 | ... else: |
---|
40 | ... print 1 |
---|
41 | ... |
---|
42 | 1 |
---|
43 | >>> check_slice_get_indicies( slice(None)) |
---|
44 | 0 |
---|
45 | >>> check_slice_get_indicies( slice(2,-2)) |
---|
46 | 0 |
---|
47 | >>> check_slice_get_indicies( slice(2, None, 2)) |
---|
48 | 5 |
---|
49 | >>> check_slice_get_indicies( slice(2, None, -1)) |
---|
50 | -12 |
---|
51 | >>> check_slice_get_indicies( slice( 20, None)) |
---|
52 | 0 |
---|
53 | >>> check_slice_get_indicies( slice( -2, -5, -2)) |
---|
54 | 6 |
---|
55 | """ |
---|
56 | |
---|
57 | # Performs an affirmative and negative argument resolution check, |
---|
58 | # checks the operation of extended slicing in Numeric arrays |
---|
59 | # (only performed if Numeric.array or numarray.array can be found). |
---|
60 | # checks the operation of extended slicing in new strings (Python 2.3 only). |
---|
61 | |
---|
62 | def run(args = None): |
---|
63 | import sys |
---|
64 | import doctest |
---|
65 | |
---|
66 | if args is not None: |
---|
67 | sys.argv = args |
---|
68 | return doctest.testmod(sys.modules.get(__name__)) |
---|
69 | |
---|
70 | if __name__ == '__main__': |
---|
71 | print "running..." |
---|
72 | import sys |
---|
73 | status = run()[0] |
---|
74 | if (status == 0): print "Done." |
---|
75 | sys.exit(status) |
---|