Commit 9afc87bd1b3033a7c25f4fb804895b882347b511
1 parent
adf6ef3a
Add comments
Showing
3 changed files
with
68 additions
and
65 deletions
test/test_pipelines.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This scripts performs tests processing pipelines. | 3 | +# This scripts performs tests processing pipelines |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 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 | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -72,27 +72,24 @@ class Test(gammalib.GPythonTestSuite): | @@ -72,27 +72,24 @@ class Test(gammalib.GPythonTestSuite): | ||
| 72 | Test unbinned pipeline with FITS file saving | 72 | Test unbinned pipeline with FITS file saving |
| 73 | """ | 73 | """ |
| 74 | # Set script parameters | 74 | # Set script parameters |
| 75 | - model_name = self._model | ||
| 76 | events_name = 'events.fits' | 75 | events_name = 'events.fits' |
| 77 | selected_events_name = 'selected_events.fits' | 76 | selected_events_name = 'selected_events.fits' |
| 78 | result_name = 'results.xml' | 77 | result_name = 'results.xml' |
| 79 | - caldb = self._caldb | ||
| 80 | - irf = self._irf | ||
| 81 | ra = 83.63 | 78 | ra = 83.63 |
| 82 | dec = 22.01 | 79 | dec = 22.01 |
| 83 | rad_sim = 10.0 | 80 | rad_sim = 10.0 |
| 81 | + rad_select = 3.0 | ||
| 84 | tstart = 0.0 | 82 | tstart = 0.0 |
| 85 | tstop = 1800.0 | 83 | tstop = 1800.0 |
| 86 | emin = 0.1 | 84 | emin = 0.1 |
| 87 | emax = 100.0 | 85 | emax = 100.0 |
| 88 | - rad_select = 3.0 | ||
| 89 | 86 | ||
| 90 | # Simulate events | 87 | # Simulate events |
| 91 | sim = ctools.ctobssim() | 88 | sim = ctools.ctobssim() |
| 92 | - sim['inmodel'] = model_name | 89 | + sim['inmodel'] = self._model |
| 93 | sim['outevents'] = events_name | 90 | sim['outevents'] = events_name |
| 94 | - sim['caldb'] = caldb | ||
| 95 | - sim['irf'] = irf | 91 | + sim['caldb'] = self._caldb |
| 92 | + sim['irf'] = self._irf | ||
| 96 | sim['ra'] = ra | 93 | sim['ra'] = ra |
| 97 | sim['dec'] = dec | 94 | sim['dec'] = dec |
| 98 | sim['rad'] = rad_sim | 95 | sim['rad'] = rad_sim |
| @@ -118,10 +115,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,10 +115,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Perform maximum likelihood fitting | 115 | # Perform maximum likelihood fitting |
| 119 | like = ctools.ctlike() | 116 | like = ctools.ctlike() |
| 120 | like['inobs'] = selected_events_name | 117 | like['inobs'] = selected_events_name |
| 121 | - like['inmodel'] = model_name | 118 | + like['inmodel'] = self._model |
| 122 | like['outmodel'] = result_name | 119 | like['outmodel'] = result_name |
| 123 | - like['caldb'] = caldb | ||
| 124 | - like['irf'] = irf | 120 | + like['caldb'] = self._caldb |
| 121 | + like['irf'] = self._irf | ||
| 125 | like.execute() | 122 | like.execute() |
| 126 | 123 | ||
| 127 | # Return | 124 | # Return |
| @@ -133,23 +130,20 @@ class Test(gammalib.GPythonTestSuite): | @@ -133,23 +130,20 @@ class Test(gammalib.GPythonTestSuite): | ||
| 133 | Test unbinned in-memory pipeline | 130 | Test unbinned in-memory pipeline |
| 134 | """ | 131 | """ |
| 135 | # Set script parameters | 132 | # Set script parameters |
| 136 | - model_name = self._model | ||
| 137 | - caldb = self._caldb | ||
| 138 | - irf = self._irf | ||
| 139 | ra = 83.63 | 133 | ra = 83.63 |
| 140 | dec = 22.01 | 134 | dec = 22.01 |
| 141 | rad_sim = 10.0 | 135 | rad_sim = 10.0 |
| 136 | + rad_select = 3.0 | ||
| 142 | tstart = 0.0 | 137 | tstart = 0.0 |
| 143 | tstop = 1800.0 | 138 | tstop = 1800.0 |
| 144 | emin = 0.1 | 139 | emin = 0.1 |
| 145 | emax = 100.0 | 140 | emax = 100.0 |
| 146 | - rad_select = 3.0 | ||
| 147 | 141 | ||
| 148 | # Simulate events | 142 | # Simulate events |
| 149 | sim = ctools.ctobssim() | 143 | sim = ctools.ctobssim() |
| 150 | - sim['inmodel'] = model_name | ||
| 151 | - sim['caldb'] = caldb | ||
| 152 | - sim['irf'] = irf | 144 | + sim['inmodel'] = self._model |
| 145 | + sim['caldb'] = self._caldb | ||
| 146 | + sim['irf'] = self._irf | ||
| 153 | sim['ra'] = ra | 147 | sim['ra'] = ra |
| 154 | sim['dec'] = dec | 148 | sim['dec'] = dec |
| 155 | sim['rad'] = rad_sim | 149 | sim['rad'] = rad_sim |
test/test_python_cscripts.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This scripts performs unit tests for cscripts. | 3 | +# This scripts performs unit tests for cscripts |
| 4 | # | 4 | # |
| 5 | # Copyright (C) 2016 Juergen Knoedlseder | 5 | # Copyright (C) 2016 Juergen Knoedlseder |
| 6 | # | 6 | # |
| @@ -74,7 +74,7 @@ def test(installed=False, debug=False): | @@ -74,7 +74,7 @@ def test(installed=False, debug=False): | ||
| 74 | testdir = inspect.getfile(cscripts.tests) | 74 | testdir = inspect.getfile(cscripts.tests) |
| 75 | dirname = os.path.dirname(testdir) | 75 | dirname = os.path.dirname(testdir) |
| 76 | 76 | ||
| 77 | - # Copy over test data and irf | 77 | + # Copy test data in "data" directory |
| 78 | os.system('cp -r %s %s' % (dirname+'/data', 'data')) | 78 | os.system('cp -r %s %s' % (dirname+'/data', 'data')) |
| 79 | 79 | ||
| 80 | # Set test data environment variable | 80 | # Set test data environment variable |
| @@ -86,14 +86,18 @@ def test(installed=False, debug=False): | @@ -86,14 +86,18 @@ def test(installed=False, debug=False): | ||
| 86 | else: | 86 | else: |
| 87 | os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) | 87 | os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) |
| 88 | 88 | ||
| 89 | - # Set PFILES environment variable | 89 | + # Create a local "pfiles" directory and set PFILES environment variable |
| 90 | try: | 90 | try: |
| 91 | os.mkdir('pfiles') | 91 | os.mkdir('pfiles') |
| 92 | except: | 92 | except: |
| 93 | pass | 93 | pass |
| 94 | os.environ['PFILES'] = 'pfiles' | 94 | os.environ['PFILES'] = 'pfiles' |
| 95 | 95 | ||
| 96 | - # Copy over pfiles | 96 | + # Copy the cscripts parameter files into the "pfiles" directory. For a |
| 97 | + # non-installed test we copy the parameter files from the "cscripts" | ||
| 98 | + # source directory into the "pfiles" directory, for an installed version | ||
| 99 | + # we get all parameter files from the "syspfiles" directory. Also make | ||
| 100 | + # sure that all parameter files are writable. | ||
| 97 | if not installed: | 101 | if not installed: |
| 98 | os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR'])) | 102 | os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR'])) |
| 99 | os.system('chmod u+w pfiles/*') | 103 | os.system('chmod u+w pfiles/*') |
| @@ -162,16 +166,16 @@ def test(installed=False, debug=False): | @@ -162,16 +166,16 @@ def test(installed=False, debug=False): | ||
| 162 | suites.append(suite_csworkflow) | 166 | suites.append(suite_csworkflow) |
| 163 | 167 | ||
| 164 | # Append tests for Python 2.6+ (the IACT cscripts depend on the json | 168 | # Append tests for Python 2.6+ (the IACT cscripts depend on the json |
| 165 | - # module which is only available since Python 2.6+ | 169 | + # module which is only available since Python 2.6+) |
| 166 | ver = sys.version.split()[0] | 170 | ver = sys.version.split()[0] |
| 167 | if ver >= '2.6.0': | 171 | if ver >= '2.6.0': |
| 168 | 172 | ||
| 169 | # Check for VHEFITS environment variable | 173 | # Check for VHEFITS environment variable |
| 170 | if 'VHEFITS' in os.environ: | 174 | if 'VHEFITS' in os.environ: |
| 171 | 175 | ||
| 172 | - # If environment variable exists then unset for the test cases. | ||
| 173 | - # Since Python is executed in a subprocess this will not impact | ||
| 174 | - # the environment variable in the parent shell. | 176 | + # If the environment variable exists then unset it for the test |
| 177 | + # cases. Since Python is executed in a subprocess this will not | ||
| 178 | + # impact the environment variable in the parent shell. | ||
| 175 | del os.environ['VHEFITS'] | 179 | del os.environ['VHEFITS'] |
| 176 | 180 | ||
| 177 | # Allocate test suites | 181 | # Allocate test suites |
test/test_python_ctools.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This scripts performs unit tests for the ctools package. | 3 | +# This scripts performs unit tests for the ctools package |
| 4 | # | 4 | # |
| 5 | # Copyright (C) 2012-2016 Juergen Knoedlseder | 5 | # Copyright (C) 2012-2016 Juergen Knoedlseder |
| 6 | # | 6 | # |
| @@ -54,10 +54,51 @@ def test(installed=False): | @@ -54,10 +54,51 @@ def test(installed=False): | ||
| 54 | installed : bool, optional | 54 | installed : bool, optional |
| 55 | Flag indicating whether the script has been installed or not | 55 | Flag indicating whether the script has been installed or not |
| 56 | """ | 56 | """ |
| 57 | - # Set environment variables first | 57 | + # If we have an installed version then create a temporary |
| 58 | + # directory and copy over all information that is needed | ||
| 58 | if installed: | 59 | if installed: |
| 60 | + | ||
| 61 | + # Create temporary working directory | ||
| 62 | + import tempfile | ||
| 63 | + path = tempfile.mkdtemp() | ||
| 64 | + os.chdir(path) | ||
| 65 | + | ||
| 66 | + # Get test directory | ||
| 67 | + import inspect | ||
| 68 | + testdir = inspect.getfile(ctools.tests) | ||
| 69 | + dirname = os.path.dirname(testdir) | ||
| 70 | + | ||
| 71 | + # Copy test data in "data" directory | ||
| 72 | + os.system('cp -r %s %s' % (dirname+'/data', 'data')) | ||
| 73 | + | ||
| 74 | + # Set test data environment variable | ||
| 59 | os.environ['TEST_DATA'] = 'data' | 75 | os.environ['TEST_DATA'] = 'data' |
| 60 | 76 | ||
| 77 | + # ... otherwise set the calibration database to the one shipped with the | ||
| 78 | + # package; we don't need to set the 'TEST_DATA', this is done by the | ||
| 79 | + # test environment | ||
| 80 | + else: | ||
| 81 | + os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) | ||
| 82 | + | ||
| 83 | + # Create a local "pfiles" directory and set PFILES environment variable | ||
| 84 | + try: | ||
| 85 | + os.mkdir('pfiles') | ||
| 86 | + except: | ||
| 87 | + pass | ||
| 88 | + os.environ['PFILES'] = 'pfiles' | ||
| 89 | + | ||
| 90 | + # Copy the ctools parameter files into the "pfiles" directory. For a | ||
| 91 | + # non-installed test we copy the parameter files from the respective | ||
| 92 | + # source directories into the "pfiles" directory, for an installed version | ||
| 93 | + # we get all parameter files from the "syspfiles" directory. Also make | ||
| 94 | + # sure that all parameter files are writable. | ||
| 95 | + if not installed: | ||
| 96 | + os.system('cp -r %s/src/*/*.par pfiles/' % (os.environ['TEST_SRCDIR'])) | ||
| 97 | + os.system('chmod u+w pfiles/*') | ||
| 98 | + else: | ||
| 99 | + os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) | ||
| 100 | + os.system('chmod u+w pfiles/*') | ||
| 101 | + | ||
| 61 | # Allocate test suite container | 102 | # Allocate test suite container |
| 62 | suites = gammalib.GTestSuites('ctools unit testing') | 103 | suites = gammalib.GTestSuites('ctools unit testing') |
| 63 | 104 | ||
| @@ -118,42 +159,6 @@ def test(installed=False): | @@ -118,42 +159,6 @@ def test(installed=False): | ||
| 118 | suites.append(suite_cterror) | 159 | suites.append(suite_cterror) |
| 119 | suites.append(suite_pipelines) | 160 | suites.append(suite_pipelines) |
| 120 | 161 | ||
| 121 | - # If we have an installed version then create a temporary | ||
| 122 | - # directory and copy over all information that is needed | ||
| 123 | - if installed: | ||
| 124 | - | ||
| 125 | - # Create temporary working directory | ||
| 126 | - import tempfile | ||
| 127 | - path = tempfile.mkdtemp() | ||
| 128 | - os.chdir(path) | ||
| 129 | - | ||
| 130 | - # Get test directory | ||
| 131 | - import inspect | ||
| 132 | - testdir = inspect.getfile(ctools.tests) | ||
| 133 | - dirname = os.path.dirname(testdir) | ||
| 134 | - | ||
| 135 | - # Copy over test data and irf | ||
| 136 | - os.system('cp -r %s %s' % (dirname+'/data', 'data')) | ||
| 137 | - | ||
| 138 | - # ... otherwise set the calibration database | ||
| 139 | - else: | ||
| 140 | - os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) | ||
| 141 | - | ||
| 142 | - # Set PFILES environment variable | ||
| 143 | - try: | ||
| 144 | - os.mkdir('pfiles') | ||
| 145 | - except: | ||
| 146 | - pass | ||
| 147 | - os.environ['PFILES'] = 'pfiles' | ||
| 148 | - | ||
| 149 | - # Copy over pfiles | ||
| 150 | - if not installed: | ||
| 151 | - os.system('cp -r %s/src/*/*.par pfiles/' % (os.environ['TEST_SRCDIR'])) | ||
| 152 | - os.system('chmod u+w pfiles/*') | ||
| 153 | - else: | ||
| 154 | - os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) | ||
| 155 | - os.system('chmod u+w pfiles/*') | ||
| 156 | - | ||
| 157 | # Run test suite | 162 | # Run test suite |
| 158 | success = suites.run() | 163 | success = suites.run() |
| 159 | 164 |