Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/slice.py @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.8 KB
Line 
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)))
71
8>>> try:
9...     accept_slice(list((1,2)))
10...     print "test failed"
11... except:
12...     print "test passed"
13...
14test 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...
331
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...
421
43>>> check_slice_get_indicies( slice(None))
440
45>>> check_slice_get_indicies( slice(2,-2))
460
47>>> check_slice_get_indicies( slice(2, None, 2))
485
49>>> check_slice_get_indicies( slice(2, None, -1))
50-12
51>>> check_slice_get_indicies( slice( 20, None))
520
53>>> check_slice_get_indicies( slice( -2, -5, -2))
546
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
62def 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   
70if __name__ == '__main__':
71    print "running..."
72    import sys
73    status = run()[0]
74    if (status == 0): print "Done."
75    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.