""" Script to run unit tests from the command line as:
casapy [casa-options] -c runUnitTest.py testname1 testname2 ...
casapy [casa-options] -c runUnitTest.py testname1[test_r,test23] testname2...
casapy [casa-options] -c runUnitTest.py --Help
casapy [casa-options] -c runUnitTest.py --list
casapy [casa-options] -c runUnitTest.py --list
casapy [casa-options] -c runUnitTest.py --file Tests.txt
casapy [casa-options] -c runUnitTest.py --classes test_listobs
or from inside casapy:
runUnitTest.main(['testname'])
runUnitTest.main()
NOTE: It will search for scripts in the casapy installation directory, which usually is in:
<casa_install_dir>/python/2.6/tests"""
import os
import sys
import getopt
import traceback
import unittest
import string
import re
import shutil
import pprint
import nose
from taskinit import casalog
sys.path.insert(0,'')
PYVER = str(sys.version_info[0]) + "." + str(sys.version_info[1])
CASA_DIR = os.environ["CASAPATH"].split()[0]
TESTS_DIR = CASA_DIR + "/" + os.environ["CASAPATH"].split()[1] + '/lib/python' + PYVER + '/tests/'
if not os.access(TESTS_DIR, os.F_OK):
if os.access(CASA_DIR+'/lib64', os.F_OK):
TESTS_DIR = CASA_DIR+'/lib64/python' + PYVER + '/tests/'
elif os.access(CASA_DIR+'/lib', os.F_OK):
TESTS_DIR = CASA_DIR+'/lib/python'+ PYVER +'/tests/'
else:
TESTS_DIR = CASA_DIR+'/Resources/python/tests/'
HAVE_MEMTEST=True
try:
import memTest
except:
HAVE_MEMTEST = False
import testwrapper
from testwrapper import *
LISTofTESTS = TESTS_DIR+'unittests_list.txt'
MEM = 0
def usage():
print '========================================================================='
print '\nRunUnitTest will execute Python unit test(s) of CASA tasks.'
print 'Usage:\n'
print 'casapy [casapy-options] -c runUnitTest.py [options] test_name\n'
print 'Options:'
print ' no option print this message and exit.'
print ' -a or --all run all tests defined in '
print ' trunk/gcwrap/python/scripts/tests/unittests_list.txt.'
print ' <test_name> run only <test_name> (more tests are separated by spaces).'
print ' -f or --file <list> run the tests defined in an ASCII file <list>; one test per line.'
print ' -d or --datadir <dir> set an env. variable to a directory, TEST_DATADIR=<dir> '
print ' that can be used inside the tests.'