Commit 80625161e9a9bd9196eef57eac69608512ad5062

Authored by Jürgen Knödlseder
1 parent afd3a311

Add cscripts Python module test.

.gitignore
... ... @@ -80,6 +80,7 @@ test/model.reg
80 80 test/obs.reg
81 81 test/.coverage
82 82 test/test_python.sh
  83 +test/test_python_cscripts.sh
83 84 examples/*.fits
84 85 examples/*.xml
85 86 examples/*.dat
... ...
configure.ac
... ... @@ -998,6 +998,7 @@ AC_CONFIG_FILES([Makefile
998 998 test/Makefile
999 999 test/test_cscripts.sh
1000 1000 test/test_python.sh
  1001 + test/test_python_cscripts.sh
1001 1002 pyext/Makefile
1002 1003 pyext/setup.py
1003 1004 pyext/ctools/__init__.py
... ... @@ -1010,6 +1011,7 @@ AC_CONFIG_FILES([Makefile
1010 1011 testconf.sh],
1011 1012 [if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi;
1012 1013 if test -f test/test_python.sh; then chmod +x test/test_python.sh; fi;
  1014 + if test -f test/test_python_cscripts.sh; then chmod +x test/test_python_cscripts.sh; fi;
1013 1015 if test -f testconf.sh; then chmod +x testconf.sh; fi])
1014 1016 AC_OUTPUT
1015 1017  
... ...
cscripts/Makefile.am
... ... @@ -19,6 +19,17 @@ linkscripts = cspull cssens cstsdist cscaldb csresmap \
19 19 csobs2caldb \
20 20 csfindobs csiactcopy csiactdata csiactobs
21 21  
  22 +# Test scripts to be distributed in $(pyexecdir)/cscripts/tests
  23 +testscripts = tests/__init__.py \
  24 + ../test/test_python_cscripts.py \
  25 + ../test/test_cscaldb.py
  26 +
  27 +# Test data to be distributed in $(pyexecdir)/cscripts/tests/data
  28 +testdata =
  29 +
  30 +# Test IRFs to be distributed in $(pyexecdir)/cscripts/tests/irf
  31 +testirf =
  32 +
22 33 # Distribute scripts and parfiles
23 34 EXTRA_DIST = $(binscripts) $(pythonscripts)
24 35 binscriptsdir = $(bindir)
... ... @@ -27,6 +38,12 @@ pythonscriptsdir = $(pyexecdir)/cscripts
27 38 pythonscripts_DATA = $(pythonscripts)
28 39 pfilesdir = $(prefix)/syspfiles
29 40 pfiles_DATA = $(parfiles)
  41 +testscriptsdir = $(pyexecdir)/cscripts/tests
  42 +testscripts_DATA = $(testscripts)
  43 +testdatadir = $(pyexecdir)/cscripts/tests/data
  44 +testdata_DATA = $(testdata)
  45 +testirfdir = $(pyexecdir)/cscripts/tests/irf
  46 +testirf_DATA = $(testirf)
30 47  
31 48 # Add hook rule to create symbolic links for cscripts
32 49 install-data-hook:
... ...
cscripts/__init__.py.in
... ... @@ -39,8 +39,7 @@ __all__ = [
39 39 "cstsdist",
40 40 "cstsmapmerge",
41 41 "csfindobs",
42   - "obsutils",
43   - "test",
  42 + "obsutils"
44 43 ]
45 44 if cur_version > req_version:
46 45 __all__.extend(["csfindobs",
... ... @@ -80,7 +79,8 @@ def test():
80 79 """
81 80 Run cscripts tests.
82 81 """
83   - print("No cscripts unit tests have been implemented so far.")
  82 + from cscripts.tests import test_python_cscripts
  83 + test_python_cscripts.test(installed=True)
84 84  
85 85 # Add version
86 86 __version__ = '@PACKAGE_VERSION@'
87 87 \ No newline at end of file
... ...
cscripts/tests/__init__.py 0 → 100644
test/Makefile.am
... ... @@ -6,9 +6,10 @@ MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@
6 6  
7 7 # Optional python bindings
8 8 if WITH_PYTHON
9   - TEST_CSCRIPTS = test_cscripts.sh
10   - TEST_PYTHON_SCRIPT = test_python.sh
11   - TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH)
  9 + TEST_CSCRIPTS = test_cscripts.sh
  10 + TEST_PYTHON_CTOOLS = test_python.sh
  11 + TEST_PYTHON_CSCRIPTS = test_python_cscripts.sh
  12 + TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH)
12 13 endif
13 14  
14 15 # Set test environment
... ... @@ -18,7 +19,8 @@ TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(LIBDI
18 19 # Tests (these are the tests to be executed)
19 20 TESTS = test_ctools.sh \
20 21 $(TEST_CSCRIPTS) \
21   - $(TEST_PYTHON_SCRIPT)
  22 + $(TEST_PYTHON_CTOOLS) \
  23 + $(TEST_PYTHON_CSCRIPTS)
22 24  
23 25 # Add Valgrind rule
24 26 valgrind:
... ...
test/test_python.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for the ctools package.
4 4 #
5   -# Copyright (C) 2012-2015 Juergen Knoedlseder
  5 +# Copyright (C) 2012-2016 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -37,7 +37,6 @@ import test_ctcubemask
37 37 import test_ctbutterfly
38 38 import test_ctulimit
39 39 import test_cterror
40   -import test_cscaldb
41 40 import test_pipelines
42 41  
43 42  
... ... @@ -66,7 +65,6 @@ def test(installed=False):
66 65 suite_ctbutterfly = test_ctbutterfly.Test()
67 66 suite_ctulimit = test_ctulimit.Test()
68 67 suite_cterror = test_cterror.Test()
69   - suite_cscaldb = test_cscaldb.Test()
70 68 suite_pipelines = test_pipelines.Test()
71 69  
72 70 # Setup unit tests
... ... @@ -84,7 +82,6 @@ def test(installed=False):
84 82 suite_ctbutterfly.set()
85 83 suite_ctulimit.set()
86 84 suite_cterror.set()
87   - suite_cscaldb.set()
88 85 suite_pipelines.set()
89 86  
90 87 # Append tests to container
... ... @@ -102,7 +99,6 @@ def test(installed=False):
102 99 suites.append(suite_ctbutterfly)
103 100 suites.append(suite_ctulimit)
104 101 suites.append(suite_cterror)
105   - suites.append(suite_cscaldb)
106 102 suites.append(suite_pipelines)
107 103  
108 104 # If we have an installed version then create a temporary
... ... @@ -133,7 +129,6 @@ def test(installed=False):
133 129 # Copy over pfiles
134 130 if not installed:
135 131 os.system("cp -r ../src/*/*.par pfiles/")
136   - os.system("cp -r ../cscripts/*.par pfiles/")
137 132 else:
138 133 os.system("cp -r %s/syspfiles/*.par pfiles/" % (os.environ['CTOOLS']))
139 134  
... ...
test/test_python_cscripts.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for cscripts used from Python.
  4 +#
  5 +# Copyright (C) 2016 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import gammalib
  22 +import cscripts
  23 +import sys
  24 +import os
  25 +sys.path.append(os.path.dirname(os.path.abspath(__file__)))
  26 +import test_cscaldb
  27 +
  28 +
  29 +# ================== #
  30 +# Perform unit tests #
  31 +# ================== #
  32 +def test(installed=False):
  33 + """
  34 + Perform unit testing for Python interface.
  35 + """
  36 + # Allocate test suite container
  37 + suites = gammalib.GTestSuites("cscripts unit testing")
  38 +
  39 + # Allocate test suites and append them to the container
  40 + suite_cscaldb = test_cscaldb.Test()
  41 +
  42 + # Setup unit tests
  43 + suite_cscaldb.set()
  44 +
  45 + # Append tests to container
  46 + suites.append(suite_cscaldb)
  47 +
  48 + # If we have an installed version then create a temporary directory and
  49 + # copy over all information that is needed
  50 + if installed:
  51 +
  52 + # Create temporary working directory
  53 + import tempfile
  54 + path = tempfile.mkdtemp()
  55 + os.chdir(path)
  56 +
  57 + # Get test directory
  58 + import inspect
  59 + testdir = inspect.getfile(cscripts.tests)
  60 + dirname = os.path.dirname(testdir)
  61 +
  62 + # Copy over test data and irf
  63 + #os.system("cp -r %s %s" % (dirname+"/data", "data"))
  64 + #os.system("cp -r %s %s" % (dirname+"/irf", "irf"))
  65 +
  66 + # Set PFILES environment variable
  67 + try:
  68 + os.mkdir("pfiles")
  69 + except:
  70 + pass
  71 + os.environ['PFILES'] = "pfiles"
  72 +
  73 + # Copy over pfiles
  74 + if not installed:
  75 + os.system("cp -r ../cscripts/*.par pfiles/")
  76 + else:
  77 + os.system("cp -r %s/syspfiles/*.par pfiles/" % (os.environ['CTOOLS']))
  78 +
  79 + # Run test suite
  80 + success = suites.run()
  81 +
  82 + # If we have a non-installed version then save test results
  83 + if not installed:
  84 + suites.save("reports/cscripts.xml")
  85 +
  86 + # Set return code
  87 + if success:
  88 + rc = 0
  89 + else:
  90 + rc = 1
  91 +
  92 + # Exit with return code
  93 + sys.exit(rc)
  94 +
  95 +
  96 +# ======================== #
  97 +# Main routine entry point #
  98 +# ======================== #
  99 +if __name__ == '__main__':
  100 + """
  101 + Perform unit testing for cscripts used from Python.
  102 + """
  103 + # Run tests
  104 + test()
... ...
test/test_python_cscripts.sh.in 0 → 100755
  1 +#! /bin/sh
  2 +# ==========================================================================
  3 +# This script tests the cscripts Python module
  4 +#
  5 +# Copyright (C) 2016 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +
  22 +#
  23 +# Run the Python test
  24 +# ===================
  25 +@PYTHON_COVERAGE@./test_python_cscripts.py
... ...