From 651d45a753e169e2a846ca39bd711920b485bd90 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Mon, 14 Mar 2016 18:03:22 +0100 Subject: [PATCH] Add ctbin Python module unit tests. --- test/test_ctbin.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- test/test_python_cscripts.py | 2 +- test/test_python_ctools.py | 2 +- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/test/test_ctbin.py b/test/test_ctbin.py index 5368618..f17d62d 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -52,15 +52,15 @@ class Test(gammalib.GPythonTestSuite): self.name("ctbin") # Append tests - self.append(self.test_functional, "Test ctbin functionality") + self.append(self._test_ctbin, "Test ctbin") # Return return - # Test ctbin functionnality - def test_functional(self): + # Test ctbin + def _test_ctbin(self): """ - Test ctbin functionnality. + Test ctbin. """ # Set-up ctbin bin = ctools.ctbin() @@ -83,22 +83,91 @@ class Test(gammalib.GPythonTestSuite): try: bin.run() self.test_try_success() - #except Exception as e: - # msg = "Exception occured in ctbin: %s." % (e,) except: msg = "Exception occured in ctbin." self.test_try_failure(msg) + # Check content of observation and cube + self._test_observation(bin, 5542) + self._test_cube(bin.cube(), 5542) + + # Test copy constructor + cpy_bin = bin.copy() + + # Check content of observation and cube + self._test_observation(cpy_bin, 5542) + self._test_cube(cpy_bin.cube(), 5542) + + # Run copy of ctbin again + cpy_bin.run() + + # Check content of observation and cube. We expect now an empty + # event cube as on input the observation is binned, and any binned + # observation will be skipped, hence the counts cube should be + # empty. + self._test_observation(cpy_bin, 0) + self._test_cube(cpy_bin.cube(), 0) + + # Clear and run copy of ctbin again + #cpy_bin.clear() + #cpy_bin.run() +#RuntimeError: *** ERROR in GXmlAttribute::value(std::string): Invalid XML attribute value: *** ERROR in GPythonTestSuite::test: +#*** ERROR in GApplicationPars::operator[](std::string&): Invalid argument. Parameter "debug" has not been found in parameter file. +#Please specify a valid parameter name. + # Save counts cube self.test_try("Save counts cube") try: bin.save() self.test_try_success() - #except Exception as e: - # msg = "Exception occured in saving counts cube: %s." % (e,) except: msg = "Exception occured in saving counts cube." self.test_try_failure(msg) + # Load counts cube and check content. + evt = gammalib.GCTAEventCube("cntmap.fits") + self._test_cube(evt, 5542) + + # Return + return + + # Check observation + def _test_observation(self, ctbin, nevents): + """ + Test content of an observation. + + Args: + ctbin: ctbin instance + nevents: Expected number of events + """ + # Test observation container + obs = gammalib.GCTAObservation(ctbin.obs()[0]) + pnt = obs.pointing() + self.test_value(ctbin.obs().size(), 1, "There is one observation") + self.test_assert(obs.instrument() == "CTA", "Observation is CTA observation") + self.test_value(obs.ontime(), 1800.0, 1.0e-6, "Ontime is 1800 sec") + self.test_value(obs.livetime(), 1710.0, 1.0e-6, "Livetime is 1710 sec") + self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, "Pointing Right Ascension is 83.63 deg") + self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, "Pointing Declination is 22.01 deg") + + # Test event cube + self._test_cube(obs.events(), nevents) + + # Return + return + + # Check event cube + def _test_cube(self, cube, nevents): + """ + Test content of event cube." + + Args: + cube: Event cube + nevents: Expected number of events. + """ + # Test event cube + self.test_value(cube.size(), 800000, "800000 event bins") + self.test_value(cube.number(), nevents, str(nevents)+" events") + # Return return diff --git a/test/test_python_cscripts.py b/test/test_python_cscripts.py index 9c57f1a..c3266af 100755 --- a/test/test_python_cscripts.py +++ b/test/test_python_cscripts.py @@ -34,7 +34,7 @@ def test(installed=False): Perform unit testing for Python interface. """ # Allocate test suite container - suites = gammalib.GTestSuites("cscripts unit testing") + suites = gammalib.GTestSuites("cscripts Python module unit testing") # Allocate test suites and append them to the container suite_cscaldb = test_cscaldb.Test() diff --git a/test/test_python_ctools.py b/test/test_python_ctools.py index 3d4aacd..1f72500 100755 --- a/test/test_python_ctools.py +++ b/test/test_python_ctools.py @@ -48,7 +48,7 @@ def test(installed=False): Perform unit testing for Python interface. """ # Allocate test suite container - suites = gammalib.GTestSuites("ctools unit testing") + suites = gammalib.GTestSuites("ctools Python module unit testing") # Allocate test suites and append them to the container suite_ctobssim = test_ctobssim.Test() -- libgit2 0.21.4