source: trunk/misc/tools/acceptance_tests/test_python_packages.py @ 8427

Last change on this file since 8427 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

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