Commit 5446cc5d6b610828db5ad115e40b42c26bd36ba8
1 parent
ff88c7a1
Add command line test for ctobssim.
Showing
1 changed file
with
65 additions
and
10 deletions
test/test_ctobssim.py
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | # ========================================================================== |
| 3 | -# This scripts performs unit tests for the ctobssim module. | |
| 3 | +# This scripts performs unit tests for the ctobssim tool. | |
| 4 | 4 | # |
| 5 | 5 | # Copyright (C) 2014-2016 Juergen Knoedlseder |
| 6 | 6 | # |
| ... | ... | @@ -18,17 +18,21 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | from cscripts import obsutils |
| 24 | 25 | |
| 25 | 26 | |
| 26 | -# ============================== # | |
| 27 | -# Test class for ctobssim module # | |
| 28 | -# ============================== # | |
| 27 | +# ============================ # | |
| 28 | +# Test class for ctobssim tool # | |
| 29 | +# ============================ # | |
| 29 | 30 | class Test(gammalib.GPythonTestSuite): |
| 30 | 31 | """ |
| 31 | - Test class for ctobssim module. | |
| 32 | + Test class for ctobssim tools. | |
| 33 | + | |
| 34 | + This test class makes unit tests for the ctobssim tool by using it from | |
| 35 | + the command line and from Python. | |
| 32 | 36 | """ |
| 33 | 37 | |
| 34 | 38 | # Constructor |
| ... | ... | @@ -56,16 +60,67 @@ class Test(gammalib.GPythonTestSuite): |
| 56 | 60 | self.name("ctobssim") |
| 57 | 61 | |
| 58 | 62 | # Append tests |
| 59 | - self.append(self._test_ctobssim, "Test ctobssim") | |
| 60 | - #self.append(self._test_container, "Test ctobssim on observation container") | |
| 63 | + self.append(self._test_ctobssim_cmd, "Test ctobssim on command line") | |
| 64 | + self.append(self._test_ctobssim_python, "Test ctobssim from Python") | |
| 61 | 65 | |
| 62 | 66 | # Return |
| 63 | 67 | return |
| 64 | 68 | |
| 65 | - # Test ctobssim | |
| 66 | - def _test_ctobssim(self): | |
| 69 | + # Test ctobssim on command line | |
| 70 | + def _test_ctobssim_cmd(self): | |
| 67 | 71 | """ |
| 68 | - Test ctobssim. | |
| 72 | + Test ctobssim on the command line. | |
| 73 | + """ | |
| 74 | + # Kluge to set the command (installed version has no README file) | |
| 75 | + if os.path.isfile("README"): | |
| 76 | + ctobssim = "../src/ctobssim/ctobssim" | |
| 77 | + else: | |
| 78 | + ctobssim = "ctobssim" | |
| 79 | + | |
| 80 | + # Setup ctobssim command | |
| 81 | + cmd = ctobssim+' inmodel="data/crab.xml" outevents="events.fits"'+ \ | |
| 82 | + ' caldb="irf" irf="cta_dummy_irf" '+ \ | |
| 83 | + ' ra=83.63 dec=22.01 rad=10.0'+ \ | |
| 84 | + ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' | |
| 85 | + | |
| 86 | + # Execute ctobssim, make sure we catch any exception | |
| 87 | + try: | |
| 88 | + rc = os.system(cmd+" >/dev/null") | |
| 89 | + except: | |
| 90 | + pass | |
| 91 | + | |
| 92 | + # Check if execution was successful | |
| 93 | + self.test_assert(rc == 0, | |
| 94 | + "Successful ctobssim execution on command line") | |
| 95 | + | |
| 96 | + # Load counts cube and check content. | |
| 97 | + evt = gammalib.GCTAEventList("events.fits") | |
| 98 | + self._test_list(evt, 4119) | |
| 99 | + | |
| 100 | + # Setup ctobssim command | |
| 101 | + cmd = ctobssim+' inmodel="model_that_does_not_exist.xml"'+ \ | |
| 102 | + ' outevents="events.fits"'+ \ | |
| 103 | + ' caldb="irf" irf="cta_dummy_irf" '+ \ | |
| 104 | + ' ra=83.63 dec=22.01 rad=10.0'+ \ | |
| 105 | + ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' | |
| 106 | + | |
| 107 | + # Execute ctobssim, make sure we catch any exception | |
| 108 | + try: | |
| 109 | + rc = os.system(cmd+" >/dev/null") | |
| 110 | + except: | |
| 111 | + pass | |
| 112 | + | |
| 113 | + # Check if execution failed | |
| 114 | + self.test_assert(rc != 0, | |
| 115 | + "Failure of ctobssim execution on command line") | |
| 116 | + | |
| 117 | + # Return | |
| 118 | + return | |
| 119 | + | |
| 120 | + # Test ctobssim from Python | |
| 121 | + def _test_ctobssim_python(self): | |
| 122 | + """ | |
| 123 | + Test ctobssim from Python. | |
| 69 | 124 | """ |
| 70 | 125 | # Set-up ctobssim |
| 71 | 126 | sim = ctools.ctobssim() | ... | ... |