From 5df975a625f5e97c8b4f12f3aa4728b59aecde02 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Mon, 6 Oct 2014 17:34:51 +0200 Subject: [PATCH] Add test cases for cttsmap --- test/test_ctools.sh | 29 +++++++++++++++++++++++++++++ test/test_cttsmap.py | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_python.py | 4 ++++ 3 files changed, 134 insertions(+), 0 deletions(-) create mode 100755 test/test_cttsmap.py diff --git a/test/test_ctools.sh b/test/test_ctools.sh index ed940f1..682d7de 100755 --- a/test/test_ctools.sh +++ b/test/test_ctools.sh @@ -36,6 +36,7 @@ $ECHO "***************" # ================== ctbin=../src/ctbin/ctbin ctlike=../src/ctlike/ctlike +cttsmap=../src/cttsmap/cttsmap ctmodel=../src/ctmodel/ctmodel ctobssim=../src/ctobssim/ctobssim ctselect=../src/ctselect/ctselect @@ -347,6 +348,34 @@ $ECHO " ok" # +# Test cttsmap +# ============ +$ECHO -n "Test cttsmap: " +$cttsmap infile="selected_events.fits" \ + srcmdl="data/crab.xml" \ + srcname="Crab" \ + caldb="irf" \ + irf="cta_dummy_irf" \ + outfile="tsmap.fits" \ + nxpix=5 \ + nypix=5 \ + binsz=0.05 \ + coordsys="CEL" \ + xref=83.63 \ + yref=22.01 \ + proj="CAR" +$ECHO -n "." +if [ -s "tsmap.fits" ] +then + $ECHO -n "." +else + $ECHO " tsmap.fits file is not valid" + exit 1 +fi +$ECHO " ok" + + +# # Test ctexpcube # ============== $ECHO -n "Test ctexpcube: " diff --git a/test/test_cttsmap.py b/test/test_cttsmap.py new file mode 100755 index 0000000..ef731a9 --- /dev/null +++ b/test/test_cttsmap.py @@ -0,0 +1,101 @@ +#! /usr/bin/env python +# ========================================================================== +# This scripts performs unit tests for the cttsmap tool. +# +# Copyright (C) 2014 Juergen Knoedlseder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ========================================================================== +import gammalib +import ctools + + +# ========================== # +# Test class for cttsmap tool # +# ========================== # +class Test(gammalib.GPythonTestSuite): + """ + Test class for cttsmap tool. + """ + # Constructor + def __init__(self): + """ + Constructor. + """ + # Call base class constructor + gammalib.GPythonTestSuite.__init__(self) + + # Set members + self.events_name = "data/crab_events.fits" + self.model_name = "data/crab.xml" + self.caldb = "irf" + self.irf = "cta_dummy_irf" + + # Return + return + + # Set test functions + def set(self): + """ + Set all test functions. + """ + # Set test name + self.name("cttsmap") + + # Append tests + self.append(self.test_functional, "Test cttsmap functionality") + + # Return + return + + # Test cttsmap functionnality + def test_functional(self): + """ + Test cttsmap functionnality. + """ + # Set-up cttsmap + tsmap = ctools.cttsmap() + tsmap["infile"].filename(self.events_name) + tsmap["srcmdl"].filename(self.model_name) + tsmap["srcname"].string("Crab") + tsmap["caldb"].string(self.caldb) + tsmap["irf"].string(self.irf) + tsmap["outfile"].filename("tsmap.fits") + tsmap["nxpix"].integer(5) + tsmap["nypix"].integer(5) + tsmap["binsz"].real(0.02) + tsmap["coordsys"].string("CEL") + tsmap["proj"].string("CAR") + tsmap["xref"].real(83.63) + tsmap["yref"].real(22.01) + + # Run tool + self.test_try("Run cttsmap") + try: + tsmap.run() + self.test_try_success() + except: + self.test_try_failure("Exception occured in cttsmap.") + + # Save results + self.test_try("Save results") + try: + tsmap.save() + self.test_try_success() + except: + self.test_try_failure("Exception occured in saving results.") + + # Return + return diff --git a/test/test_python.py b/test/test_python.py index 8ab4a76..e9031f5 100755 --- a/test/test_python.py +++ b/test/test_python.py @@ -26,6 +26,7 @@ import test_ctobssim import test_ctselect import test_ctbin import test_ctlike +import test_cttsmap import test_ctmodel import test_ctskymap import test_ctexpcube @@ -50,6 +51,7 @@ if __name__ == '__main__': suite_ctselect = test_ctselect.Test() suite_ctbin = test_ctbin.Test() suite_ctlike = test_ctlike.Test() + suite_cttsmap = test_cttsmap.Test() suite_ctmodel = test_ctmodel.Test() suite_ctskymap = test_ctskymap.Test() suite_ctexpcube = test_ctexpcube.Test() @@ -63,6 +65,7 @@ if __name__ == '__main__': suite_ctselect.set() suite_ctbin.set() suite_ctlike.set() + suite_cttsmap.set() suite_ctmodel.set() suite_ctskymap.set() suite_ctexpcube.set() @@ -76,6 +79,7 @@ if __name__ == '__main__': suites.append(suite_ctselect) suites.append(suite_ctbin) suites.append(suite_ctlike) + suites.append(suite_cttsmap) suites.append(suite_ctmodel) suites.append(suite_ctskymap) suites.append(suite_ctexpcube) -- libgit2 0.21.4