source: branches/numpy_misc/tools/acceptance_tests/test_python_packages.py @ 7018

Last change on this file since 7018 was 7018, checked in by rwilson, 15 years ago

Removed psyco from modules tested.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/env python
2
3'''Testlet to check that packages required are importable'''
4
5import os
6import sys
7import time
8import test_utils as util
9
10
11# packages we are testing
12Package_Imports = ('from Scientific.IO.NetCDF import NetCDFFile',
13                   'import numpy',
14                   'import Numeric',
15                   'import RandomArray',
16                   'import pypar',
17                   'import matplotlib',
18                   'import pylab',
19                  )
20
21name = 'Test if python packages are importable'
22
23def test(logfile):
24    result = True
25
26    (cluster, domain) = util.get_hostname()
27
28    # get python to run
29    python_env_var = os.getenv('PYTHON')
30
31    # get max width of the import tests
32    width = 0
33    for pkg in Package_Imports:
34        width = max(len(pkg), width)
35
36    # create a 'null' stdout object
37    null_stdout = open('/dev/null', 'w')
38
39    # test each import
40    num_errors = 0
41    error_packages = []
42   
43    for pkg in Package_Imports:
44        util.log_print(logfile, "Testing: %s" % pkg.ljust(width+2))
45        try:
46            # turn off stdout while doing this
47            save_stdout = sys.stdout
48            sys.stdout = null_stdout
49
50            exec pkg
51
52            sys.stdout = save_stdout
53            util.log_print_nl(logfile, 'OK')
54        except ImportError, e:
55            sys.stdout = save_stdout
56            util.log_print_nl(logfile, 'ERROR')
57            error_packages.append(pkg)
58            num_errors += 1
59            result = False
60        except:
61            sys.stdout = save_stdout
62            util.log_print_nl(logfile, 'EXCEPTION')
63            error_packages.append(pkg)
64            num_errors += 1
65            result = False
66
67    # close the 'null' stdout
68    null_stdout.close()
69
70    # report errors
71    util.log_print_nl(logfile)
72    if num_errors == 0:
73        util.log_print_nl(logfile, 'All OK.')
74    else:
75        if num_errors == 1:
76            util.log_print_nl(logfile, '\nGot %d error: ' % num_errors)
77        else:
78            util.log_print_nl(logfile, '\nGot %d errors: ' % num_errors)
79        for pkg in error_packages:
80            util.log_print_nl(logfile, '\t%s' % pkg)
81   
82    return result
83
84
85if __name__ == '__main__':
86    import os
87
88    logfile = 'test.log'
89    if len(sys.argv) > 1:
90        logfile = sys.argv[1]
91
92    try:
93        os.remove(logfile)
94    except:
95        pass
96
97    if not test(logfile):
98        sys.exit(10)
99
100    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.