Commit 651d45a753e169e2a846ca39bd711920b485bd90
1 parent
2a8ed281
Add ctbin Python module unit tests.
Showing
3 changed files
with
79 additions
and
10 deletions
test/test_ctbin.py
| @@ -52,15 +52,15 @@ class Test(gammalib.GPythonTestSuite): | @@ -52,15 +52,15 @@ class Test(gammalib.GPythonTestSuite): | ||
| 52 | self.name("ctbin") | 52 | self.name("ctbin") |
| 53 | 53 | ||
| 54 | # Append tests | 54 | # Append tests |
| 55 | - self.append(self.test_functional, "Test ctbin functionality") | 55 | + self.append(self._test_ctbin, "Test ctbin") |
| 56 | 56 | ||
| 57 | # Return | 57 | # Return |
| 58 | return | 58 | return |
| 59 | 59 | ||
| 60 | - # Test ctbin functionnality | ||
| 61 | - def test_functional(self): | 60 | + # Test ctbin |
| 61 | + def _test_ctbin(self): | ||
| 62 | """ | 62 | """ |
| 63 | - Test ctbin functionnality. | 63 | + Test ctbin. |
| 64 | """ | 64 | """ |
| 65 | # Set-up ctbin | 65 | # Set-up ctbin |
| 66 | bin = ctools.ctbin() | 66 | bin = ctools.ctbin() |
| @@ -83,22 +83,91 @@ class Test(gammalib.GPythonTestSuite): | @@ -83,22 +83,91 @@ class Test(gammalib.GPythonTestSuite): | ||
| 83 | try: | 83 | try: |
| 84 | bin.run() | 84 | bin.run() |
| 85 | self.test_try_success() | 85 | self.test_try_success() |
| 86 | - #except Exception as e: | ||
| 87 | - # msg = "Exception occured in ctbin: %s." % (e,) | ||
| 88 | except: | 86 | except: |
| 89 | msg = "Exception occured in ctbin." | 87 | msg = "Exception occured in ctbin." |
| 90 | self.test_try_failure(msg) | 88 | self.test_try_failure(msg) |
| 91 | 89 | ||
| 90 | + # Check content of observation and cube | ||
| 91 | + self._test_observation(bin, 5542) | ||
| 92 | + self._test_cube(bin.cube(), 5542) | ||
| 93 | + | ||
| 94 | + # Test copy constructor | ||
| 95 | + cpy_bin = bin.copy() | ||
| 96 | + | ||
| 97 | + # Check content of observation and cube | ||
| 98 | + self._test_observation(cpy_bin, 5542) | ||
| 99 | + self._test_cube(cpy_bin.cube(), 5542) | ||
| 100 | + | ||
| 101 | + # Run copy of ctbin again | ||
| 102 | + cpy_bin.run() | ||
| 103 | + | ||
| 104 | + # Check content of observation and cube. We expect now an empty | ||
| 105 | + # event cube as on input the observation is binned, and any binned | ||
| 106 | + # observation will be skipped, hence the counts cube should be | ||
| 107 | + # empty. | ||
| 108 | + self._test_observation(cpy_bin, 0) | ||
| 109 | + self._test_cube(cpy_bin.cube(), 0) | ||
| 110 | + | ||
| 111 | + # Clear and run copy of ctbin again | ||
| 112 | + #cpy_bin.clear() | ||
| 113 | + #cpy_bin.run() | ||
| 114 | +#RuntimeError: *** ERROR in GXmlAttribute::value(std::string): Invalid XML attribute value: *** ERROR in GPythonTestSuite::test: <type 'exceptions.RuntimeError'> | ||
| 115 | +#*** ERROR in GApplicationPars::operator[](std::string&): Invalid argument. Parameter "debug" has not been found in parameter file. | ||
| 116 | +#Please specify a valid parameter name. | ||
| 117 | + | ||
| 92 | # Save counts cube | 118 | # Save counts cube |
| 93 | self.test_try("Save counts cube") | 119 | self.test_try("Save counts cube") |
| 94 | try: | 120 | try: |
| 95 | bin.save() | 121 | bin.save() |
| 96 | self.test_try_success() | 122 | self.test_try_success() |
| 97 | - #except Exception as e: | ||
| 98 | - # msg = "Exception occured in saving counts cube: %s." % (e,) | ||
| 99 | except: | 123 | except: |
| 100 | msg = "Exception occured in saving counts cube." | 124 | msg = "Exception occured in saving counts cube." |
| 101 | self.test_try_failure(msg) | 125 | self.test_try_failure(msg) |
| 102 | 126 | ||
| 127 | + # Load counts cube and check content. | ||
| 128 | + evt = gammalib.GCTAEventCube("cntmap.fits") | ||
| 129 | + self._test_cube(evt, 5542) | ||
| 130 | + | ||
| 131 | + # Return | ||
| 132 | + return | ||
| 133 | + | ||
| 134 | + # Check observation | ||
| 135 | + def _test_observation(self, ctbin, nevents): | ||
| 136 | + """ | ||
| 137 | + Test content of an observation. | ||
| 138 | + | ||
| 139 | + Args: | ||
| 140 | + ctbin: ctbin instance | ||
| 141 | + nevents: Expected number of events | ||
| 142 | + """ | ||
| 143 | + # Test observation container | ||
| 144 | + obs = gammalib.GCTAObservation(ctbin.obs()[0]) | ||
| 145 | + pnt = obs.pointing() | ||
| 146 | + self.test_value(ctbin.obs().size(), 1, "There is one observation") | ||
| 147 | + self.test_assert(obs.instrument() == "CTA", "Observation is CTA observation") | ||
| 148 | + self.test_value(obs.ontime(), 1800.0, 1.0e-6, "Ontime is 1800 sec") | ||
| 149 | + self.test_value(obs.livetime(), 1710.0, 1.0e-6, "Livetime is 1710 sec") | ||
| 150 | + self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, "Pointing Right Ascension is 83.63 deg") | ||
| 151 | + self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, "Pointing Declination is 22.01 deg") | ||
| 152 | + | ||
| 153 | + # Test event cube | ||
| 154 | + self._test_cube(obs.events(), nevents) | ||
| 155 | + | ||
| 156 | + # Return | ||
| 157 | + return | ||
| 158 | + | ||
| 159 | + # Check event cube | ||
| 160 | + def _test_cube(self, cube, nevents): | ||
| 161 | + """ | ||
| 162 | + Test content of event cube." | ||
| 163 | + | ||
| 164 | + Args: | ||
| 165 | + cube: Event cube | ||
| 166 | + nevents: Expected number of events. | ||
| 167 | + """ | ||
| 168 | + # Test event cube | ||
| 169 | + self.test_value(cube.size(), 800000, "800000 event bins") | ||
| 170 | + self.test_value(cube.number(), nevents, str(nevents)+" events") | ||
| 171 | + | ||
| 103 | # Return | 172 | # Return |
| 104 | return | 173 | return |
test/test_python_cscripts.py
| @@ -34,7 +34,7 @@ def test(installed=False): | @@ -34,7 +34,7 @@ def test(installed=False): | ||
| 34 | Perform unit testing for Python interface. | 34 | Perform unit testing for Python interface. |
| 35 | """ | 35 | """ |
| 36 | # Allocate test suite container | 36 | # Allocate test suite container |
| 37 | - suites = gammalib.GTestSuites("cscripts unit testing") | 37 | + suites = gammalib.GTestSuites("cscripts Python module unit testing") |
| 38 | 38 | ||
| 39 | # Allocate test suites and append them to the container | 39 | # Allocate test suites and append them to the container |
| 40 | suite_cscaldb = test_cscaldb.Test() | 40 | suite_cscaldb = test_cscaldb.Test() |
test/test_python_ctools.py
| @@ -48,7 +48,7 @@ def test(installed=False): | @@ -48,7 +48,7 @@ def test(installed=False): | ||
| 48 | Perform unit testing for Python interface. | 48 | Perform unit testing for Python interface. |
| 49 | """ | 49 | """ |
| 50 | # Allocate test suite container | 50 | # Allocate test suite container |
| 51 | - suites = gammalib.GTestSuites("ctools unit testing") | 51 | + suites = gammalib.GTestSuites("ctools Python module unit testing") |
| 52 | 52 | ||
| 53 | # Allocate test suites and append them to the container | 53 | # Allocate test suites and append them to the container |
| 54 | suite_ctobssim = test_ctobssim.Test() | 54 | suite_ctobssim = test_ctobssim.Test() |