Commit 996c4df264a3a2a05dabe482323dedc5422ada7a

Authored by Jürgen Knödlseder
1 parent ab8f5bbc

Add cterror Python unit test.

test/test_cterror.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the cterror tool.
  4 +#
  5 +# Copyright (C) 2015 Florent Forest
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import gammalib
  22 +import ctools
  23 +
  24 +
  25 +# =========================== #
  26 +# Test class for cterror tool #
  27 +# =========================== #
  28 +class Test(gammalib.GPythonTestSuite):
  29 + """
  30 + Test class for cterror tool.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + gammalib.GPythonTestSuite.__init__(self)
  39 +
  40 + # Set members
  41 + self.events_name = "data/crab_events.fits"
  42 + self.model_name = "data/crab.xml"
  43 + self.result_name = "cterror_result.xml"
  44 + self.caldb = "irf"
  45 + self.irf = "cta_dummy_irf"
  46 +
  47 + # Return
  48 + return
  49 +
  50 + # Set test functions
  51 + def set(self):
  52 + """
  53 + Set all test functions.
  54 + """
  55 + # Set test name
  56 + self.name("cterror")
  57 +
  58 + # Append tests
  59 + self.append(self.test_functional, "Test cterror functionality")
  60 +
  61 + # Return
  62 + return
  63 +
  64 + # Test cttsmap functionnality
  65 + def test_functional(self):
  66 + """
  67 + Test cterror functionnality.
  68 + """
  69 + # Set-up cterror
  70 + error = ctools.cterror()
  71 + error["inobs"].filename(self.events_name)
  72 + error["inmodel"].filename(self.model_name)
  73 + error["outmodel"].filename(self.result_name)
  74 + error["srcname"].string("Crab")
  75 + error["caldb"].string(self.caldb)
  76 + error["irf"].string(self.irf)
  77 +
  78 + # Run tool
  79 + self.test_try("Run cterror")
  80 + try:
  81 + error.run()
  82 + self.test_try_success()
  83 + except:
  84 + self.test_try_failure("Exception occured in cterror.")
  85 +
  86 + # Save results
  87 + self.test_try("Save results")
  88 + try:
  89 + error.save()
  90 + self.test_try_success()
  91 + except:
  92 + self.test_try_failure("Exception occured in saving results.")
  93 +
  94 + # Return
  95 + return
test/test_ctulimit.py
@@ -22,12 +22,12 @@ import gammalib @@ -22,12 +22,12 @@ import gammalib
22 import ctools 22 import ctools
23 23
24 24
25 -# ========================== #  
26 -# Test class for cttsmap tool #  
27 -# ========================== # 25 +# ============================ #
  26 +# Test class for ctulimit tool #
  27 +# ============================ #
28 class Test(gammalib.GPythonTestSuite): 28 class Test(gammalib.GPythonTestSuite):
29 """ 29 """
30 - Test class for cttsmap tool. 30 + Test class for ctulimit tool.
31 """ 31 """
32 # Constructor 32 # Constructor
33 def __init__(self): 33 def __init__(self):
@@ -63,7 +63,7 @@ class Test(gammalib.GPythonTestSuite): @@ -63,7 +63,7 @@ class Test(gammalib.GPythonTestSuite):
63 # Test cttsmap functionnality 63 # Test cttsmap functionnality
64 def test_functional(self): 64 def test_functional(self):
65 """ 65 """
66 - Test cttsmap functionnality. 66 + Test ctulimit functionnality.
67 """ 67 """
68 # Set-up cttsmap 68 # Set-up cttsmap
69 ulimit = ctools.ctulimit() 69 ulimit = ctools.ctulimit()