Commit 9afc87bd1b3033a7c25f4fb804895b882347b511

Authored by Jürgen Knödlseder
1 parent adf6ef3a

Add comments

test/test_pipelines.py
1 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 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
... ... @@ -72,27 +72,24 @@ class Test(gammalib.GPythonTestSuite):
72 72 Test unbinned pipeline with FITS file saving
73 73 """
74 74 # Set script parameters
75   - model_name = self._model
76 75 events_name = 'events.fits'
77 76 selected_events_name = 'selected_events.fits'
78 77 result_name = 'results.xml'
79   - caldb = self._caldb
80   - irf = self._irf
81 78 ra = 83.63
82 79 dec = 22.01
83 80 rad_sim = 10.0
  81 + rad_select = 3.0
84 82 tstart = 0.0
85 83 tstop = 1800.0
86 84 emin = 0.1
87 85 emax = 100.0
88   - rad_select = 3.0
89 86  
90 87 # Simulate events
91 88 sim = ctools.ctobssim()
92   - sim['inmodel'] = model_name
  89 + sim['inmodel'] = self._model
93 90 sim['outevents'] = events_name
94   - sim['caldb'] = caldb
95   - sim['irf'] = irf
  91 + sim['caldb'] = self._caldb
  92 + sim['irf'] = self._irf
96 93 sim['ra'] = ra
97 94 sim['dec'] = dec
98 95 sim['rad'] = rad_sim
... ... @@ -118,10 +115,10 @@ class Test(gammalib.GPythonTestSuite):
118 115 # Perform maximum likelihood fitting
119 116 like = ctools.ctlike()
120 117 like['inobs'] = selected_events_name
121   - like['inmodel'] = model_name
  118 + like['inmodel'] = self._model
122 119 like['outmodel'] = result_name
123   - like['caldb'] = caldb
124   - like['irf'] = irf
  120 + like['caldb'] = self._caldb
  121 + like['irf'] = self._irf
125 122 like.execute()
126 123  
127 124 # Return
... ... @@ -133,23 +130,20 @@ class Test(gammalib.GPythonTestSuite):
133 130 Test unbinned in-memory pipeline
134 131 """
135 132 # Set script parameters
136   - model_name = self._model
137   - caldb = self._caldb
138   - irf = self._irf
139 133 ra = 83.63
140 134 dec = 22.01
141 135 rad_sim = 10.0
  136 + rad_select = 3.0
142 137 tstart = 0.0
143 138 tstop = 1800.0
144 139 emin = 0.1
145 140 emax = 100.0
146   - rad_select = 3.0
147 141  
148 142 # Simulate events
149 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 147 sim['ra'] = ra
154 148 sim['dec'] = dec
155 149 sim['rad'] = rad_sim
... ...
test/test_python_cscripts.py
1 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 5 # Copyright (C) 2016 Juergen Knoedlseder
6 6 #
... ... @@ -74,7 +74,7 @@ def test(installed=False, debug=False):
74 74 testdir = inspect.getfile(cscripts.tests)
75 75 dirname = os.path.dirname(testdir)
76 76  
77   - # Copy over test data and irf
  77 + # Copy test data in "data" directory
78 78 os.system('cp -r %s %s' % (dirname+'/data', 'data'))
79 79  
80 80 # Set test data environment variable
... ... @@ -86,14 +86,18 @@ def test(installed=False, debug=False):
86 86 else:
87 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 90 try:
91 91 os.mkdir('pfiles')
92 92 except:
93 93 pass
94 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 101 if not installed:
98 102 os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR']))
99 103 os.system('chmod u+w pfiles/*')
... ... @@ -162,16 +166,16 @@ def test(installed=False, debug=False):
162 166 suites.append(suite_csworkflow)
163 167  
164 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 170 ver = sys.version.split()[0]
167 171 if ver >= '2.6.0':
168 172  
169 173 # Check for VHEFITS environment variable
170 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 179 del os.environ['VHEFITS']
176 180  
177 181 # Allocate test suites
... ...
test/test_python_ctools.py
1 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 5 # Copyright (C) 2012-2016 Juergen Knoedlseder
6 6 #
... ... @@ -54,10 +54,51 @@ def test(installed=False):
54 54 installed : bool, optional
55 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 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 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 102 # Allocate test suite container
62 103 suites = gammalib.GTestSuites('ctools unit testing')
63 104  
... ... @@ -118,42 +159,6 @@ def test(installed=False):
118 159 suites.append(suite_cterror)
119 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 162 # Run test suite
158 163 success = suites.run()
159 164  
... ...