diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am
index ef704f1..b623a23 100644
--- a/cscripts/Makefile.am
+++ b/cscripts/Makefile.am
@@ -69,8 +69,8 @@ linkscripts = cscaldb \
# Test scripts to be distributed in $(pyexecdir)/cscripts/tests
testscripts = tests/__init__.py \
+ ../test/testing.py \
../test/test_python_cscripts.py \
- ../test/test_cscripts_class.py \
../test/test_cscaldb.py \
../test/test_csmodelinfo.py \
../test/test_csmodelmerge.py \
diff --git a/pyext/Makefile.am b/pyext/Makefile.am
index 0a4cd9e..050b1f1 100755
--- a/pyext/Makefile.am
+++ b/pyext/Makefile.am
@@ -31,6 +31,7 @@ if WITH_PYTHON
# Test scripts to be distributed in $(pyexecdir)/ctools/tests
testscripts = ctools/tests/__init__.py \
+ ../test/testing.py \
../test/test_python_ctools.py \
../test/test_ctobssim.py \
../test/test_ctselect.py \
diff --git a/test/test_cscaldb.py b/test/test_cscaldb.py
index f9dbed2..7f14a54 100755
--- a/test/test_cscaldb.py
+++ b/test/test_cscaldb.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+import test_cscripts_class
# ============================= #
# Test class for cscaldb script #
# ============================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test_cscripts_class.cscripts_test):
"""
- Test class for cscaldb script.
+ Test class for cscaldb script
This test class makes unit tests for the cslightcrv script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test_cscripts_class.cscripts_test.__init__(self)
# Return
return
@@ -65,24 +65,19 @@ class Test(gammalib.GPythonTestSuite):
"""
Test cscaldb on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cscaldb = '../cscripts/cscaldb.py'
- else:
- cscaldb = 'cscaldb'
+ # Set script name
+ cscaldb = self._script('cscaldb')
# Setup cscaldb command
cmd = cscaldb+' logfile="cscaldb_cmd1.log" chatter=1'
- # Execute cscaldb, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cscaldb execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Return
return
@@ -94,8 +89,8 @@ class Test(gammalib.GPythonTestSuite):
"""
# Set-up cscaldb
caldb = cscripts.cscaldb()
- caldb['logfile'] = 'cscaldb_py1.log'
- caldb['chatter'] = 2
+ caldb['logfile'] = 'cscaldb_py1.log'
+ caldb['chatter'] = 2
# Run script
caldb.logFileOpen() # Make sure we get a log file
diff --git a/test/test_csfindobs.py b/test/test_csfindobs.py
index 775494c..3ffed07 100755
--- a/test/test_csfindobs.py
+++ b/test/test_csfindobs.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
-# ================================ #
+# =============================== #
# Test class for csfindobs script #
-# ================================ #
-class Test(gammalib.GPythonTestSuite):
+# =============================== #
+class Test(test):
"""
- Test class for csfindobs script.
+ Test class for csfindobs script
This test class makes unit tests for the csfindobs script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test csfindobs on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- csfindobs = '../cscripts/csfindobs.py'
- else:
- csfindobs = 'csfindobs'
+ # Set script name
+ csfindobs = self._script('csfindobs')
# Setup csfindobs command
cmd = csfindobs+' datapath="iactdata/"'+ \
@@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite):
' outfile="runlist_cmd1.dat"'+ \
' logfile="csfindobs_cmd1.log" chatter=1'
- # Execute csfindobs, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful csfindobs execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check run list
self._check_runlist('runlist_cmd1.dat')
@@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite):
' outfile="runlist_cmd2.dat"'+ \
' logfile="csfindobs_cmd2.log"'
- # Execute csfindobs, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of csfindobs execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
diff --git a/test/test_csiactcopy.py b/test/test_csiactcopy.py
index c969b84..e4d4377 100755
--- a/test/test_csiactcopy.py
+++ b/test/test_csiactcopy.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================ #
# Test class for csiactcopy script #
# ================================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csiactcopy script.
+ Test class for csiactcopy script
This test class makes unit tests for the csiactcopy script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csiactcopy")
+ self.name('csiactcopy')
# Append tests
- self.append(self._test_cmd, "Test csiactcopy on command line")
- self.append(self._test_python, "Test csiactcopy from Python")
+ self.append(self._test_cmd, 'Test csiactcopy on command line')
+ self.append(self._test_python, 'Test csiactcopy from Python')
# Return
return
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactcopy on command line
def _test_cmd(self):
"""
- Test csiactcopy on the command line.
+ Test csiactcopy on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csiactcopy = "../cscripts/csiactcopy.py"
- else:
- csiactcopy = "csiactcopy"
+ # Set script name
+ csiactcopy = self._script('csiactcopy')
# Setup csiactcopy command
cmd = csiactcopy+' remote_master="iactdata/master.json"'+ \
@@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite):
' outpath="iactdata_cmd1"'+ \
' logfile="csiactcopy_cmd1.log" chatter=1'
- # Execute csiactcopy, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csiactcopy execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check copy
- self._check_copy("iactdata_cmd1")
+ self._check_copy('iactdata_cmd1')
# Setup csiactcopy command
cmd = csiactcopy+' remote_master="master_that_does_not_exist"'+ \
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' outpath="iactdata_test"'+ \
' logfile="csiactcopy_cmd2.log"'
- # Execute csiactcopy, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csiactcopy execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,15 +101,15 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactcopy from Python
def _test_python(self):
"""
- Test csiactcopy from Python.
+ Test csiactcopy from Python
"""
# Set-up csiactcopy
findobs = cscripts.csiactcopy()
- findobs["remote_master"] = "iactdata/master.json"
- findobs["prodname"] = "unit-test"
- findobs["outpath"] = "iactdata_py1"
- findobs["logfile"] = "csiactcopy_py1.log"
- findobs["chatter"] = 2
+ findobs['remote_master'] = 'iactdata/master.json'
+ findobs['prodname'] = 'unit-test'
+ findobs['outpath'] = 'iactdata_py1'
+ findobs['logfile'] = 'csiactcopy_py1.log'
+ findobs['chatter'] = 2
# Run csiactcopy script and save run list
findobs.logFileOpen() # Make sure we get a log file
@@ -128,7 +117,7 @@ class Test(gammalib.GPythonTestSuite):
findobs.save()
# Check copy
- self._check_copy("iactdata_py1")
+ self._check_copy('iactdata_py1')
# Return
return
@@ -139,9 +128,9 @@ class Test(gammalib.GPythonTestSuite):
Check copy.
"""
# Set file names
- hdu_index_name = gammalib.GFilename(pathname+"/hdu-index.fits")
- obs_index_name = gammalib.GFilename(pathname+"/obs-index.fits")
- master_name = gammalib.GFilename(pathname+"/master.json")
+ hdu_index_name = gammalib.GFilename(pathname+'/hdu-index.fits')
+ obs_index_name = gammalib.GFilename(pathname+'/obs-index.fits')
+ master_name = gammalib.GFilename(pathname+'/master.json')
# Check for existence of files
self.test_assert(hdu_index_name.exists(),
diff --git a/test/test_csiactdata.py b/test/test_csiactdata.py
index 14f6d2b..b5f0a4e 100755
--- a/test/test_csiactdata.py
+++ b/test/test_csiactdata.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================ #
# Test class for csiactdata script #
# ================================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csiactdata script.
+ Test class for csiactdata script
This test class makes unit tests for the csiactdata script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csiactdata")
+ self.name('csiactdata')
# Append tests
- self.append(self._test_cmd, "Test csiactdata on command line")
- self.append(self._test_python, "Test csiactdata from Python")
+ self.append(self._test_cmd, 'Test csiactdata on command line')
+ self.append(self._test_python, 'Test csiactdata from Python')
# Return
return
@@ -63,41 +63,30 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactdata on command line
def _test_cmd(self):
"""
- Test csiactdata on the command line.
+ Test csiactdata on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csiactdata = "../cscripts/csiactdata.py"
- else:
- csiactdata = "csiactdata"
+ # Set script name
+ csiactdata = self._script('csiactdata')
# Setup csiactdata command
cmd = csiactdata+' datapath="iactdata"'+ \
' logfile="csiactdata_cmd1.log" chatter=1'
- # Execute csiactdata, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csiactdata execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Setup csiactdata command
cmd = csiactdata+' datapath="data_path_that_does_not_exist"'+ \
' logfile="csiactdata_cmd2.log"'
- # Execute csiactdata, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csiactdata execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -105,13 +94,13 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactdata from Python
def _test_python(self):
"""
- Test csiactdata from Python.
+ Test csiactdata from Python
"""
# Set-up csiactdata
iactdata = cscripts.csiactdata()
- iactdata["datapath"] = "iactdata"
- iactdata["logfile"] = "csiactdata_py1.log"
- iactdata["chatter"] = 2
+ iactdata['datapath'] = 'iactdata'
+ iactdata['logfile'] = 'csiactdata_py1.log'
+ iactdata['chatter'] = 2
# Run csiactdata script and save run list
iactdata.logFileOpen() # Make sure we get a log file
diff --git a/test/test_csiactobs.py b/test/test_csiactobs.py
index 122d659..48306b9 100755
--- a/test/test_csiactobs.py
+++ b/test/test_csiactobs.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# =============================== #
# Test class for csiactobs script #
# =============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csiactobs script.
+ Test class for csiactobs script
This test class makes unit tests for the csiactobs script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csiactobs")
+ self.name('csiactobs')
# Append tests
- self.append(self._test_cmd, "Test csiactobs on command line")
- self.append(self._test_python, "Test csiactobs from Python")
+ self.append(self._test_cmd, 'Test csiactobs on command line')
+ self.append(self._test_python, 'Test csiactobs from Python')
# Return
return
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactobs on command line
def _test_cmd(self):
"""
- Test csiactobs on the command line.
+ Test csiactobs on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csiactobs = "../cscripts/csiactobs.py"
- else:
- csiactobs = "csiactobs"
+ # Set script name
+ csiactobs = self._script('csiactobs')
# Setup csiactobs command
cmd = csiactobs+' datapath="iactdata"'+ \
@@ -80,21 +77,19 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="bgd_iactobs_cmd1.xml"'+ \
' logfile="csiactobs_cmd1.log" chatter=1'
- # Execute csiactobs, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csiactobs execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check observation definition XML file
- self._check_obsdef("obs_iactobs_cmd1.xml")
+ self._check_obsdef('obs_iactobs_cmd1.xml')
# Check model definition XML file
- self._check_moddef("bgd_iactobs_cmd1.xml")
+ self._check_moddef('bgd_iactobs_cmd1.xml')
# Setup csiactobs command
cmd = csiactobs+' datapath="data_path_that_does_not_exist"'+ \
@@ -105,15 +100,9 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="bgd_iactobs_cmd2.xml"'+ \
' logfile="csiactobs_cmd2.log" chatter=1'
- # Execute csiactobs, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csiactobs execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -121,18 +110,18 @@ class Test(gammalib.GPythonTestSuite):
# Test csiactobs from Python
def _test_python(self):
"""
- Test csiactobs from Python.
+ Test csiactobs from Python
"""
# Set-up csiactobs
iactobs = cscripts.csiactobs()
- iactobs["datapath"] = "iactdata"
- iactobs["prodname"] = "unit-test"
- iactobs["infile"] = "runlist_py1.dat"
- iactobs["bkgpars"] = 1
- iactobs["outobs"] = "obs_iactobs_py1.xml"
- iactobs["outmodel"] = "bgd_iactobs_py1.xml"
- iactobs["logfile"] = "csiactobs_py1.log"
- iactobs["chatter"] = 2
+ iactobs['datapath'] = 'iactdata'
+ iactobs['prodname'] = 'unit-test'
+ iactobs['infile'] = 'runlist_py1.dat'
+ iactobs['bkgpars'] = 1
+ iactobs['outobs'] = 'obs_iactobs_py1.xml'
+ iactobs['outmodel'] = 'bgd_iactobs_py1.xml'
+ iactobs['logfile'] = 'csiactobs_py1.log'
+ iactobs['chatter'] = 2
# Run csiactobs script and save run list
iactobs.logFileOpen() # Make sure we get a log file
@@ -140,10 +129,10 @@ class Test(gammalib.GPythonTestSuite):
iactobs.save()
# Check observation definition XML file
- self._check_obsdef("obs_iactobs_py1.xml")
+ self._check_obsdef('obs_iactobs_py1.xml')
# Check model definition XML file
- self._check_moddef("bgd_iactobs_py1.xml")
+ self._check_moddef('bgd_iactobs_py1.xml')
# Return
return
@@ -151,7 +140,7 @@ class Test(gammalib.GPythonTestSuite):
# Check observation definition XML file
def _check_obsdef(self, filename):
"""
- Check observation definition XML file.
+ Check observation definition XML file
"""
# Load observation definition XML file
obs = gammalib.GObservations(filename)
@@ -197,7 +186,7 @@ class Test(gammalib.GPythonTestSuite):
# Check model XML file
def _check_moddef(self, filename):
"""
- Check model definition XML file.
+ Check model definition XML file
"""
# Load model definition XML file
models = gammalib.GModels(filename)
diff --git a/test/test_cslightcrv.py b/test/test_cslightcrv.py
index 6f64efe..bb1ecd5 100755
--- a/test/test_cslightcrv.py
+++ b/test/test_cslightcrv.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================ #
# Test class for cslightcrv script #
# ================================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for cslightcrv script.
+ Test class for cslightcrv script
This test class makes unit tests for the cslightcrv script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
self._events_name = 'data/crab_events.fits'
@@ -69,11 +69,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test cslightcrv on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cslightcrv = '../cscripts/cslightcrv.py'
- else:
- cslightcrv = 'cslightcrv'
+ # Set script name
+ cslightcrv = self._script('cslightcrv')
# Setup cslightcrv command
cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \
@@ -84,15 +81,13 @@ class Test(gammalib.GPythonTestSuite):
' outfile="lightcurve_cmd1.fits"'+ \
' logfile="cslightcrv_cmd1.log" chatter=1'
- # Execute cslightcrv, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cslightcrv execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check light curve
self._check_light_curve('lightcurve_cmd1.fits', 3)
@@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite):
' outfile="lightcurve_cmd1.fits"'+ \
' logfile="cslightcrv_cmd2.log"'
- # Execute cslightcrv, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of cslightcrv execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite):
# Test cslightcrv from Python
def _test_python(self):
"""
- Test cslightcrv from Python.
+ Test cslightcrv from Python
"""
# Set-up unbinned cslightcrv
lcrv = cscripts.cslightcrv()
@@ -249,7 +238,7 @@ class Test(gammalib.GPythonTestSuite):
# Check light curve result file
def _check_light_curve(self, filename, bins):
"""
- Check light curve file.
+ Check light curve file
"""
# Expected column names
cols = ['MJD', 'e_MJD', 'Prefactor', 'e_Prefactor',
diff --git a/test/test_csmodelinfo.py b/test/test_csmodelinfo.py
index 79818a6..cc555ac 100755
--- a/test/test_csmodelinfo.py
+++ b/test/test_csmodelinfo.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================= #
# Test class for csmodelinfo script #
# ================================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csmodelinfo script.
+ Test class for csmodelinfo script
This test class makes unit tests for the csmodelinfo script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
self._model_name = "data/crab.xml"
@@ -54,11 +54,11 @@ class Test(gammalib.GPythonTestSuite):
Set all test functions.
"""
# Set test name
- self.name("csmodelinfo")
+ self.name('csmodelinfo')
# Append tests
- self.append(self._test_cmd, "Test csmodelinfo on command line")
- self.append(self._test_python, "Test csmodelinfo from Python")
+ self.append(self._test_cmd, 'Test csmodelinfo on command line')
+ self.append(self._test_python, 'Test csmodelinfo from Python')
# Return
return
@@ -66,46 +66,35 @@ class Test(gammalib.GPythonTestSuite):
# Test csmodelinfo on command line
def _test_cmd(self):
"""
- Test csmodelinfo on the command line.
+ Test csmodelinfo on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csmodelinfo = "../cscripts/csmodelinfo.py"
- else:
- csmodelinfo = "csmodelinfo"
+ # Set script name
+ csmodelinfo = self._script('csmodelinfo')
# Setup csmodelinfo command
cmd = csmodelinfo+' inmodel="'+self._model_name+'"'+ \
' ds9file="model_cmd1.reg"'+ \
' logfile="csmodelinfo_cmd1.log" chatter=1'
- # Execute csmodelinfo, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csmodelinfo execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check region file
- self._check_ds9_file("model_cmd1.reg")
+ self._check_ds9_file('model_cmd1.reg')
# Setup csmodelinfo command
cmd = csmodelinfo+' inmodel="model_that_does_not_exist.xml"'+ \
' ds9file="model_cmd2.reg"'+ \
' logfile="csmodelinfo_cmd2.log"'
- # Execute csmodelinfo, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csmodelinfo execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -113,14 +102,14 @@ class Test(gammalib.GPythonTestSuite):
# Test csmodelinfo from Python
def _test_python(self):
"""
- Test csmodelinfo from Python.
+ Test csmodelinfo from Python
"""
# Set-up csmodelinfo
modelinfo = cscripts.csmodelinfo()
- modelinfo["inmodel"] = self._model_name
- modelinfo["ds9file"] = "csmodelinfo_py1.reg"
- modelinfo["logfile"] = "csmodelinfo_py1.log"
- modelinfo["chatter"] = 2
+ modelinfo['inmodel'] = self._model_name
+ modelinfo['ds9file'] = 'csmodelinfo_py1.reg'
+ modelinfo['logfile'] = 'csmodelinfo_py1.log'
+ modelinfo['chatter'] = 2
# Run csmodelinfo script and save DS9 file
modelinfo.logFileOpen() # Make sure we get a log file
@@ -128,20 +117,20 @@ class Test(gammalib.GPythonTestSuite):
modelinfo.save()
# Check region file
- self._check_ds9_file("csmodelinfo_py1.reg")
+ self._check_ds9_file('csmodelinfo_py1.reg')
# Set-up csmodelinfo
modelinfo = cscripts.csmodelinfo()
- modelinfo["inmodel"] = self._model_name
- modelinfo["ds9file"] = "csmodelinfo_py2.reg"
- modelinfo["logfile"] = "csmodelinfo_py2.log"
- modelinfo["chatter"] = 3
+ modelinfo['inmodel'] = self._model_name
+ modelinfo['ds9file'] = 'csmodelinfo_py2.reg'
+ modelinfo['logfile'] = 'csmodelinfo_py2.log'
+ modelinfo['chatter'] = 3
# Execute csmodelinfo script
modelinfo.execute()
# Check region file
- self._check_ds9_file("csmodelinfo_py2.reg")
+ self._check_ds9_file('csmodelinfo_py2.reg')
# Return
return
@@ -149,10 +138,10 @@ class Test(gammalib.GPythonTestSuite):
# Check region file
def _check_ds9_file(self, filename):
"""
- Check region file.
+ Check region file
"""
# Open file
- f = open(filename,"r")
+ f = open(filename,'r')
# Expect "fk5" in first line
line = f.readline().strip('\n')
diff --git a/test/test_csmodelmerge.py b/test/test_csmodelmerge.py
index 9d505f5..81276d4 100755
--- a/test/test_csmodelmerge.py
+++ b/test/test_csmodelmerge.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================== #
# Test class for csmodelmerge script #
# ================================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csmodelmerge script.
+ Test class for csmodelmerge script
This test class makes unit tests for the csmodelmerge script by using it
from the command line and from Python.
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -51,11 +51,11 @@ class Test(gammalib.GPythonTestSuite):
Set all test functions.
"""
# Set test name
- self.name("csmodelmerge")
+ self.name('csmodelmerge')
# Append tests
- self.append(self._test_cmd, "Test csmodelmerge on command line")
- self.append(self._test_python, "Test csmodelmerge from Python")
+ self.append(self._test_cmd, 'Test csmodelmerge on command line')
+ self.append(self._test_python, 'Test csmodelmerge from Python')
# Return
return
@@ -63,46 +63,35 @@ class Test(gammalib.GPythonTestSuite):
# Test csmodelmerge on command line
def _test_cmd(self):
"""
- Test csmodelmerge on the command line.
+ Test csmodelmerge on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csmodelmerge = "../cscripts/csmodelmerge.py"
- else:
- csmodelmerge = "csmodelmerge"
+ # Set script name
+ csmodelmerge = self._script('csmodelmerge')
# Setup csmodelmerge command
cmd = csmodelmerge+' inmodels="data/crab.xml data/model_cube_background.xml"'+ \
' outmodel="mergedmodel_cmd1.xml"'+ \
' logfile="csmodelmerge_cmd1.log" chatter=1'
- # Execute csmodelmerge, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csmodelmerge execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check model file
- self._check_model_file("mergedmodel_cmd1.xml", 3)
+ self._check_model_file('mergedmodel_cmd1.xml', 3)
# Setup csmodelmerge command
cmd = csmodelmerge+' inmodels="model_that_does_not_exist.xml"'+ \
' outmodel="mergedmodel_cmd2.xml"'+ \
' logfile="csmodelmerge_cmd2.log"'
- # Execute csmodelmerge, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csmodelmerge execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -110,14 +99,14 @@ class Test(gammalib.GPythonTestSuite):
# Test csmodelmerge from Python
def _test_python(self):
"""
- Test csmodelmerge from Python.
+ Test csmodelmerge from Python
"""
# Set-up csmodelmerge for space-separated input
modelmerge = cscripts.csmodelmerge()
- modelmerge["inmodels"] = "data/crab.xml data/model_cube_background.xml"
- modelmerge["outmodel"] = "mergedmodel_py1.xml"
- modelmerge["logfile"] = "csmodelmerge_py1.log"
- modelmerge["chatter"] = 2
+ modelmerge['inmodels'] = 'data/crab.xml data/model_cube_background.xml'
+ modelmerge['outmodel'] = 'mergedmodel_py1.xml'
+ modelmerge['logfile'] = 'csmodelmerge_py1.log'
+ modelmerge['chatter'] = 2
# Run csmodelmerge script and save models
modelmerge.logFileOpen() # Make sure we get a log file
@@ -125,46 +114,46 @@ class Test(gammalib.GPythonTestSuite):
modelmerge.save()
# Check model file
- self._check_model_file("mergedmodel_py1.xml", 3)
+ self._check_model_file('mergedmodel_py1.xml', 3)
# Set-up csmodelmerge for semi-colon separated input
modelmerge = cscripts.csmodelmerge()
- modelmerge["inmodels"] = "data/crab.xml;data/model_cube_background.xml"
- modelmerge["outmodel"] = "mergedmodel_py2.xml"
- modelmerge["logfile"] = "csmodelmerge_py2.log"
- modelmerge["chatter"] = 3
+ modelmerge['inmodels'] = 'data/crab.xml;data/model_cube_background.xml'
+ modelmerge['outmodel'] = 'mergedmodel_py2.xml'
+ modelmerge['logfile'] = 'csmodelmerge_py2.log'
+ modelmerge['chatter'] = 3
# Execute csmodelmerge script
modelmerge.execute()
# Check model file
- self._check_model_file("mergedmodel_py2.xml", 3)
+ self._check_model_file('mergedmodel_py2.xml', 3)
# Set-up csmodelmerge for wildcard input
modelmerge = cscripts.csmodelmerge()
- modelmerge["inmodels"] = "data/model_cube_background*.xml"
- modelmerge["outmodel"] = "mergedmodel_py3.xml"
- modelmerge["logfile"] = "csmodelmerge_py3.log"
- modelmerge["chatter"] = 4
+ modelmerge['inmodels'] = 'data/model_cube_background*.xml'
+ modelmerge['outmodel'] = 'mergedmodel_py3.xml'
+ modelmerge['logfile'] = 'csmodelmerge_py3.log'
+ modelmerge['chatter'] = 4
# Execute csmodelmerge script
modelmerge.execute()
# Check model file
- self._check_model_file("mergedmodel_py3.xml", 2)
+ self._check_model_file('mergedmodel_py3.xml', 2)
# Set-up csmodelmerge for ASCII file
modelmerge = cscripts.csmodelmerge()
- modelmerge["inmodels"] = "@data/models.txt"
- modelmerge["outmodel"] = "mergedmodel_py4.xml"
- modelmerge["logfile"] = "csmodelmerge_py4.log"
- modelmerge["chatter"] = 4
+ modelmerge['inmodels'] = '@data/models.txt'
+ modelmerge['outmodel'] = 'mergedmodel_py4.xml'
+ modelmerge['logfile'] = 'csmodelmerge_py4.log'
+ modelmerge['chatter'] = 4
# Execute csmodelmerge script
modelmerge.execute()
# Check model file
- self._check_model_file("mergedmodel_py4.xml", 2)
+ self._check_model_file('mergedmodel_py4.xml', 2)
# Return
return
@@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite):
# Check model file
def _check_model_file(self, filename, number):
"""
- Check model file.
+ Check model file
"""
# Open models
models = gammalib.GModels(filename)
diff --git a/test/test_csobs2caldb.py b/test/test_csobs2caldb.py
index b294c12..b67e8be 100755
--- a/test/test_csobs2caldb.py
+++ b/test/test_csobs2caldb.py
@@ -21,14 +21,15 @@
import os
import gammalib
import cscripts
+from testing import test
# ================================= #
# Test class for csobs2caldb script #
# ================================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csobs2caldb script.
+ Test class for csobs2caldb script
This test class makes unit tests for the csobs2caldb script by using it
from the command line and from Python.
@@ -37,17 +38,17 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
- self._inobs = "data/obs_unbinned.xml"
+ self._inobs = 'data/obs_unbinned.xml'
# Clean calibration database
- os.system("rm -rf caldb >/dev/null 2>&1")
- os.system("mkdir -p caldb >/dev/null 2>&1")
+ os.system('rm -rf caldb >/dev/null 2>&1')
+ os.system('mkdir -p caldb >/dev/null 2>&1')
# Return
return
@@ -55,14 +56,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csobs2caldb")
+ self.name('csobs2caldb')
# Append tests
- self.append(self._test_cmd, "Test csobs2caldb on command line")
- self.append(self._test_python, "Test csobs2caldb from Python")
+ self.append(self._test_cmd, 'Test csobs2caldb on command line')
+ self.append(self._test_python, 'Test csobs2caldb from Python')
# Return
return
@@ -70,46 +71,35 @@ class Test(gammalib.GPythonTestSuite):
# Test csobs2caldb on command line
def _test_cmd(self):
"""
- Test csobs2caldb on the command line.
+ Test csobs2caldb on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csobs2caldb = "../cscripts/csobs2caldb.py"
- else:
- csobs2caldb = "csobs2caldb"
+ # Set script name
+ csobs2caldb = self._script('csobs2caldb')
# Setup csobs2caldb command
cmd = csobs2caldb+' inobs="'+self._inobs+'"'+ \
' caldb="cta" irf="Cmd1" rootdir="caldb"'+ \
' logfile="csobs2caldb_cmd1.log" chatter=1'
- # Execute csobs2caldb, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csobs2caldb execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check response
- self._check_response("cta", "Cmd1")
+ self._check_response('cta', 'Cmd1')
# Setup csobs2caldb command
cmd = csobs2caldb+' inobs="xml_file_that_does_not_exist.xml"'+ \
' caldb="cta" irf="Cmd2" rootdir="caldb"'+ \
' logfile="csobs2caldb_cmd2.log"'
- # Execute csobs2caldb, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csobs2caldb execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -117,16 +107,16 @@ class Test(gammalib.GPythonTestSuite):
# Test csobs2caldb from Python
def _test_python(self):
"""
- Test csobs2caldb from Python.
+ Test csobs2caldb from Python
"""
# Set-up csobs2caldb using "inobs" parameter
irf = cscripts.csobs2caldb()
- irf["inobs"] = self._inobs
- irf["caldb"] = "cta"
- irf["irf"] = "Py1"
- irf["rootdir"] = "caldb"
- irf["logfile"] = "csobs2caldb_py1.log"
- irf["chatter"] = 2
+ irf['inobs'] = self._inobs
+ irf['caldb'] = 'cta'
+ irf['irf'] = 'Py1'
+ irf['rootdir'] = 'caldb'
+ irf['logfile'] = 'csobs2caldb_py1.log'
+ irf['chatter'] = 2
# Run csobs2caldb script and save IRF
irf.logFileOpen() # Make sure we get a log file
@@ -134,24 +124,24 @@ class Test(gammalib.GPythonTestSuite):
irf.save()
# Check response
- self._check_response("cta", "Py1")
+ self._check_response('cta', 'Py1')
# Load observation container
obs = gammalib.GObservations(self._inobs)
# Set-up csobs2caldb using observation container
irf = cscripts.csobs2caldb(obs)
- irf["caldb"] = "cta"
- irf["irf"] = "Py2"
- irf["rootdir"] = "caldb"
- irf["logfile"] = "csobs2caldb_py2.log"
- irf["chatter"] = 3
+ irf['caldb'] = 'cta'
+ irf['irf'] = 'Py2'
+ irf['rootdir'] = 'caldb'
+ irf['logfile'] = 'csobs2caldb_py2.log'
+ irf['chatter'] = 3
# Execute csobs2caldb script
irf.execute()
# Check response
- self._check_response("cta", "Py2")
+ self._check_response('cta', 'Py2')
# Return
return
@@ -159,24 +149,24 @@ class Test(gammalib.GPythonTestSuite):
# Check response
def _check_response(self, caldb, irf):
"""
- Check response.
+ Check response
"""
# Open calibration database
- db = gammalib.GCaldb("caldb")
- db.open("cta", caldb)
+ db = gammalib.GCaldb('caldb')
+ db.open('cta', caldb)
# Get filenames of response components
- expr = "NAME("+irf+")"
- aeff = gammalib.GFilename(db.filename("","","EFF_AREA","","",expr))
- psf = gammalib.GFilename(db.filename("","","RPSF","","",expr))
- edisp = gammalib.GFilename(db.filename("","","EDISP","","",expr))
- bgd = gammalib.GFilename(db.filename("","","BGD","","",expr))
+ expr = 'NAME('+irf+')'
+ aeff = gammalib.GFilename(db.filename('','','EFF_AREA','','',expr))
+ psf = gammalib.GFilename(db.filename('','','RPSF','','',expr))
+ edisp = gammalib.GFilename(db.filename('','','EDISP','','',expr))
+ bgd = gammalib.GFilename(db.filename('','','BGD','','',expr))
# Check whether files exist
- self.test_assert(aeff.exists(), "Effective area file exists")
- self.test_assert(psf.exists(), "Point spread function file exists")
- self.test_assert(edisp.exists(), "Energy dispersion file exists")
- self.test_assert(bgd.exists(), "Background file exists")
+ self.test_assert(aeff.exists(), 'Effective area file exists')
+ self.test_assert(psf.exists(), 'Point spread function file exists')
+ self.test_assert(edisp.exists(), 'Energy dispersion file exists')
+ self.test_assert(bgd.exists(), 'Background file exists')
# Return
return
diff --git a/test/test_csobsdef.py b/test/test_csobsdef.py
index a2250c2..72a3eaa 100755
--- a/test/test_csobsdef.py
+++ b/test/test_csobsdef.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ============================== #
# Test class for csobsdef script #
# ============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csobsdef script.
+ Test class for csobsdef script
This test class makes unit tests for the csobsdef script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('csobsdef')
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csobsdef on command line
def _test_cmd(self):
"""
- Test csobsdef on the command line.
+ Test csobsdef on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- csobsdef = '../cscripts/csobsdef.py'
- else:
- csobsdef = 'csobsdef'
+ # Set script name
+ csobsdef = self._script('csobsdef')
# Setup csobsdef command
cmd = csobsdef+' inpnt="data/pntdef.dat"'+ \
@@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \
' logfile="csobsdef_cmd1.log" chatter=1'
- # Execute csobsdef, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful csobsdef execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check observation definition file
self._check_obsdef_file('csobsdef_cmd1.xml')
@@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \
' logfile="csobsdef_cmd2.log"'
- # Execute csobsdef, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of csobsdef execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite):
# Test csobsdef from Python
def _test_python(self):
"""
- Test csobsdef from Python.
+ Test csobsdef from Python
"""
# Set-up csobsdef
obsdef = cscripts.csobsdef()
@@ -184,7 +173,7 @@ class Test(gammalib.GPythonTestSuite):
# Check observation definition file
def _check_obsdef_file(self, filename):
"""
- Check observation definition file.
+ Check observation definition file
"""
# Load observation definition file
obs = gammalib.GObservations(filename)
diff --git a/test/test_csobsinfo.py b/test/test_csobsinfo.py
index ca3daf7..ce65344 100755
--- a/test/test_csobsinfo.py
+++ b/test/test_csobsinfo.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# =============================== #
# Test class for csobsinfo script #
# =============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csobsinfo script.
+ Test class for csobsinfo script
This test class makes unit tests for the csobsinfo script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csobsinfo")
+ self.name('csobsinfo')
# Append tests
- self.append(self._test_cmd, "Test csobsinfo on command line")
- self.append(self._test_python, "Test csobsinfo from Python")
+ self.append(self._test_cmd, 'Test csobsinfo on command line')
+ self.append(self._test_python, 'Test csobsinfo from Python')
# Return
return
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csobsinfo on command line
def _test_cmd(self):
"""
- Test csobsinfo on the command line.
+ Test csobsinfo on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csobsinfo = "../cscripts/csobsinfo.py"
- else:
- csobsinfo = "csobsinfo"
+ # Set script name
+ csobsinfo = self._script('csobsinfo')
# Setup csobsinfo command
cmd = csobsinfo+' inobs="data/obs_unbinned.xml"'+ \
@@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite):
' offset=yes ra=83.63 dec=22.01'+ \
' logfile="csobsinfo_cmd1.log" chatter=1'
- # Execute csobsinfo, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csobsinfo execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check DS9 file
- self._check_ds9_file("csobsinfo_cmd1.reg")
+ self._check_ds9_file('csobsinfo_cmd1.reg')
# Setup csobsinfo command
cmd = csobsinfo+' inobs="obs_definition_that_does_not_exist.xml"'+ \
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' offset=yes ra=83.63 dec=22.01'+ \
' logfile="csobsinfo_cmd2.log"'
- # Execute csobsinfo, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of csobsinfo execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,17 +101,17 @@ class Test(gammalib.GPythonTestSuite):
# Test csobsinfo from Python
def _test_python(self):
"""
- Test csobsinfo from Python.
+ Test csobsinfo from Python
"""
# Set-up csobsinfo
obsinfo = cscripts.csobsinfo()
- obsinfo["inobs"] = "data/obs_unbinned.xml"
- obsinfo["ds9file"] = "csobsinfo_py1.reg"
- obsinfo["offset"] = True
- obsinfo["ra"] = 83.63
- obsinfo["dec"] = 22.01
- obsinfo["logfile"] = "csobsinfo_py1.log"
- obsinfo["chatter"] = 2
+ obsinfo['inobs'] = 'data/obs_unbinned.xml'
+ obsinfo['ds9file'] = 'csobsinfo_py1.reg'
+ obsinfo['offset'] = True
+ obsinfo['ra'] = 83.63
+ obsinfo['dec'] = 22.01
+ obsinfo['logfile'] = 'csobsinfo_py1.log'
+ obsinfo['chatter'] = 2
# Run csobsinfo script and save XML file
obsinfo.logFileOpen() # Make sure we get a log file
@@ -130,23 +119,23 @@ class Test(gammalib.GPythonTestSuite):
obsinfo.save()
# Check DS9 file
- self._check_ds9_file("csobsinfo_py1.reg")
+ self._check_ds9_file('csobsinfo_py1.reg')
# Set-up csobsinfo
obsinfo = cscripts.csobsinfo()
- obsinfo["inobs"] = "data/obs_unbinned.xml"
- obsinfo["ds9file"] = "csobsinfo_py2.reg"
- obsinfo["offset"] = True
- obsinfo["ra"] = 83.63
- obsinfo["dec"] = 22.01
- obsinfo["logfile"] = "csobsinfo_py2.log"
- obsinfo["chatter"] = 3
+ obsinfo['inobs'] = 'data/obs_unbinned.xml'
+ obsinfo['ds9file'] = 'csobsinfo_py2.reg'
+ obsinfo['offset'] = True
+ obsinfo['ra'] = 83.63
+ obsinfo['dec'] = 22.01
+ obsinfo['logfile'] = 'csobsinfo_py2.log'
+ obsinfo['chatter'] = 3
# Execute csobsinfo script
obsinfo.execute()
# Check DS9 file
- self._check_ds9_file("csobsinfo_py2.reg")
+ self._check_ds9_file('csobsinfo_py2.reg')
# Return
return
@@ -154,10 +143,10 @@ class Test(gammalib.GPythonTestSuite):
# Check DS9 file
def _check_ds9_file(self, filename):
"""
- Check DS9 file.
+ Check DS9 file
"""
# Open file
- f = open(filename,"r")
+ f = open(filename,'r')
# Expect "fk5" in first line
line = f.readline().strip('\n')
diff --git a/test/test_cspull.py b/test/test_cspull.py
index 8cca24a..e65d90d 100755
--- a/test/test_cspull.py
+++ b/test/test_cspull.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ============================ #
# Test class for cspull script #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for cspull script.
+ Test class for cspull script
This test class makes unit tests for the cspull script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("cspull")
+ self.name('cspull')
# Append tests
- self.append(self._test_cmd, "Test cspull on command line")
- self.append(self._test_python, "Test cspull from Python")
+ self.append(self._test_cmd, 'Test cspull on command line')
+ self.append(self._test_python, 'Test cspull from Python')
# Return
return
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test cspull on command line
def _test_cmd(self):
"""
- Test cspull on the command line.
+ Test cspull on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- cspull = "../cscripts/cspull.py"
- else:
- cspull = "cspull"
+ # Set script name
+ cspull = self._script('cspull')
# Setup cspull command
cmd = cspull+' inmodel="data/crab.xml"'+ \
@@ -80,18 +77,16 @@ class Test(gammalib.GPythonTestSuite):
' npix=200 binsz=0.05'+ \
' logfile="cspull_cmd1.log" chatter=1'
- # Execute cspull, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful cspull execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check pull distribution file
- self._check_pull_file("cspull_cmd1.dat")
+ self._check_pull_file('cspull_cmd1.dat')
# Setup cspull command
cmd = cspull+' inmodel="model_that_does_not_exist.xml"'+ \
@@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite):
' npix=200 binsz=0.05'+ \
' logfile="cspull_cmd2.log"'
- # Execute cspull, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of cspull execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -118,25 +107,25 @@ class Test(gammalib.GPythonTestSuite):
# Test cspull from Python
def _test_python(self):
"""
- Test cspull from Python.
+ Test cspull from Python
"""
# Set-up unbinned cspull
pull = cscripts.cspull()
- pull["inmodel"] = "data/crab.xml"
- pull["outfile"] = "cspull_py1.dat"
- pull["ntrials"] = 3
- pull["caldb"] = "prod2"
- pull["irf"] = "South_0.5h"
- pull["ra"] = 83.6331
- pull["dec"] = 22.0145
- pull["emin"] = 0.1
- pull["emax"] = 100.0
- pull["enumbins"] = 0
- pull["tmax"] = 1800.0
- pull["deadc"] = 0.95
- pull["rad"] = 5.0
- pull["logfile"] = "cspull_py1.log"
- pull["chatter"] = 2
+ pull['inmodel'] = 'data/crab.xml'
+ pull['outfile'] = 'cspull_py1.dat'
+ pull['ntrials'] = 3
+ pull['caldb'] = 'prod2'
+ pull['irf'] = 'South_0.5h'
+ pull['ra'] = 83.6331
+ pull['dec'] = 22.0145
+ pull['emin'] = 0.1
+ pull['emax'] = 100.0
+ pull['enumbins'] = 0
+ pull['tmax'] = 1800.0
+ pull['deadc'] = 0.95
+ pull['rad'] = 5.0
+ pull['logfile'] = 'cspull_py1.log'
+ pull['chatter'] = 2
# Run cspull script
pull.logFileOpen() # Make sure we get a log file
@@ -144,93 +133,93 @@ class Test(gammalib.GPythonTestSuite):
#pull.save()
# Check pull distribution file
- self._check_pull_file("cspull_py1.dat")
+ self._check_pull_file('cspull_py1.dat')
# Set-up binned cspull
pull = cscripts.cspull()
- pull["inmodel"] = "data/crab.xml"
- pull["outfile"] = "cspull_py2.dat"
- pull["ntrials"] = 3
- pull["caldb"] = "prod2"
- pull["irf"] = "South_0.5h"
- pull["ra"] = 83.6331
- pull["dec"] = 22.0145
- pull["emin"] = 0.1
- pull["emax"] = 100.0
- pull["enumbins"] = 10
- pull["tmax"] = 1800.0
- pull["deadc"] = 0.95
- pull["rad"] = 5.0
- pull["npix"] = 100
- pull["binsz"] = 0.02
- pull["coordsys"] = "CEL"
- pull["proj"] = "TAN"
- pull["logfile"] = "cspull_py2.log"
- pull["chatter"] = 3
+ pull['inmodel'] = 'data/crab.xml'
+ pull['outfile'] = 'cspull_py2.dat'
+ pull['ntrials'] = 3
+ pull['caldb'] = 'prod2'
+ pull['irf'] = 'South_0.5h'
+ pull['ra'] = 83.6331
+ pull['dec'] = 22.0145
+ pull['emin'] = 0.1
+ pull['emax'] = 100.0
+ pull['enumbins'] = 10
+ pull['tmax'] = 1800.0
+ pull['deadc'] = 0.95
+ pull['rad'] = 5.0
+ pull['npix'] = 100
+ pull['binsz'] = 0.02
+ pull['coordsys'] = 'CEL'
+ pull['proj'] = 'TAN'
+ pull['logfile'] = 'cspull_py2.log'
+ pull['chatter'] = 3
# Execute cspull script
pull.execute()
# Check pull distribution file
- self._check_pull_file("cspull_py2.dat")
+ self._check_pull_file('cspull_py2.dat')
# Set-up cspull from event list
pull = cscripts.cspull()
- pull["inobs"] = "data/crab_events.fits"
- pull["inmodel"] = "data/crab.xml"
- pull["outfile"] = "cspull_py3.dat"
- pull["ntrials"] = 3
- pull["caldb"] = "prod2"
- pull["irf"] = "South_0.5h"
- pull["enumbins"] = 0
- pull["logfile"] = "cspull_py3.log"
- pull["chatter"] = 4
+ pull['inobs'] = 'data/crab_events.fits'
+ pull['inmodel'] = 'data/crab.xml'
+ pull['outfile'] = 'cspull_py3.dat'
+ pull['ntrials'] = 3
+ pull['caldb'] = 'prod2'
+ pull['irf'] = 'South_0.5h'
+ pull['enumbins'] = 0
+ pull['logfile'] = 'cspull_py3.log'
+ pull['chatter'] = 4
# Execute cspull script
pull.execute()
# Check pull distribution file
- self._check_pull_file("cspull_py3.dat")
+ self._check_pull_file('cspull_py3.dat')
# Build observation container with unbinned observation
- cta = gammalib.GCTAObservation("data/crab_events.fits")
+ cta = gammalib.GCTAObservation('data/crab_events.fits')
obs = gammalib.GObservations()
obs.append(cta)
# Set-up cspull from observation container with unbinned observation
pull = cscripts.cspull(obs)
- pull["inmodel"] = "data/crab.xml"
- pull["outfile"] = "cspull_py4.dat"
- pull["ntrials"] = 3
- pull["caldb"] = "prod2"
- pull["irf"] = "South_0.5h"
- pull["enumbins"] = 0
- pull["logfile"] = "cspull_py4.log"
- pull["chatter"] = 4
+ pull['inmodel'] = 'data/crab.xml'
+ pull['outfile'] = 'cspull_py4.dat'
+ pull['ntrials'] = 3
+ pull['caldb'] = 'prod2'
+ pull['irf'] = 'South_0.5h'
+ pull['enumbins'] = 0
+ pull['logfile'] = 'cspull_py4.log'
+ pull['chatter'] = 4
# Execute cspull script
pull.execute()
# Check pull distribution file
- self._check_pull_file("cspull_py4.dat")
+ self._check_pull_file('cspull_py4.dat')
# Set-up stacked cspull
pull = cscripts.cspull()
- pull["inobs"] = "data/obs_stacked.xml"
- pull["inmodel"] = "data/crab_bkgcube.xml"
- pull["outfile"] = "cspull_py5.dat"
- pull["ntrials"] = 3
- pull["caldb"] = "prod2"
- pull["irf"] = "South_0.5h"
- pull["enumbins"] = 0
- pull["logfile"] = "cspull_py5.log"
- pull["chatter"] = 4
+ pull['inobs'] = 'data/obs_stacked.xml'
+ pull['inmodel'] = 'data/crab_bkgcube.xml'
+ pull['outfile'] = 'cspull_py5.dat'
+ pull['ntrials'] = 3
+ pull['caldb'] = 'prod2'
+ pull['irf'] = 'South_0.5h'
+ pull['enumbins'] = 0
+ pull['logfile'] = 'cspull_py5.log'
+ pull['chatter'] = 4
# Execute cspull script
pull.execute()
# Check pull distribution file
- self._check_pull_file("cspull_py5.dat")
+ self._check_pull_file('cspull_py5.dat')
# Return
return
@@ -238,7 +227,7 @@ class Test(gammalib.GPythonTestSuite):
# Check pull file
def _check_pull_file(self, filename):
"""
- Check pull file.
+ Check pull file
"""
# Open pull file as CSV file
pulls = gammalib.GCsv(filename)
diff --git a/test/test_csresmap.py b/test/test_csresmap.py
index 5cec03f..07e1718 100755
--- a/test/test_csresmap.py
+++ b/test/test_csresmap.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ============================== #
# Test class for csresmap script #
# ============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csresmap script.
+ Test class for csresmap script
This test class makes unit tests for the csresmap script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('csresmap')
@@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test csresmap on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- csresmap = '../cscripts/csresmap.py'
- else:
- csresmap = 'csresmap'
+ # Set script name
+ csresmap = self._script('csresmap')
# Setup csresmap command
cmd = csresmap+' inobs="data/crab_events.fits"'+ \
@@ -82,15 +79,13 @@ class Test(gammalib.GPythonTestSuite):
' algorithm="SUBDIV"'+ \
' logfile="csresmap_cmd1.log" chatter=1'
- # Execute csresmap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful csresmap execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('csresmap_cmd1.fits')
@@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite):
' algorithm="SUBDIV"'+ \
' logfile="csresmap_cmd2.log" chatter=2'
- # Execute csresmap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of csresmap execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite):
# Test csresmap from Python
def _test_python(self):
"""
- Test csresmap from Python.
+ Test csresmap from Python
"""
# Set-up csresmap for event list
resmap = cscripts.csresmap()
@@ -181,7 +170,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename, nx=50, ny=50):
"""
- Check result file.
+ Check result file
"""
# Load residual map
residual = gammalib.GSkyMap(filename)
diff --git a/test/test_csroot2caldb.py b/test/test_csroot2caldb.py
index b0d4289..3a11a29 100644
--- a/test/test_csroot2caldb.py
+++ b/test/test_csroot2caldb.py
@@ -21,14 +21,15 @@
import os
import gammalib
import cscripts
+from testing import test
# ================================== #
# Test class for csroot2caldb script #
# ================================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csroot2caldb script.
+ Test class for csroot2caldb script
This test class makes unit tests for the cslightcrv script by using it
from the command line and from Python.
@@ -40,10 +41,10 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Clean calibration database
- os.system("rm -rf csroot2caldb_* >/dev/null 2>&1")
+ os.system('rm -rf csroot2caldb_* >/dev/null 2>&1')
# Return
return
@@ -51,14 +52,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("csroot2caldb")
+ self.name('csroot2caldb')
# Append tests
- self.append(self._test_cmd, "Test csroot2caldb on command line")
- self.append(self._test_python, "Test csroot2caldb from Python")
+ self.append(self._test_cmd, 'Test csroot2caldb on command line')
+ self.append(self._test_python, 'Test csroot2caldb from Python')
# Return
return
@@ -66,13 +67,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csroot2caldb on command line
def _test_cmd(self):
"""
- Test csroot2caldb on the command line.
+ Test csroot2caldb on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- csroot2caldb = "../cscripts/csroot2caldb.py"
- else:
- csroot2caldb = "csroot2caldb"
+ # Set script name
+ csroot2caldb = self._script('csroot2caldb')
# Setup csroot2caldb command
cmd = csroot2caldb+' infile="data/irf.root"'+ \
@@ -81,15 +79,13 @@ class Test(gammalib.GPythonTestSuite):
' analysis=DESY'+ \
' logfile="csroot2caldb_cmd1.log" chatter=1'
- # Execute csroot2caldb, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful csroot2caldb execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Return
return
@@ -97,18 +93,18 @@ class Test(gammalib.GPythonTestSuite):
# Test csroot2caldb from Python
def _test_python(self):
"""
- Test csroot2caldb from Python.
+ Test csroot2caldb from Python
"""
# Set-up csroot2caldb
caldb = cscripts.csroot2caldb()
- caldb["infile"] = "data/irf.root"
- caldb["outdir"] = "csroot2caldb_py1"
- caldb["inst"] = "prod3"
- caldb["id"] = "South_50h"
- caldb["version"] = "prod3"
- caldb["analysis"] = "DESY"
- caldb["logfile"] = "csroot2caldb_py1.log"
- caldb["chatter"] = 2
+ caldb['infile'] = 'data/irf.root'
+ caldb['outdir'] = 'csroot2caldb_py1'
+ caldb['inst'] = 'prod3'
+ caldb['id'] = 'South_50h'
+ caldb['version'] = 'prod3'
+ caldb['analysis'] = 'DESY'
+ caldb['logfile'] = 'csroot2caldb_py1.log'
+ caldb['chatter'] = 2
# Run script
caldb.logFileOpen() # Make sure we get a log file
diff --git a/test/test_cssens.py b/test/test_cssens.py
index b489190..44b91a2 100755
--- a/test/test_cssens.py
+++ b/test/test_cssens.py
@@ -20,13 +20,13 @@
# ==========================================================================
import gammalib
import cscripts
-import test_cscripts_class
+from testing import test
# ============================ #
# Test class for cssens script #
# ============================ #
-class Test(test_cscripts_class.cscripts_test):
+class Test(test):
"""
Test class for cssens script
@@ -40,7 +40,7 @@ class Test(test_cscripts_class.cscripts_test):
Constructor
"""
# Call base class constructor
- test_cscripts_class.cscripts_test.__init__(self)
+ test.__init__(self)
# Return
return
@@ -103,7 +103,7 @@ class Test(test_cscripts_class.cscripts_test):
# Test cssens from Python
def _test_python(self):
"""
- Test cssens from Python.
+ Test cssens from Python
"""
# Set-up cssens
sens = cscripts.cssens()
@@ -135,7 +135,7 @@ class Test(test_cscripts_class.cscripts_test):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file as CSV file
results = gammalib.GCsv(filename, ',')
diff --git a/test/test_csspec.py b/test/test_csspec.py
index 83a78fd..664c3e6 100755
--- a/test/test_csspec.py
+++ b/test/test_csspec.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ============================ #
# Test class for csspec script #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csspec script.
+ Test class for csspec script
This test class makes unit tests for the csspec script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('csspec')
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test csspec on command line
def _test_cmd(self):
"""
- Test csspec on the command line.
+ Test csspec on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- csspec = '../cscripts/csspec.py'
- else:
- csspec = 'csspec'
+ # Set script name
+ csspec = self._script('csspec')
# Setup csspec command
cmd = csspec+' inobs="data/crab_events.fits"'+ \
@@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite):
' outfile="csspec_cmd1.fits"'+ \
' logfile="csspec_cmd1.log" chatter=1'
- # Execute csspec, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful csspec execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('csspec_cmd1.fits', 5)
@@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite):
' outfile="csspec_cmd2.fits"'+ \
' logfile="csspec_cmd2.log" chatter=1'
- # Execute csspec, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of csspec execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite):
# Test csspec from Python
def _test_python(self):
"""
- Test csspec from Python.
+ Test csspec from Python
"""
# Set-up unbinned csspec
spec = cscripts.csspec()
@@ -170,7 +159,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename, bins):
"""
- Check result file.
+ Check result file
"""
# Open result file
fits = gammalib.GFits(filename)
diff --git a/test/test_cstsdist.py b/test/test_cstsdist.py
index 10ff345..88f0491 100755
--- a/test/test_cstsdist.py
+++ b/test/test_cstsdist.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ============================== #
# Test class for cstsdist script #
# ============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for cstsdist script.
+ Test class for cstsdist script
This test class makes unit tests for the cstsdist script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('cstsdist')
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
# Test cstsdist on command line
def _test_cmd(self):
"""
- Test cstsdist on the command line.
+ Test cstsdist on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cstsdist = '../cscripts/cstsdist.py'
- else:
- cstsdist = 'cstsdist'
+ # Set script name
+ cstsdist = self._script('cstsdist')
# Setup cstsdist command
cmd = cstsdist+' inmodel="data/crab.xml"'+ \
@@ -80,15 +77,13 @@ class Test(gammalib.GPythonTestSuite):
' outfile="cstsdist_cmd1.dat"'+ \
' logfile="cstsdist_cmd1.log" chatter=1'
- # Execute cstsdist, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cstsdist execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('cstsdist_cmd1.dat')
@@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite):
' outfile="cstsdist_cmd2.dat"'+ \
' logfile="cstsdist_cmd2.log" chatter=2'
- # Execute cstsdist, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of cstsdist execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite):
# Test cstsdist from Python
def _test_python(self):
"""
- Test cstsdist from Python.
+ Test cstsdist from Python
"""
# Set-up cstsdist
tsdist = cscripts.cstsdist()
@@ -154,7 +143,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file as CSV file
results = gammalib.GCsv(filename, ',')
diff --git a/test/test_cstsmapmerge.py b/test/test_cstsmapmerge.py
index 8be2a0c..95177e2 100755
--- a/test/test_cstsmapmerge.py
+++ b/test/test_cstsmapmerge.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================== #
# Test class for cstsmapmerge script #
# ================================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for cstsmapmerge script.
+ Test class for cstsmapmerge script
This test class makes unit tests for the cstsmapmerge script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('cstsmapmerge')
@@ -63,28 +63,23 @@ class Test(gammalib.GPythonTestSuite):
# Test cstsmapmerge on command line
def _test_cmd(self):
"""
- Test cstsmapmerge on the command line.
+ Test cstsmapmerge on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cstsmapmerge = '../cscripts/cstsmapmerge.py'
- else:
- cstsmapmerge = 'cstsmapmerge'
+ # Set script name
+ cstsmapmerge = self._script('cstsmapmerge')
# Setup cstsmapmerge command
cmd = cstsmapmerge+' inmaps="data/tsmap_0.fits;data/tsmap_1.fits"'+ \
' outmap="cstsmapmerge_cmd1.fits"'+ \
' logfile="cstsmapmerge_cmd1.log" chatter=1'
- # Execute cstsmapmerge, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cstsmapmerge execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('cstsmapmerge_cmd1.fits')
@@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite):
' outmap="cstsmapmerge_cmd2.fits"'+ \
' logfile="cstsmapmerge_cmd2.log" chatter=2'
- # Execute cstsmapmerge, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of cstsmapmerge execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite):
# Test cstsmapmerge from Python
def _test_python(self):
"""
- Test cstsmapmerge from Python.
+ Test cstsmapmerge from Python
"""
# Set-up semi-colon separated cstsmapmerge
merge = cscripts.cstsmapmerge()
@@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
fits = gammalib.GFits(filename)
diff --git a/test/test_csworkflow.py b/test/test_csworkflow.py
index fda26ab..bb0b9d4 100755
--- a/test/test_csworkflow.py
+++ b/test/test_csworkflow.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import cscripts
+from testing import test
# ================================ #
# Test class for csworkflow script #
# ================================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for csworkflow script.
+ Test class for csworkflow script
This test class makes unit tests for the cslightcrv script by using it
from the command line and from Python.
@@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('csworkflow')
@@ -62,12 +62,11 @@ class Test(gammalib.GPythonTestSuite):
# Test csworkflow on command line
def _test_cmd(self):
-
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- csworkflow = '../cscripts/csworkflow.py'
- else:
- csworkflow = 'csworkflow'
+ """
+ Test csworkflow on the command line
+ """
+ # Set script name
+ csworkflow = self._script('csworkflow')
# Remove result file
gammalib.GFilename('wf_crab_results.xml').remove()
@@ -76,16 +75,13 @@ class Test(gammalib.GPythonTestSuite):
cmd = csworkflow+' inflow="data/workflow.xml"'+ \
' logfile="csworkflow_cmd1.log" chatter=1'
- # Execute csworkflow, make sure we catch any exception
- try:
- rc = os.system(cmd)
- #rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful csworkflow execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check fit result
self._check_fit_result('wf_crab_results.xml')
@@ -95,7 +91,9 @@ class Test(gammalib.GPythonTestSuite):
# Test csworkflow from Python
def _test_python(self):
-
+ """
+ Test csworkflow from Python
+ """
# Remove result file
gammalib.GFilename('wf_crab_results.xml').remove()
@@ -132,7 +130,9 @@ class Test(gammalib.GPythonTestSuite):
# Check fit result XML values
def _check_fit_result(self, filename):
-
+ """
+ Check result file
+ """
# Load fit results
models = gammalib.GModels(filename)
diff --git a/test/test_ctbin.py b/test/test_ctbin.py
index 22bd625..ff582dc 100755
--- a/test/test_ctbin.py
+++ b/test/test_ctbin.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ========================= #
# Test class for ctbin tool #
# ========================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctbin tool.
+ Test class for ctbin tool
This test class makes unit tests for the ctbin tool by using it from
the command line and from Python.
@@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
- self._events_name = "data/crab_events.fits"
+ self._events_name = 'data/crab_events.fits'
# Return
return
@@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("ctbin")
+ self.name('ctbin')
# Append tests
- self.append(self._test_cmd, "Test ctbin on command line")
- self.append(self._test_python, "Test ctbin from Python")
+ self.append(self._test_cmd, 'Test ctbin on command line')
+ self.append(self._test_python, 'Test ctbin from Python')
# Return
return
@@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctbin on command line
def _test_cmd(self):
"""
- Test ctbin on the command line.
+ Test ctbin on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- ctbin = "../src/ctbin/ctbin"
- else:
- ctbin = "ctbin"
+ # Set tool name
+ ctbin = self._tool('ctbin')
# Setup ctbin command
cmd = ctbin+' inobs="'+self._events_name+'"'+ \
@@ -81,18 +78,16 @@ class Test(gammalib.GPythonTestSuite):
' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \
' xref=83.63 yref=22.01 proj="CAR"'
- # Execute ctbin, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful ctbin execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Load counts cube and check content.
- evt = gammalib.GCTAEventCube("cntmap_cmd1.fits")
+ evt = gammalib.GCTAEventCube('cntmap_cmd1.fits')
self._check_cube(evt, 5542)
# Setup ctbin command
@@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite):
' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \
' xref=83.63 yref=22.01 proj="CAR"'
- # Execute ctbin, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of ctbin execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -118,23 +107,23 @@ class Test(gammalib.GPythonTestSuite):
# Test ctbin from Python
def _test_python(self):
"""
- Test ctbin from Python.
+ Test ctbin from Python
"""
# Set-up ctbin
bin = ctools.ctbin()
- bin["inobs"] = self._events_name
- bin["outcube"] = "cntmap.fits"
- bin["ebinalg"] = "LOG"
- bin["emin"] = 0.1
- bin["emax"] = 100.0
- bin["enumbins"] = 20
- bin["nxpix"] = 200
- bin["nypix"] = 200
- bin["binsz"] = 0.02
- bin["coordsys"] = "CEL"
- bin["proj"] = "CAR"
- bin["xref"] = 83.63
- bin["yref"] = 22.01
+ bin['inobs'] = self._events_name
+ bin['outcube'] = 'cntmap.fits'
+ bin['ebinalg'] = 'LOG'
+ bin['emin'] = 0.1
+ bin['emax'] = 100.0
+ bin['enumbins'] = 20
+ bin['nxpix'] = 200
+ bin['nypix'] = 200
+ bin['binsz'] = 0.02
+ bin['coordsys'] = 'CEL'
+ bin['proj'] = 'CAR'
+ bin['xref'] = 83.63
+ bin['yref'] = 22.01
# Run ctbin tool
bin.run()
@@ -160,44 +149,37 @@ class Test(gammalib.GPythonTestSuite):
self._check_observation(cpy_bin, 0)
self._check_cube(cpy_bin.cube(), 0)
- # Clear and run copy of ctbin again
- #cpy_bin.clear()
- #cpy_bin.run()
-#RuntimeError: *** ERROR in GXmlAttribute::value(std::string): Invalid XML attribute value: *** ERROR in GPythonTestSuite::test:
-#*** ERROR in GApplicationPars::operator[](std::string&): Invalid argument. Parameter "debug" has not been found in parameter file.
-#Please specify a valid parameter name.
-
# Save counts cube
bin.save()
# Load counts cube and check content.
- evt = gammalib.GCTAEventCube("cntmap.fits")
+ evt = gammalib.GCTAEventCube('cntmap.fits')
self._check_cube(evt, 5542)
# Prepare observation container for stacked analysis
cta = gammalib.GCTAObservation(self._events_name)
obs = gammalib.GObservations()
- cta.id("0001")
+ cta.id('0001')
obs.append(cta)
- cta.id("0002")
+ cta.id('0002')
obs.append(cta)
- cta.id("0003")
+ cta.id('0003')
obs.append(cta)
# Set-up ctbin using an observation container
bin = ctools.ctbin(obs)
- bin["outcube"] = "cntmap.fits"
- bin["ebinalg"] = "LOG"
- bin["emin"] = 0.1
- bin["emax"] = 100.0
- bin["enumbins"] = 20
- bin["nxpix"] = 200
- bin["nypix"] = 200
- bin["binsz"] = 0.02
- bin["coordsys"] = "CEL"
- bin["proj"] = "CAR"
- bin["xref"] = 83.63
- bin["yref"] = 22.01
+ bin['outcube'] = 'cntmap.fits'
+ bin['ebinalg'] = 'LOG'
+ bin['emin'] = 0.1
+ bin['emax'] = 100.0
+ bin['enumbins'] = 20
+ bin['nxpix'] = 200
+ bin['nypix'] = 200
+ bin['binsz'] = 0.02
+ bin['coordsys'] = 'CEL'
+ bin['proj'] = 'CAR'
+ bin['xref'] = 83.63
+ bin['yref'] = 22.01
# Run ctbin tool
bin.run()
@@ -209,65 +191,58 @@ class Test(gammalib.GPythonTestSuite):
# Set-up ctbin using an observation container
bin = ctools.ctbin(obs)
- bin["outcube"] = "cntmap2.fits"
- bin["ebinalg"] = "LOG"
- bin["emin"] = 0.1
- bin["emax"] = 100.0
- bin["enumbins"] = 20
- bin["nxpix"] = 200
- bin["nypix"] = 200
- bin["binsz"] = 0.02
- bin["coordsys"] = "CEL"
- bin["proj"] = "CAR"
- bin["xref"] = 83.63
- bin["yref"] = 22.01
+ bin['outcube'] = 'cntmap2.fits'
+ bin['ebinalg'] = 'LOG'
+ bin['emin'] = 0.1
+ bin['emax'] = 100.0
+ bin['enumbins'] = 20
+ bin['nxpix'] = 200
+ bin['nypix'] = 200
+ bin['binsz'] = 0.02
+ bin['coordsys'] = 'CEL'
+ bin['proj'] = 'CAR'
+ bin['xref'] = 83.63
+ bin['yref'] = 22.01
# Execute ctbin tool
bin.execute()
# Load counts cube and check content.
- evt = gammalib.GCTAEventCube("cntmap2.fits")
+ evt = gammalib.GCTAEventCube('cntmap2.fits')
self._check_cube(evt, 5542, multiplier=3)
- # Clear tool
- #bin.clear()
-#what(): *** ERROR in GApplicationPars::write(std::string&): Unable to open parameter file "pfiles/".
-
- # Check content of observation and cube
- #self.test_value(bin.obs().size(), 0, "There is no observation")
- #self.test_value(bin.cube().size(), 0, "0 event bins")
- #self.test_value(bin.cube().number(), 0, "0 events")
-
# Return
return
# Check observation
def _check_observation(self, ctbin, nevents, multiplier=1):
"""
- Check content of an observation.
+ Check content of an observation
- Args:
- ctbin: ctbin instance
- nevents: Expected number of events
-
- Kwargs:
- multiplier: Observation multiplier
+ Parameters
+ ----------
+ ctbin : `~ctools.ctbin`
+ ctbin instance
+ nevents : int
+ Expected number of events
+ multiplier : float, optional
+ Observation multiplier
"""
# Test observation container
obs = gammalib.GCTAObservation(ctbin.obs()[0])
pnt = obs.pointing()
self.test_value(ctbin.obs().size(), 1,
- "There is one observation")
- self.test_assert(obs.instrument() == "CTA",
- "Observation is CTA observation")
+ 'There is one observation')
+ self.test_assert(obs.instrument() == 'CTA',
+ 'Observation is CTA observation')
self.test_value(obs.ontime(), 1800.0*multiplier, 1.0e-6,
- "Ontime is 1800 sec")
+ 'Ontime is 1800 sec')
self.test_value(obs.livetime(), 1710.0*multiplier, 1.0e-6,
- "Livetime is 1710 sec")
+ 'Livetime is 1710 sec')
self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6,
- "Pointing Right Ascension is 83.63 deg")
+ 'Pointing Right Ascension is 83.63 deg')
self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6,
- "Pointing Declination is 22.01 deg")
+ 'Pointing Declination is 22.01 deg')
# Test event cube
self._check_cube(obs.events(), nevents, multiplier=multiplier)
@@ -278,19 +253,21 @@ class Test(gammalib.GPythonTestSuite):
# Check event cube
def _check_cube(self, cube, nevents, multiplier=1):
"""
- Check content of event cube."
+ Check content of event cube
- Args:
- cube: Event cube
- nevents: Expected number of events.
-
- Kwargs:
- multiplier: Event number multiplier
+ Parameters
+ ----------
+ cube : `~gammalib.GCTAEventCube`
+ Event cube
+ nevents : int
+ Expected number of events
+ multiplier : float
+ Event number multiplier
"""
# Test event cube
- self.test_value(cube.size(), 800000, "800000 event bins")
+ self.test_value(cube.size(), 800000, '800000 event bins')
self.test_value(cube.number(), nevents*multiplier,
- str(nevents*multiplier)+" events")
+ str(nevents*multiplier)+' events')
# Return
return
diff --git a/test/test_ctbkgcube.py b/test/test_ctbkgcube.py
index 5ae5de0..f110983 100755
--- a/test/test_ctbkgcube.py
+++ b/test/test_ctbkgcube.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================= #
# Test class for ctbkgcube tool #
# ============================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
Test class for ctbkgcube tool.
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctbkgcube')
@@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test ctbkgcube on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctbkgcube = '../src/ctbkgcube/ctbkgcube'
- else:
- ctbkgcube = 'ctbkgcube'
+ # Set tool name
+ ctbkgcube = self._tool('ctbkgcube')
# Setup ctbkgcube command
cmd = ctbkgcube+' inobs="data/crab_events.fits"'+ \
@@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="ctbkgcube_cmd1.log" chatter=1'
- # Execute ctbkgcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctbkgcube execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctbkgcube_cmd1.fits')
@@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="ctbkgcube_cmd2.log" chatter=1'
- # Execute ctbkgcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctbkgcube execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctbkgcube from Python
def _test_python(self):
"""
- Test ctbkgcube from Python.
+ Test ctbkgcube from Python
"""
# Set-up ctbkgcube
bkgcube = ctools.ctbkgcube()
@@ -159,7 +148,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GCTACubeBackground(filename)
diff --git a/test/test_ctbutterfly.py b/test/test_ctbutterfly.py
index 6d018c4..131c637 100755
--- a/test/test_ctbutterfly.py
+++ b/test/test_ctbutterfly.py
@@ -18,15 +18,15 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# =============================== #
# Test class for ctbutterfly tool #
# =============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
Test class for ctbutterfly tool.
"""
@@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test ctbutterfly on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctbutterfly = '../src/ctbutterfly/ctbutterfly'
- else:
- ctbutterfly = 'ctbutterfly'
+ # Set tool name
+ ctbutterfly = self._tool('ctbutterfly')
# Setup ctbutterfly command
cmd = ctbutterfly+' inobs="data/crab_events.fits"'+\
@@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctbutterfly_cmd1.log" chatter=1'
- # Execute ctbutterfly, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctbutterfly execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctbutterfly_cmd1.txt')
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctbutterfly_cmd2.log" chatter=1'
- # Execute ctbutterfly, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctbutterfly execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctbutterfly from Python
def _test_python(self):
"""
- Test ctbutterfly from Python.
+ Test ctbutterfly from Python
"""
# Set-up ctbutterfly
butterfly = ctools.ctbutterfly()
@@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file as CSV file
results = gammalib.GCsv(filename)
diff --git a/test/test_ctcubemask.py b/test/test_ctcubemask.py
index 6380f5a..39bbd7e 100755
--- a/test/test_ctcubemask.py
+++ b/test/test_ctcubemask.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================== #
# Test class for ctcubemask tool #
# ============================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctcubemask tool.
+ Test class for ctcubemask tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctcubemask')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctcubemask on command line
def _test_cmd(self):
"""
- Test ctcubemask on the command line.
+ Test ctcubemask on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctcubemask = '../src/ctcubemask/ctcubemask'
- else:
- ctcubemask = 'ctcubemask'
+ # Set tool name
+ ctcubemask = self._tool('ctcubemask')
# Setup ctcubemask command
cmd = ctcubemask+' inobs="data/crab_cntmap.fits"'+ \
@@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctcubemask_cmd1.log" chatter=1'
- # Execute ctcubemask, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctcubemask execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctcubemask_cmd1.fits')
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctcubemask_cmd2.log" chatter=2'
- # Execute ctcubemask, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctcubemask execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctcubemask from Python
def _test_python(self):
"""
- Test ctcubemask from Python.
+ Test ctcubemask from Python
"""
# Set-up ctcubemask
mask = ctools.ctcubemask()
@@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Load counts cube
cube = gammalib.GCTAEventCube(filename)
diff --git a/test/test_ctedispcube.py b/test/test_ctedispcube.py
index 38d8ce5..29ebadf 100755
--- a/test/test_ctedispcube.py
+++ b/test/test_ctedispcube.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
-# ============================= #
+# =============================== #
# Test class for ctedispcube tool #
-# ============================= #
-class Test(gammalib.GPythonTestSuite):
+# =============================== #
+class Test(test):
"""
- Test class for ctedispcube tool.
+ Test class for ctedispcube tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctedispcube')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctedispcube on command line
def _test_cmd(self):
"""
- Test ctedispcube on the command line.
+ Test ctedispcube on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctedispcube = '../src/ctedispcube/ctedispcube'
- else:
- ctedispcube = 'ctedispcube'
+ # Set tool name
+ ctedispcube = self._tool('ctedispcube')
# Setup ctedispcube command
cmd = ctedispcube+' inobs="data/crab_events.fits"'+ \
@@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite):
' migramax=2.0 migrabins=10'+ \
' logfile="ctedispcube_cmd1.log" chatter=1'
- # Execute ctedispcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctedispcube execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctedispcube_cmd1.fits')
@@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite):
' migramax=2.0 migrabins=10'+ \
' logfile="ctedispcube_cmd2.log" chatter=2'
- # Execute ctedispcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctedispcube execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctedispcube from Python
def _test_python(self):
"""
- Test ctedispcube from Python.
+ Test ctedispcube from Python
"""
# Set-up ctedispcube
edispcube = ctools.ctedispcube()
@@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GCTACubeEdisp(filename)
diff --git a/test/test_cterror.py b/test/test_cterror.py
index 173efaa..da15c04 100755
--- a/test/test_cterror.py
+++ b/test/test_cterror.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# =========================== #
# Test class for cterror tool #
# =========================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for cterror tool.
+ Test class for cterror tool
"""
# Constructor
def __init__(self):
@@ -36,14 +36,14 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
- self.events_name = "data/crab_events.fits"
- self.model_name = "data/crab.xml"
- self.result_name = "cterror_result.xml"
- self.caldb = "irf"
- self.irf = "cta_dummy_irf"
+ self.events_name = 'data/crab_events.fits'
+ self.model_name = 'data/crab.xml'
+ self.result_name = 'cterror_result.xml'
+ self.caldb = 'irf'
+ self.irf = 'cta_dummy_irf'
# Return
return
@@ -51,7 +51,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('cterror')
@@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite):
# Test cterror on command line
def _test_cmd(self):
"""
- Test cterror on the command line.
+ Test cterror on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cterror = '../src/cterror/cterror'
- else:
- cterror = 'cterror'
+ # Set tool name
+ cterror = self._tool('cterror')
# Setup cterror command
cmd = cterror+' inobs="data/crab_events.fits"'+ \
@@ -81,15 +78,13 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="cterror_cmd1.xml"'+ \
' logfile="cterror_cmd1.log" chatter=1'
- # Execute cterror, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cterror execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('cterror_cmd1.xml')
@@ -101,15 +96,9 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="cterror_cmd2.xml"'+ \
' logfile="cterror_cmd2.log" chatter=1'
- # Execute cterror, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of cterror execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -117,7 +106,7 @@ class Test(gammalib.GPythonTestSuite):
# Test cterror from Python
def _test_python(self):
"""
- Test cterror from Python.
+ Test cterror from Python
"""
# Set-up cterror
error = ctools.cterror()
@@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GModels(filename)
diff --git a/test/test_ctexpcube.py b/test/test_ctexpcube.py
index 2d8db47..45deb69 100755
--- a/test/test_ctexpcube.py
+++ b/test/test_ctexpcube.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================= #
# Test class for ctexpcube tool #
# ============================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctexpcube tool.
+ Test class for ctexpcube tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctexpcube')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctexpcube on command line
def _test_cmd(self):
"""
- Test ctexpcube on the command line.
+ Test ctexpcube on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctexpcube = '../src/ctexpcube/ctexpcube'
- else:
- ctexpcube = 'ctexpcube'
+ # Set tool name
+ ctexpcube = self._tool('ctexpcube')
# Setup ctexpcube command
cmd = ctexpcube+' inobs="data/crab_events.fits"'+ \
@@ -77,15 +74,13 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="ctexpcube_cmd1.log" chatter=1'
- # Execute ctexpcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctexpcube execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctexpcube_cmd1.fits')
@@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="ctexpcube_cmd2.log" chatter=1'
- # Execute ctexpcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctexpcube execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctexpcube from Python
def _test_python(self):
"""
- Test ctexpcube from Python.
+ Test ctexpcube from Python
"""
# Set-up ctexpcube
expcube = ctools.ctexpcube()
@@ -153,7 +142,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GCTACubeExposure(filename)
diff --git a/test/test_ctlike.py b/test/test_ctlike.py
index dfdff89..a60bf21 100755
--- a/test/test_ctlike.py
+++ b/test/test_ctlike.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ========================== #
# Test class for ctlike tool #
# ========================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctlike tool.
+ Test class for ctlike tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctlike')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctlike on command line
def _test_cmd(self):
"""
- Test ctlike on the command line.
+ Test ctlike on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctlike = '../src/ctlike/ctlike'
- else:
- ctlike = 'ctlike'
+ # Set tool name
+ ctlike = self._tool('ctlike')
# Setup ctlike command
cmd = ctlike+' inobs="data/crab_events.fits"'+ \
@@ -74,15 +71,13 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="ctlike_cmd1.xml"'+ \
' logfile="ctlike_cmd1.log" chatter=1'
- # Execute ctlike, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctlike execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctlike_cmd1.xml')
@@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite):
' outmodel="ctlike_cmd2.xml"'+ \
' logfile="ctlike_cmd2.log" chatter=1'
- # Execute ctlike, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctlike execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctlike from Python
def _test_python(self):
"""
- Test ctlike from Python.
+ Test ctlike from Python
"""
# Set-up ctlike
like = ctools.ctlike()
@@ -136,7 +125,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GModels(filename)
diff --git a/test/test_ctmapcube.py b/test/test_ctmapcube.py
index e83dbe9..4592aeb 100644
--- a/test/test_ctmapcube.py
+++ b/test/test_ctmapcube.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================= #
# Test class for ctmapcube tool #
# ============================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctmapcube tool.
+ Test class for ctmapcube tool
This test class makes unit tests for the ctmapcube tool by using it from
the command line and from Python.
@@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
- self._model_name = "data/crab.xml"
+ self._model_name = 'data/crab.xml'
# Return
return
@@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("ctmapcube")
+ self.name('ctmapcube')
# Append tests
- self.append(self._test_cmd, "Test ctmapcube on command line")
- self.append(self._test_python, "Test ctmapcube from Python")
+ self.append(self._test_cmd, 'Test ctmapcube on command line')
+ self.append(self._test_python, 'Test ctmapcube from Python')
# Return
return
@@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctmapcube on command line
def _test_cmd(self):
"""
- Test ctmapcube on the command line.
+ Test ctmapcube on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- ctmapcube = "../src/ctmapcube/ctmapcube"
- else:
- ctmapcube = "ctmapcube"
+ # Set tool name
+ ctmapcube = self._tool('ctmapcube')
# Setup ctmapcube command
cmd = ctmapcube+' inmodel="'+self._model_name+'"'+ \
@@ -82,19 +79,16 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01 proj=CAR'+ \
' logfile="ctmapcube_cmd1.log" chatter=1'
- # Execute ctmapcube, make sure we catch any exception
- try:
- #rc = os.system(cmd)
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful ctmapcube execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check map cube
- self._check_cube("ctmapcube_cmd1.fits")
+ self._check_cube('ctmapcube_cmd1.fits')
# Setup ctmapcube command
cmd = ctmapcube+' inmodel="events_that_do_not_exist.fits"'+ \
@@ -104,16 +98,9 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01 proj=CAR'+ \
' logfile="ctmapcube_cmd2.log"'
- # Execute ctmapcube, make sure we catch any exception
- try:
- #rc = os.system(cmd)
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of ctmapcube execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -121,25 +108,25 @@ class Test(gammalib.GPythonTestSuite):
# Test ctmapcube from Python
def _test_python(self):
"""
- Test ctmapcube from Python.
+ Test ctmapcube from Python
"""
# Set-up ctmapcube
mapcube = ctools.ctmapcube()
- mapcube["inmodel"] = self._model_name
- mapcube["outcube"] = "ctmapcube_py1.fits"
- mapcube["ebinalg"] = "LOG"
- mapcube["emin"] = 0.1
- mapcube["emax"] = 100.0
- mapcube["enumbins"] = 20
- mapcube["nxpix"] = 200
- mapcube["nypix"] = 200
- mapcube["binsz"] = 0.02
- mapcube["coordsys"] = "CEL"
- mapcube["proj"] = "CAR"
- mapcube["xref"] = 83.63
- mapcube["yref"] = 22.01
- mapcube["logfile"] = "ctmapcube_py1.log"
- mapcube["chatter"] = 2
+ mapcube['inmodel'] = self._model_name
+ mapcube['outcube'] = 'ctmapcube_py1.fits'
+ mapcube['ebinalg'] = 'LOG'
+ mapcube['emin'] = 0.1
+ mapcube['emax'] = 100.0
+ mapcube['enumbins'] = 20
+ mapcube['nxpix'] = 200
+ mapcube['nypix'] = 200
+ mapcube['binsz'] = 0.02
+ mapcube['coordsys'] = 'CEL'
+ mapcube['proj'] = 'CAR'
+ mapcube['xref'] = 83.63
+ mapcube['yref'] = 22.01
+ mapcube['logfile'] = 'ctmapcube_py1.log'
+ mapcube['chatter'] = 2
# Run ctmapcube tool
mapcube.logFileOpen() # Make sure we get a log file
@@ -149,7 +136,7 @@ class Test(gammalib.GPythonTestSuite):
mapcube.save()
# Check map cube
- self._check_cube("ctmapcube_py1.fits")
+ self._check_cube('ctmapcube_py1.fits')
# Return
return
@@ -157,22 +144,23 @@ class Test(gammalib.GPythonTestSuite):
# Check map cube
def _check_cube(self, filename):
"""
- Check content of map cube."
+ Check content of map cube
- Args:
- filename: Map cube file name.
+ Parameters
+ ----------
+ filename : str
+ Map cube file name.
"""
# Load map cube
cube = gammalib.GModelSpatialDiffuseCube(filename)
- #print(cube)
# Test map cube
#self.test_value(cube.maps(), 20, "20 maps")
#self.test_value(cube.pixels(), 40000, "40000 map pixels")
# The map cube is not loaded by default !!!! We should add the method so that
# the attributes are known !!!!
- self.test_value(cube.maps(), 0, "20 maps")
- self.test_value(cube.pixels(), 0, "40000 map pixels")
+ self.test_value(cube.maps(), 0, '20 maps')
+ self.test_value(cube.pixels(), 0, '40000 map pixels')
# Return
return
diff --git a/test/test_ctmodel.py b/test/test_ctmodel.py
index 33c6475..b3c7b39 100755
--- a/test/test_ctmodel.py
+++ b/test/test_ctmodel.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# =========================== #
# Test class for ctmodel tool #
# =========================== #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctmodel tool.
+ Test class for ctmodel tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctmodel')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctmodel on command line
def _test_cmd(self):
"""
- Test ctmodel on the command line.
+ Test ctmodel on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctmodel = '../src/ctmodel/ctmodel'
- else:
- ctmodel = 'ctmodel'
+ # Set tool name
+ ctmodel = self._tool('ctmodel')
# Setup ctmodel command
cmd = ctmodel+' incube="NONE" inobs="NONE" expcube="NONE"'+\
@@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01'+ \
' logfile="ctmodel_cmd1.log" chatter=1'
- # Execute ctmodel, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctmodel execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctmodel_cmd1.fits')
@@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01'+ \
' logfile="ctmodel_cmd2.log" chatter=1'
- # Execute ctmodel, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctmodel execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctmodel from Python
def _test_python(self):
"""
- Test ctmodel from Python.
+ Test ctmodel from Python
"""
# Set-up ctmodel from scratch
model = ctools.ctmodel()
@@ -165,7 +154,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
fits = gammalib.GFits(filename)
diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py
index ec65cf6..288dcfe 100755
--- a/test/test_ctobssim.py
+++ b/test/test_ctobssim.py
@@ -18,18 +18,18 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
from cscripts import obsutils
+from testing import test
# ============================ #
# Test class for ctobssim tool #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctobssim tools.
+ Test class for ctobssim tools
This test class makes unit tests for the ctobssim tool by using it from
the command line and from Python.
@@ -38,15 +38,15 @@ class Test(gammalib.GPythonTestSuite):
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Set members
- self._model_name = "data/crab.xml"
- self._caldb = "irf"
- self._irf = "cta_dummy_irf"
+ self._model_name = 'data/crab.xml'
+ self._caldb = 'irf'
+ self._irf = 'cta_dummy_irf'
# Return
return
@@ -54,14 +54,14 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
- self.name("ctobssim")
+ self.name('ctobssim')
# Append tests
- self.append(self._test_ctobssim_cmd, "Test ctobssim on command line")
- self.append(self._test_ctobssim_python, "Test ctobssim from Python")
+ self.append(self._test_ctobssim_cmd, 'Test ctobssim on command line')
+ self.append(self._test_ctobssim_python, 'Test ctobssim from Python')
# Return
return
@@ -69,13 +69,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctobssim on command line
def _test_ctobssim_cmd(self):
"""
- Test ctobssim on the command line.
+ Test ctobssim on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile("README.md"):
- ctobssim = "../src/ctobssim/ctobssim"
- else:
- ctobssim = "ctobssim"
+ # Set tool name
+ ctobssim = self._tool('ctobssim')
# Setup ctobssim command
cmd = ctobssim+' inmodel="data/crab.xml" outevents="events.fits"'+ \
@@ -83,18 +80,16 @@ class Test(gammalib.GPythonTestSuite):
' ra=83.63 dec=22.01 rad=10.0'+ \
' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0'
- # Execute ctobssim, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- "Successful ctobssim execution on command line")
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Load counts cube and check content.
- evt = gammalib.GCTAEventList("events.fits")
+ evt = gammalib.GCTAEventList('events.fits')
self._test_list(evt, 4119)
# Setup ctobssim command
@@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite):
' ra=83.63 dec=22.01 rad=10.0'+ \
' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0'
- # Execute ctobssim, make sure we catch any exception
- try:
- rc = os.system(cmd+" >/dev/null 2>&1")
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- "Failure of ctobssim execution on command line")
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -120,21 +109,21 @@ class Test(gammalib.GPythonTestSuite):
# Test ctobssim from Python
def _test_ctobssim_python(self):
"""
- Test ctobssim from Python.
+ Test ctobssim from Python
"""
# Set-up ctobssim
sim = ctools.ctobssim()
- sim["inmodel"] = self._model_name
- sim["outevents"] = "events.fits"
- sim["caldb"] = self._caldb
- sim["irf"] = self._irf
- sim["ra"] = 83.63
- sim["dec"] = 22.01
- sim["rad"] = 10.0
- sim["tmin"] = 0.0
- sim["tmax"] = 1800.0
- sim["emin"] = 0.1
- sim["emax"] = 100.0
+ sim['inmodel'] = self._model_name
+ sim['outevents'] = 'events.fits'
+ sim['caldb'] = self._caldb
+ sim['irf'] = self._irf
+ sim['ra'] = 83.63
+ sim['dec'] = 22.01
+ sim['rad'] = 10.0
+ sim['tmin'] = 0.0
+ sim['tmax'] = 1800.0
+ sim['emin'] = 0.1
+ sim['emax'] = 100.0
# Run tool
sim.run()
@@ -147,7 +136,7 @@ class Test(gammalib.GPythonTestSuite):
sim.save()
# Load counts cube and check content.
- evt = gammalib.GCTAEventList("events.fits")
+ evt = gammalib.GCTAEventList('events.fits')
self._test_list(evt, 4119)
# Set-up observation container
@@ -159,8 +148,8 @@ class Test(gammalib.GPythonTestSuite):
# Set-up ctobssim from observation container
sim = ctools.ctobssim(obs)
- sim["outevents"] = "sim_events.xml"
- sim["inmodel"] = self._model_name
+ sim['outevents'] = 'sim_events.xml'
+ sim['inmodel'] = self._model_name
# Run tool
sim.run()
@@ -176,7 +165,7 @@ class Test(gammalib.GPythonTestSuite):
sim.save()
# Load events
- obs = gammalib.GObservations("sim_events.xml")
+ obs = gammalib.GObservations('sim_events.xml')
# Retrieve observation and check content
self._test_list(obs[0].events(), 4063)
@@ -186,20 +175,20 @@ class Test(gammalib.GPythonTestSuite):
# Set-up ctobssim with invalid event file
sim = ctools.ctobssim()
- sim["inmodel"] = "model_file_that_does_not_exist.xml"
- sim["outevents"] = "events.fits"
- sim["caldb"] = self._caldb
- sim["irf"] = self._irf
- sim["ra"] = 83.63
- sim["dec"] = 22.01
- sim["rad"] = 10.0
- sim["tmin"] = 0.0
- sim["tmax"] = 1800.0
- sim["emin"] = 0.1
- sim["emax"] = 100.0
+ sim['inmodel'] = 'model_file_that_does_not_exist.xml'
+ sim['outevents'] = 'events.fits'
+ sim['caldb'] = self._caldb
+ sim['irf'] = self._irf
+ sim['ra'] = 83.63
+ sim['dec'] = 22.01
+ sim['rad'] = 10.0
+ sim['tmin'] = 0.0
+ sim['tmax'] = 1800.0
+ sim['emin'] = 0.1
+ sim['emax'] = 100.0
# Run ctbin tool
- self.test_try("Run ctobssim with invalid model file")
+ self.test_try('Run ctobssim with invalid model file')
try:
sim.run()
self.test_try_failure()
@@ -213,31 +202,33 @@ class Test(gammalib.GPythonTestSuite):
def _test_observation(self, ctobssim, nobs=1,
pnts=[{'ra': 83.63, 'dec': 22.01}]):
"""
- Test content of an observation.
+ Test content of an observation
- Args:
- ctobssim: ctobssim instance
-
- Kwargs:
- nobs: Number of observations
- pnts: List of pointing dictionaries
+ Parameters
+ ----------
+ ctobssim : `~ctools.ctobssim`
+ ctobssim instance
+ nobs : int
+ Number of observations
+ pnts : list of dict
+ List of pointing dictionaries
"""
# Test observation container
self.test_value(ctobssim.obs().size(), nobs,
- "There is one observation")
+ 'There is one observation')
for i in range(ctobssim.obs().size()):
obs = gammalib.GCTAObservation(ctobssim.obs()[i])
pnt = obs.pointing()
- self.test_assert(obs.instrument() == "CTA",
- "Observation is CTA observation")
+ self.test_assert(obs.instrument() == 'CTA',
+ 'Observation is CTA observation')
self.test_value(obs.ontime(), 1800.0, 1.0e-6,
- "Ontime is 1800 sec")
+ 'Ontime is 1800 sec')
self.test_value(obs.livetime(), 1710.0, 1.0e-6,
- "Livetime is 1710 sec")
+ 'Livetime is 1710 sec')
self.test_value(pnt.dir().ra_deg(), pnts[i]['ra'], 1.0e-6,
- "Pointing Right Ascension is "+str(pnts[i]['ra'])+" deg")
+ 'Pointing Right Ascension is '+str(pnts[i]['ra'])+' deg')
self.test_value(pnt.dir().dec_deg(), pnts[i]['dec'], 1.0e-6,
- "Pointing Declination is "+str(pnts[i]['dec'])+" deg")
+ 'Pointing Declination is '+str(pnts[i]['dec'])+' deg')
# Return
return
@@ -245,15 +236,18 @@ class Test(gammalib.GPythonTestSuite):
# Check event list
def _test_list(self, list, nevents):
"""
- Test content of event list."
+ Test content of event list
- Args:
- list: Event list
- nevents: Expected number of events.
+ Parameters
+ ----------
+ list : `~gammalib.GCTAEventList`
+ Event list
+ nevents : int
+ Expected number of events
"""
# Test event list
- self.test_value(list.size(), nevents, str(nevents)+" elements")
- self.test_value(list.number(), nevents, str(nevents)+" events")
+ self.test_value(list.size(), nevents, str(nevents)+' elements')
+ self.test_value(list.number(), nevents, str(nevents)+' events')
# Return
return
diff --git a/test/test_ctpsfcube.py b/test/test_ctpsfcube.py
index 9fb5e79..2572816 100755
--- a/test/test_ctpsfcube.py
+++ b/test/test_ctpsfcube.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================= #
# Test class for ctpsfcube tool #
# ============================= #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctpsfcube tool.
+ Test class for ctpsfcube tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctpsfcube')
@@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite):
"""
Test ctpsfcube on the command line.
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctpsfcube = '../src/ctpsfcube/ctpsfcube'
- else:
- ctpsfcube = 'ctpsfcube'
+ # Set tool name
+ ctpsfcube = self._tool('ctpsfcube')
# Setup ctpsfcube command
cmd = ctpsfcube+' inobs="data/crab_events.fits"'+ \
@@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite):
' amax=0.3 anumbins=10'+ \
' logfile="ctpsfcube_cmd1.log" chatter=1'
- # Execute ctpsfcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctpsfcube execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctpsfcube_cmd1.fits')
@@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite):
' amax=0.3 anumbins=10'+ \
' logfile="ctpsfcube_cmd2.log" chatter=1'
- # Execute ctpsfcube, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctpsfcube execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctpsfcube from Python
def _test_python(self):
"""
- Test ctpsfcube from Python.
+ Test ctpsfcube from Python
"""
# Set-up ctpsfcube
psfcube = ctools.ctpsfcube()
@@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GCTACubePsf(filename)
diff --git a/test/test_ctselect.py b/test/test_ctselect.py
index 1d2c386..ef0290f 100755
--- a/test/test_ctselect.py
+++ b/test/test_ctselect.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================ #
# Test class for ctselect tool #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctselect tool.
+ Test class for ctselect tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctselect')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctselect on command line
def _test_cmd(self):
"""
- Test ctselect on the command line.
+ Test ctselect on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctselect = '../src/ctselect/ctselect'
- else:
- ctselect = 'ctselect'
+ # Set tool name
+ ctselect = self._tool('ctselect')
# Setup ctselect command
cmd = ctselect+' inobs="data/crab_events.fits"'+ \
@@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctselect_cmd1.log" chatter=1'
- # Execute ctselect, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctselect execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctselect_cmd1.fits')
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' emin=0.1 emax=100.0'+ \
' logfile="ctselect_cmd2.log" chatter=1'
- # Execute ctselect, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctselect execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctselect from Python
def _test_python(self):
"""
- Test ctselect from Python.
+ Test ctselect from Python
"""
# Set-up ctselect
select = ctools.ctselect()
@@ -142,7 +131,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GCTAEventList(filename)
diff --git a/test/test_ctskymap.py b/test/test_ctskymap.py
index fe2bc50..a6243b7 100755
--- a/test/test_ctskymap.py
+++ b/test/test_ctskymap.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================ #
# Test class for ctskymap tool #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctskymap tool.
+ Test class for ctskymap tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctskymap')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctskymap on command line
def _test_cmd(self):
"""
- Test ctskymap on the command line.
+ Test ctskymap on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctskymap = '../src/ctskymap/ctskymap'
- else:
- ctskymap = 'ctskymap'
+ # Set tool name
+ ctskymap = self._tool('ctskymap')
# Setup ctskymap command
cmd = ctskymap+' inobs="data/crab_events.fits"'+\
@@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01'+ \
' logfile="ctskymap_cmd1.log" chatter=1'
- # Execute ctskymap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctskymap execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctskymap_cmd1.fits')
@@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite):
' xref=83.63 yref=22.01'+ \
' logfile="ctskymap_cmd2.log" chatter=2'
- # Execute ctskymap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctskymap execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctskymap from Python
def _test_python(self):
"""
- Test ctskymap from Python.
+ Test ctskymap from Python
"""
# Set-up ctskymap
skymap = ctools.ctskymap()
@@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
result = gammalib.GSkyMap(filename)
diff --git a/test/test_cttsmap.py b/test/test_cttsmap.py
index d068da2..f8a99b9 100755
--- a/test/test_cttsmap.py
+++ b/test/test_cttsmap.py
@@ -18,17 +18,17 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
-# ========================== #
+# =========================== #
# Test class for cttsmap tool #
-# ========================== #
-class Test(gammalib.GPythonTestSuite):
+# =========================== #
+class Test(test):
"""
- Test class for cttsmap tool.
+ Test class for cttsmap tool
"""
# Constructor
def __init__(self):
@@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite):
Constructor.
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('cttsmap')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test cttsmap on command line
def _test_cmd(self):
"""
- Test cttsmap on the command line.
+ Test cttsmap on the command line
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- cttsmap = '../src/cttsmap/cttsmap'
- else:
- cttsmap = 'cttsmap'
+ # Set tool name
+ cttsmap = self._tool('cttsmap')
# Setup cttsmap command
cmd = cttsmap+' inobs="data/crab_events.fits"'+ \
@@ -76,15 +73,13 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="cttsmap_cmd1.log" chatter=1'
- # Execute cttsmap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful cttsmap execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('cttsmap_cmd1.fits')
@@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite):
' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \
' logfile="cttsmap_cmd2.log" chatter=2'
- # Execute cttsmap, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of cttsmap execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite):
# Test cttsmap from Python
def _test_python(self):
"""
- Test cttsmap from Python.
+ Test cttsmap from Python
"""
# Set-up cttsmap
tsmap = ctools.cttsmap()
@@ -148,7 +137,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Open result file
fits = gammalib.GFits(filename)
diff --git a/test/test_ctulimit.py b/test/test_ctulimit.py
index 139d75f..112ee1b 100755
--- a/test/test_ctulimit.py
+++ b/test/test_ctulimit.py
@@ -18,25 +18,25 @@
# along with this program. If not, see .
#
# ==========================================================================
-import os
import gammalib
import ctools
+from testing import test
# ============================ #
# Test class for ctulimit tool #
# ============================ #
-class Test(gammalib.GPythonTestSuite):
+class Test(test):
"""
- Test class for ctulimit tool.
+ Test class for ctulimit tool
"""
# Constructor
def __init__(self):
"""
- Constructor.
+ Constructor
"""
# Call base class constructor
- gammalib.GPythonTestSuite.__init__(self)
+ test.__init__(self)
# Return
return
@@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite):
# Set test functions
def set(self):
"""
- Set all test functions.
+ Set all test functions
"""
# Set test name
self.name('ctulimit')
@@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite):
# Test ctulimit on command line
def _test_cmd(self):
"""
- Test ctulimit on the command line.
+ Test ctulimit on the command lines
"""
- # Kluge to set the command (installed version has no README file)
- if os.path.isfile('README.md'):
- ctulimit = '../src/ctulimit/ctulimit'
- else:
- ctulimit = 'ctulimit'
+ # Set tool name
+ ctulimit = self._tool('ctulimit')
# Setup ctulimit command
cmd = ctulimit+' inobs="data/crab_events.fits"'+ \
@@ -73,15 +70,13 @@ class Test(gammalib.GPythonTestSuite):
' caldb="prod2" irf="South_0.5h"'+ \
' logfile="ctulimit_cmd1.log" chatter=1'
- # Execute ctulimit, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
+ # Check if execution of wrong command fails
+ self.test_assert(self._execute('command that does not exist') != 0,
+ 'Self test of test script')
# Check if execution was successful
- self.test_assert(rc == 0,
- 'Successful ctulimit execution on command line')
+ self.test_assert(self._execute(cmd) == 0,
+ 'Check successful execution from command line')
# Check result file
self._check_result_file('ctulimit_cmd1.log')
@@ -92,15 +87,9 @@ class Test(gammalib.GPythonTestSuite):
' caldb="prod2" irf="South_0.5h"'+ \
' logfile="ctulimit_cmd2.log" chatter=1'
- # Execute ctulimit, make sure we catch any exception
- try:
- rc = os.system(cmd+' >/dev/null 2>&1')
- except:
- pass
-
# Check if execution failed
- self.test_assert(rc != 0,
- 'Failure of ctulimit execution on command line')
+ self.test_assert(self._execute(cmd) != 0,
+ 'Check invalid input file when executed from command line')
# Return
return
@@ -108,7 +97,7 @@ class Test(gammalib.GPythonTestSuite):
# Test ctulimit from Python
def _test_python(self):
"""
- Test ctulimit from Python.
+ Test ctulimit from Python
"""
# Set-up ctulimit
ulimit = ctools.ctulimit()
@@ -134,7 +123,7 @@ class Test(gammalib.GPythonTestSuite):
# Check result file
def _check_result_file(self, filename):
"""
- Check result file.
+ Check result file
"""
# Return
return
diff --git a/test/test_cscripts_class.py b/test/testing.py
index 085a5cd..3d9d9ca 100755
--- a/test/test_cscripts_class.py
+++ b/test/testing.py
@@ -1,5 +1,5 @@
# ==========================================================================
-# cscripts test base class
+# Python base class for unit tests
#
# Copyright (C) 2016 Juergen Knoedlseder
#
@@ -21,12 +21,12 @@ import os
import gammalib
-# ======================================= #
-# Base class for unit testing of cscripts #
-# ======================================= #
-class cscripts_test(gammalib.GPythonTestSuite):
+# ================================ #
+# Python base class for unit tests #
+# ================================ #
+class test(gammalib.GPythonTestSuite):
"""
- Test class for scripts
+ Python base class for unit tests
"""
# Constructor
@@ -45,7 +45,7 @@ class cscripts_test(gammalib.GPythonTestSuite):
"""
Set script name
"""
- # Kluge to set the command. The installed version has no README file
+ # Kluge to set the command. The installed version has no README.md file
if os.path.isfile('README.md'):
script = '../cscripts/'+name+'.py'
else:
@@ -54,6 +54,20 @@ class cscripts_test(gammalib.GPythonTestSuite):
# Return script name
return script
+ # Set tool name
+ def _tool(self, name):
+ """
+ Set tool name
+ """
+ # Kluge to set the command. The installed version has no README.md file
+ if os.path.isfile('README.md'):
+ tool = '../src/'+name+'/'+name
+ else:
+ tool = name
+
+ # Return tool name
+ return tool
+
# Execute command and catch any exception
def _execute(self, cmd):
"""