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

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

Changes to allow for python 2.4 and 2.5 testing.

  • Property svn:executable set to *
File size: 2.5 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
20def test(logfile):
21    result = True
22    start_time = time.time()
23
24    (cluster, domain) = util.get_hostname()
25
26    util.header(logfile, 'Test if python packages are importable on %s.' % cluster)
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    util.footer(logfile, start_time)
83    return result
84
85
86if __name__ == '__main__':
87    import os
88
89    logfile = 'test.log'
90    if len(sys.argv) > 1:
91        logfile = sys.argv[1]
92
93    try:
94        os.remove(logfile)
95    except:
96        pass
97
98    if not test(logfile):
99        sys.exit(10)
100
101    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.