diff --git a/.gitignore b/.gitignore
index 50d115b..6412944 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,6 +81,7 @@ test/*.reg
test/*.trs
test/*.txt
test/test_cscripts.sh
+test/test_examples.sh
test/reports/*.xml
test/butterfly.txt
test/.coverage
diff --git a/configure.ac b/configure.ac
index c278b20..c191943 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1025,6 +1025,7 @@ AC_CONFIG_FILES([Makefile
test/test_cscripts.sh
test/test_python_ctools.sh
test/test_python_cscripts.sh
+ test/test_examples.sh
pyext/Makefile
pyext/setup.py
pyext/ctools/__init__.py
@@ -1038,6 +1039,7 @@ AC_CONFIG_FILES([Makefile
[if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi;
if test -f test/test_python_ctools.sh; then chmod +x test/test_python_ctools.sh; fi;
if test -f test/test_python_cscripts.sh; then chmod +x test/test_python_cscripts.sh; fi;
+ if test -f test/test_examples.sh; then chmod +x test/test_examples.sh; fi;
if test -f testconf.sh; then chmod +x testconf.sh; fi])
AC_OUTPUT
diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py
index 1c21dfc..5cb9db2 100755
--- a/examples/pipeline_binned_disk.py
+++ b/examples/pipeline_binned_disk.py
@@ -27,7 +27,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95, caldb='prod2', irf='South_0.5h'):
"""
Returns an observation container.
diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py
index 88724da..56e96f0 100755
--- a/examples/pipeline_binned_mem.py
+++ b/examples/pipeline_binned_mem.py
@@ -34,7 +34,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95,
caldb="prod2", irf="South_50h"):
"""
diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py
index 1c35626..09d7e93 100755
--- a/examples/pipeline_stacked_disk.py
+++ b/examples/pipeline_stacked_disk.py
@@ -34,7 +34,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95,
caldb="prod2", irf="South_50h"):
"""
diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py
index 36ab850..75e98dc 100755
--- a/examples/pipeline_stacked_mem.py
+++ b/examples/pipeline_stacked_mem.py
@@ -34,7 +34,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95,
caldb="prod2", irf="South_50h"):
"""
diff --git a/examples/pipeline_unbinned_disk.py b/examples/pipeline_unbinned_disk.py
index 44c7ea6..b97cd88 100755
--- a/examples/pipeline_unbinned_disk.py
+++ b/examples/pipeline_unbinned_disk.py
@@ -34,7 +34,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95,
caldb="prod2", irf="South_50h"):
"""
diff --git a/examples/pipeline_unbinned_mem.py b/examples/pipeline_unbinned_mem.py
index b2deb08..d57847d 100755
--- a/examples/pipeline_unbinned_mem.py
+++ b/examples/pipeline_unbinned_mem.py
@@ -34,7 +34,7 @@ from cscripts import obsutils
# Setup observations #
# ================== #
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5,
- emin=0.1, emax=100.0, rad=5.0, duration=1800.0,
+ emin=0.1, emax=100.0, rad=5.0, duration=180.0,
deadc=0.95,
caldb="prod2", irf="South_50h"):
"""
diff --git a/test/Makefile.am b/test/Makefile.am
index 3d9f41e..2213dab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -9,6 +9,7 @@ if WITH_PYTHON
TEST_CSCRIPTS = test_cscripts.sh
TEST_PYTHON_CTOOLS = test_python_ctools.sh
TEST_PYTHON_CSCRIPTS = test_python_cscripts.sh
+ TEST_PYTHON_EXAMPLES = test_examples.sh
TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH)
endif
@@ -18,7 +19,8 @@ TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(LIBDI
# Tests (these are the tests to be executed)
TESTS = $(TEST_PYTHON_CTOOLS) \
- $(TEST_PYTHON_CSCRIPTS)
+ $(TEST_PYTHON_CSCRIPTS) \
+ $(TEST_PYTHON_EXAMPLES)
# Add Valgrind rule
valgrind:
diff --git a/test/test_examples.py b/test/test_examples.py
new file mode 100755
index 0000000..78b174c
--- /dev/null
+++ b/test/test_examples.py
@@ -0,0 +1,209 @@
+#! /usr/bin/env python
+# ==========================================================================
+# Performs unit tests for the ctools example scripts
+#
+# Copyright (C) 2016 Juergen Knoedlseder
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ==========================================================================
+import os
+import sys
+import gammalib
+import ctools
+import cscripts
+
+
+# =============================================== #
+# Test class for example executables unit testing #
+# =============================================== #
+class Test(gammalib.GPythonTestSuite):
+ """
+ Test class for GammaLib example executables
+ """
+ # Constructor
+ def __init__(self):
+ """
+ Constructor.
+ """
+ # Call base class constructor
+ gammalib.GPythonTestSuite.__init__(self)
+
+ # Return
+ return
+
+ # Execute Python script
+ def _execute_python(self, name):
+ """
+ Execute Python script
+
+ Parameters
+ ----------
+ name : str
+ Python script name with .py extension.
+ """
+ # Setup command
+ cmd = '../examples/' + name + '.py'
+
+ # Execute Python script, make sure we catch any exception
+ try:
+ rc = os.system(cmd+' > example_'+name+'.log 2>&1')
+ except:
+ pass
+
+ # Check if execution was successful
+ self.test_assert(rc == 0, 'Check "'+name+'" script from command line')
+
+ # Return
+ return
+
+ # Set test functions
+ def set(self):
+ """
+ Set all test functions
+ """
+ # Set test name
+ self.name('examples')
+
+ # Append tests
+ self.append(self.test_pipeline_binned_disk, 'Test pipeline_binned_disk')
+ self.append(self.test_pipeline_binned_mem, 'Test pipeline_binned_mem')
+ self.append(self.test_pipeline_stacked_disk, 'Test pipeline_stacked_disk')
+ self.append(self.test_pipeline_stacked_mem, 'Test pipeline_stacked_mem')
+ self.append(self.test_pipeline_unbinned_disk, 'Test pipeline_unbinned_disk')
+ self.append(self.test_pipeline_unbinned_mem, 'Test pipeline_unbinned_mem')
+
+ # Return
+ return
+
+ # Test pipeline_binned_disk
+ def test_pipeline_binned_disk(self):
+ """
+ Test pipeline_binned_disk
+ """
+ # Execute script
+ self._execute_python('pipeline_binned_disk')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+ # Test pipeline_binned_mem
+ def test_pipeline_binned_mem(self):
+ """
+ Test pipeline_binned_mem
+ """
+ # Execute script
+ self._execute_python('pipeline_binned_mem')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+ # Test pipeline_stacked_disk
+ def test_pipeline_stacked_disk(self):
+ """
+ Test pipeline_stacked_disk
+ """
+ # Execute script
+ self._execute_python('pipeline_stacked_disk')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+ # Test pipeline_stacked_mem
+ def test_pipeline_stacked_mem(self):
+ """
+ Test pipeline_stacked_mem
+ """
+ # Execute script
+ self._execute_python('pipeline_stacked_mem')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+ # Test pipeline_unbinned_disk
+ def test_pipeline_unbinned_disk(self):
+ """
+ Test pipeline_unbinned_disk
+ """
+ # Execute script
+ self._execute_python('pipeline_unbinned_disk')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+ # Test pipeline_unbinned_mem
+ def test_pipeline_unbinned_mem(self):
+ """
+ Test pipeline_unbinned_mem
+ """
+ # Execute script
+ self._execute_python('pipeline_unbinned_mem')
+
+ #TODO: Do any testing
+
+ # Return
+ return
+
+
+# ======================== #
+# Main routine entry point #
+# ======================== #
+if __name__ == '__main__':
+
+ # Set calibration database
+ os.environ['CALDB'] = '../caldb'
+
+ # Set PFILES environment variable
+ try:
+ os.mkdir('pfiles')
+ except:
+ pass
+ os.environ['PFILES'] = 'pfiles'
+
+ # Copy over pfiles
+ os.system('cp -r ../src/*/*.par pfiles/')
+ os.system('cp -r ../cscripts/*.par pfiles/')
+
+ # Allocate test suites
+ suites = gammalib.GTestSuites('Examples testing')
+
+ # Allocate test suite, setup tests and append them to the container
+ suite = Test()
+ suite.set()
+ suites.append(suite)
+
+ # Run test suite
+ success = suites.run()
+
+ # Save test results
+ suites.save('reports/examples.xml')
+
+ # Set return code
+ if success:
+ rc = 0
+ else:
+ rc = 1
+
+ # Exit with return code
+ sys.exit(rc)
diff --git a/test/test_examples.sh.in b/test/test_examples.sh.in
new file mode 100755
index 0000000..fc5d689
--- /dev/null
+++ b/test/test_examples.sh.in
@@ -0,0 +1,25 @@
+#! /bin/sh
+# ==========================================================================
+# This script launches the examples unit tests
+#
+# Copyright (C) 2016 Juergen Knoedlseder
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ==========================================================================
+
+#
+# Run the examples test
+# =====================
+@PYTHON_COVERAGE@./test_examples.py