Source
xxxxxxxxxx
import os
import sys
import shutil
import unittest
from time import sleep
import datetime as dt
##########################################################################
# These tests were adapted from the ADMIT code tree
# admit/admit/test/unittest_*.py
##########################################################################
print "*** No tests will run if admit module is not installed in casa"
admit_import = True
try:
import admit
from admit.util.AdmitLogging import AdmitLogging as logging
from admit.Admit import Admit as Project
from admit.AT import AT
from admit.bdp.BDP import BDP
from admit.bdp.File_BDP import File_BDP
import admit.util.bdp_types as bt
except ImportError:
admit_import = False
# Paths for data
#datapath = os.environ.get('CASAPATH').split()[0] + "/data/regression/unittest/admit/"
#datapath = ""
#print 'admit tests will use data from '+ datapath
class admit_test_base(unittest.TestCase):
""" For tests which require an admit.Project instance """
# test initialization
def setUp(self):
self.assertTrue(admit_import)
# sometimes CWD is set to self.outputDir that is deleted by
# tearDown() function, then we need to change back to the parent dir
try:
os.getcwd()
except OSError:
os.chdir('..')
self.outputDir = "AdmitCodeTest.admit"
self.project = Project(self.outputDir)
# clean up
def tearDown(self):
if os.path.exists(self.outputDir):
# create blank project then delete it!
# otherwise "Device or resource busy" on files in dir
self.project = Project(self.outputDir)
shutil.rmtree(self.outputDir)
# -----------------------------------------------------------------------
class admit_test_base2(unittest.TestCase):
""" For tests which require admit.Project """
# test initialization
def setUp(self):
self.assertTrue(admit_import)
# sometimes CWD is set to self.outputDir that is deleted by
# tearDown() function, then we need to change back to the parent dir
try:
os.getcwd()
except OSError:
os.chdir('..')
self.outputDir = "/tmp/AdmitCodeTest_%d.admit" % os.getpid()
admit.Project = Project(self.outputDir)
# clean up
def tearDown(self):
basedir = admit.Project.baseDir
del admit.Project
if os.path.exists(basedir):
shutil.rmtree(basedir)
# ===========================================================================
class admit_test_Project(admit_test_base):
""" Test basic Admit Project class functionality """
# admit/admit/test/unittest_Admit.py
def test_Project_strlen(self):
""" test Project.__str__, __len__ """
self.project.__str__()
# to get the number of tasks