Commit 562eded470142529eae2f204af493c22d19bce19
1 parent
e995b59b
Add ctbin command line tests to test_python_ctools.py.
Note that test_python_ctools.py could ultimately replace all ctools, as for the shell script we anyways to not recover the results. Still, the shell script may still make some limited sense.
Showing
2 changed files
with
70 additions
and
17 deletions
test/test_ctbin.py
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | # ========================================================================== |
| 3 | -# This scripts performs unit tests for the ctbin module. | |
| 3 | +# This scripts performs unit tests for the ctbin tool. | |
| 4 | 4 | # |
| 5 | 5 | # Copyright (C) 2014-2016 Juergen Knoedlseder |
| 6 | 6 | # |
| ... | ... | @@ -18,16 +18,20 @@ |
| 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 | |
| 24 | 25 | |
| 25 | -# =========================== # | |
| 26 | -# Test class for ctbin module # | |
| 27 | -# =========================== # | |
| 26 | +# ========================= # | |
| 27 | +# Test class for ctbin tool # | |
| 28 | +# ========================= # | |
| 28 | 29 | class Test(gammalib.GPythonTestSuite): |
| 29 | 30 | """ |
| 30 | - Test class for ctbin module. | |
| 31 | + Test class for ctbin tool. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the ctbin tool by using it from | |
| 34 | + the command line and from Python. | |
| 31 | 35 | """ |
| 32 | 36 | |
| 33 | 37 | # Constructor |
| ... | ... | @@ -53,15 +57,66 @@ class Test(gammalib.GPythonTestSuite): |
| 53 | 57 | self.name("ctbin") |
| 54 | 58 | |
| 55 | 59 | # Append tests |
| 56 | - self.append(self._test_ctbin, "Test ctbin") | |
| 60 | + self.append(self._test_ctbin_cmd, "Test ctbin on command line") | |
| 61 | + self.append(self._test_ctbin_python, "Test ctbin from Python") | |
| 57 | 62 | |
| 58 | 63 | # Return |
| 59 | 64 | return |
| 60 | 65 | |
| 61 | - # Test ctbin | |
| 62 | - def _test_ctbin(self): | |
| 66 | + # Test ctbin on command line | |
| 67 | + def _test_ctbin_cmd(self): | |
| 63 | 68 | """ |
| 64 | - Test ctbin. | |
| 69 | + Test ctbin on the command line. | |
| 70 | + """ | |
| 71 | + # Set ctbin tool | |
| 72 | + ctbin = "../src/ctbin/ctbin" | |
| 73 | + noout = " >/dev/null" | |
| 74 | + | |
| 75 | + # Setup ctbin command | |
| 76 | + cmd = ctbin+' inobs="'+self._events_name+'"'+ \ | |
| 77 | + ' outcube="cntmap_cmd1.fits"'+\ | |
| 78 | + ' emin=0.1 emax=100.0 enumbins=20 ebinalg="LOG"'+ \ | |
| 79 | + ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ | |
| 80 | + ' xref=83.63 yref=22.01 proj="CAR"'+noout | |
| 81 | + | |
| 82 | + # Execute ctbin, make sure we catch any exception | |
| 83 | + try: | |
| 84 | + rc = os.system(cmd) | |
| 85 | + except: | |
| 86 | + pass | |
| 87 | + | |
| 88 | + # Check if execution was successful | |
| 89 | + self.test_assert(rc == 0, | |
| 90 | + "Successful ctbin execution on command line") | |
| 91 | + | |
| 92 | + # Load counts cube and check content. | |
| 93 | + evt = gammalib.GCTAEventCube("cntmap_cmd1.fits") | |
| 94 | + self._test_cube(evt, 5542) | |
| 95 | + | |
| 96 | + # Setup ctbin command | |
| 97 | + cmd = ctbin+' inobs="events_that_do_not_exist.fits"'+ \ | |
| 98 | + ' outcube="cntmap_cmd2.fits"'+\ | |
| 99 | + ' emin=0.1 emax=100.0 enumbins=20 ebinalg="LOG"'+ \ | |
| 100 | + ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ | |
| 101 | + ' xref=83.63 yref=22.01 proj="CAR"'+noout | |
| 102 | + | |
| 103 | + # Execute ctbin, make sure we catch any exception | |
| 104 | + try: | |
| 105 | + rc = os.system(cmd) | |
| 106 | + except: | |
| 107 | + pass | |
| 108 | + | |
| 109 | + # Check if execution failed | |
| 110 | + self.test_assert(rc != 0, | |
| 111 | + "Failure of ctbin execution on command line") | |
| 112 | + | |
| 113 | + # Return | |
| 114 | + return | |
| 115 | + | |
| 116 | + # Test ctbin from Python | |
| 117 | + def _test_ctbin_python(self): | |
| 118 | + """ | |
| 119 | + Test ctbin from Python. | |
| 65 | 120 | """ |
| 66 | 121 | # Set-up ctbin |
| 67 | 122 | bin = ctools.ctbin() | ... | ... |
test/test_python_ctools.py
| ... | ... | @@ -40,15 +40,15 @@ import test_cterror |
| 40 | 40 | import test_pipelines |
| 41 | 41 | |
| 42 | 42 | |
| 43 | -# ================== # | |
| 44 | -# Perform unit tests # | |
| 45 | -# ================== # | |
| 43 | +# ========================= # | |
| 44 | +# Perform ctools unit tests # | |
| 45 | +# ========================= # | |
| 46 | 46 | def test(installed=False): |
| 47 | 47 | """ |
| 48 | - Perform unit testing for Python interface. | |
| 48 | + Perform unit testing for ctools. | |
| 49 | 49 | """ |
| 50 | 50 | # Allocate test suite container |
| 51 | - suites = gammalib.GTestSuites("ctools Python module unit testing") | |
| 51 | + suites = gammalib.GTestSuites("ctools unit testing") | |
| 52 | 52 | |
| 53 | 53 | # Allocate test suites and append them to the container |
| 54 | 54 | suite_ctobssim = test_ctobssim.Test() |
| ... | ... | @@ -153,8 +153,6 @@ def test(installed=False): |
| 153 | 153 | # Main routine entry point # |
| 154 | 154 | # ======================== # |
| 155 | 155 | if __name__ == '__main__': |
| 156 | - """ | |
| 157 | - Perform unit testing for Python interface. | |
| 158 | - """ | |
| 156 | + | |
| 159 | 157 | # Run tests |
| 160 | 158 | test() | ... | ... |