Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/numpy.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.4 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
5false = 0;
6true = 1;
7
8import doctest, numeric_tests
9def _count_failures(test_modules = (numeric_tests,)):
10    failures = 0
11    for m in test_modules:
12        failures += doctest.testmod(m)[0]
13    return failures
14
15def _run(args = None):
16    import sys, numarray_tests, numeric_tests
17
18    if args is not None:
19        sys.argv = args
20
21    # See which of the numeric modules are installed
22    has_numeric = 0
23    try: import Numeric
24    except ImportError: pass
25    else:
26        has_numeric = 1
27        m = Numeric
28
29    has_numarray = 0
30    try: import numarray
31    except ImportError: pass
32    else:
33        has_numarray = 1
34        m = numarray
35   
36    # Bail if neither one is installed
37    if not (has_numeric or has_numarray):
38        return 0
39
40    # test the info routine outside the doctest. See numpy.cpp for an
41    # explanation
42    import numpy_ext
43    if (has_numarray):
44        numpy_ext.info(m.array((1,2,3)))
45
46    failures = 0
47
48    #
49    # Run tests 4 different ways if both modules are installed, just
50    # to show that set_module_and_type() is working properly
51    #
52   
53    # run all the tests with default module search
54    print 'testing default extension module:', \
55          numpy_ext.get_module_name() or '[numeric support not installed]'
56
57    failures += _count_failures()
58       
59    # test against Numeric if installed
60    if has_numeric:
61        print 'testing Numeric module explicitly'
62        numpy_ext.set_module_and_type('Numeric', 'ArrayType')
63       
64        failures += _count_failures()
65           
66    if has_numarray:
67        print 'testing numarray module explicitly'
68        numpy_ext.set_module_and_type('numarray', 'NDArray')
69        # Add the _numarray_tests to the list of things to test in
70        # this case.
71        failures += _count_failures((numarray_tests, numeric_tests))
72
73    # see that we can go back to the default
74    numpy_ext.set_module_and_type('', '')
75    print 'testing default module again:', \
76          numpy_ext.get_module_name() or '[numeric support not installed]'
77   
78    failures += _count_failures()
79   
80    return failures
81   
82if __name__ == '__main__':
83    print "running..."
84    import sys
85    status = _run()
86    if (status == 0): print "Done."
87    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.