diff --git a/test/test_pipelines.py b/test/test_pipelines.py index 2e50c1b..680eed5 100755 --- a/test/test_pipelines.py +++ b/test/test_pipelines.py @@ -1,8 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This scripts performs tests processing pipelines. +# This scripts performs tests processing pipelines # -# Copyright (C) 2014 Juergen Knoedlseder +# Copyright (C) 2014-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 @@ -72,27 +72,24 @@ class Test(gammalib.GPythonTestSuite): Test unbinned pipeline with FITS file saving """ # Set script parameters - model_name = self._model events_name = 'events.fits' selected_events_name = 'selected_events.fits' result_name = 'results.xml' - caldb = self._caldb - irf = self._irf ra = 83.63 dec = 22.01 rad_sim = 10.0 + rad_select = 3.0 tstart = 0.0 tstop = 1800.0 emin = 0.1 emax = 100.0 - rad_select = 3.0 # Simulate events sim = ctools.ctobssim() - sim['inmodel'] = model_name + sim['inmodel'] = self._model sim['outevents'] = events_name - sim['caldb'] = caldb - sim['irf'] = irf + sim['caldb'] = self._caldb + sim['irf'] = self._irf sim['ra'] = ra sim['dec'] = dec sim['rad'] = rad_sim @@ -118,10 +115,10 @@ class Test(gammalib.GPythonTestSuite): # Perform maximum likelihood fitting like = ctools.ctlike() like['inobs'] = selected_events_name - like['inmodel'] = model_name + like['inmodel'] = self._model like['outmodel'] = result_name - like['caldb'] = caldb - like['irf'] = irf + like['caldb'] = self._caldb + like['irf'] = self._irf like.execute() # Return @@ -133,23 +130,20 @@ class Test(gammalib.GPythonTestSuite): Test unbinned in-memory pipeline """ # Set script parameters - model_name = self._model - caldb = self._caldb - irf = self._irf ra = 83.63 dec = 22.01 rad_sim = 10.0 + rad_select = 3.0 tstart = 0.0 tstop = 1800.0 emin = 0.1 emax = 100.0 - rad_select = 3.0 # Simulate events sim = ctools.ctobssim() - sim['inmodel'] = model_name - sim['caldb'] = caldb - sim['irf'] = irf + sim['inmodel'] = self._model + sim['caldb'] = self._caldb + sim['irf'] = self._irf sim['ra'] = ra sim['dec'] = dec sim['rad'] = rad_sim diff --git a/test/test_python_cscripts.py b/test/test_python_cscripts.py index 9bb02ae..541dd22 100755 --- a/test/test_python_cscripts.py +++ b/test/test_python_cscripts.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # ========================================================================== -# This scripts performs unit tests for cscripts. +# This scripts performs unit tests for cscripts # # Copyright (C) 2016 Juergen Knoedlseder # @@ -74,7 +74,7 @@ def test(installed=False, debug=False): testdir = inspect.getfile(cscripts.tests) dirname = os.path.dirname(testdir) - # Copy over test data and irf + # Copy test data in "data" directory os.system('cp -r %s %s' % (dirname+'/data', 'data')) # Set test data environment variable @@ -86,14 +86,18 @@ def test(installed=False, debug=False): else: os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) - # Set PFILES environment variable + # Create a local "pfiles" directory and set PFILES environment variable try: os.mkdir('pfiles') except: pass os.environ['PFILES'] = 'pfiles' - # Copy over pfiles + # Copy the cscripts parameter files into the "pfiles" directory. For a + # non-installed test we copy the parameter files from the "cscripts" + # source directory into the "pfiles" directory, for an installed version + # we get all parameter files from the "syspfiles" directory. Also make + # sure that all parameter files are writable. if not installed: os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR'])) os.system('chmod u+w pfiles/*') @@ -162,16 +166,16 @@ def test(installed=False, debug=False): suites.append(suite_csworkflow) # Append tests for Python 2.6+ (the IACT cscripts depend on the json - # module which is only available since Python 2.6+ + # module which is only available since Python 2.6+) ver = sys.version.split()[0] if ver >= '2.6.0': # Check for VHEFITS environment variable if 'VHEFITS' in os.environ: - # If environment variable exists then unset for the test cases. - # Since Python is executed in a subprocess this will not impact - # the environment variable in the parent shell. + # If the environment variable exists then unset it for the test + # cases. Since Python is executed in a subprocess this will not + # impact the environment variable in the parent shell. del os.environ['VHEFITS'] # Allocate test suites diff --git a/test/test_python_ctools.py b/test/test_python_ctools.py index deec734..14372eb 100755 --- a/test/test_python_ctools.py +++ b/test/test_python_ctools.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # ========================================================================== -# This scripts performs unit tests for the ctools package. +# This scripts performs unit tests for the ctools package # # Copyright (C) 2012-2016 Juergen Knoedlseder # @@ -54,10 +54,51 @@ def test(installed=False): installed : bool, optional Flag indicating whether the script has been installed or not """ - # Set environment variables first + # If we have an installed version then create a temporary + # directory and copy over all information that is needed if installed: + + # Create temporary working directory + import tempfile + path = tempfile.mkdtemp() + os.chdir(path) + + # Get test directory + import inspect + testdir = inspect.getfile(ctools.tests) + dirname = os.path.dirname(testdir) + + # Copy test data in "data" directory + os.system('cp -r %s %s' % (dirname+'/data', 'data')) + + # Set test data environment variable os.environ['TEST_DATA'] = 'data' + # ... otherwise set the calibration database to the one shipped with the + # package; we don't need to set the 'TEST_DATA', this is done by the + # test environment + else: + os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) + + # Create a local "pfiles" directory and set PFILES environment variable + try: + os.mkdir('pfiles') + except: + pass + os.environ['PFILES'] = 'pfiles' + + # Copy the ctools parameter files into the "pfiles" directory. For a + # non-installed test we copy the parameter files from the respective + # source directories into the "pfiles" directory, for an installed version + # we get all parameter files from the "syspfiles" directory. Also make + # sure that all parameter files are writable. + if not installed: + os.system('cp -r %s/src/*/*.par pfiles/' % (os.environ['TEST_SRCDIR'])) + os.system('chmod u+w pfiles/*') + else: + os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) + os.system('chmod u+w pfiles/*') + # Allocate test suite container suites = gammalib.GTestSuites('ctools unit testing') @@ -118,42 +159,6 @@ def test(installed=False): suites.append(suite_cterror) suites.append(suite_pipelines) - # If we have an installed version then create a temporary - # directory and copy over all information that is needed - if installed: - - # Create temporary working directory - import tempfile - path = tempfile.mkdtemp() - os.chdir(path) - - # Get test directory - import inspect - testdir = inspect.getfile(ctools.tests) - dirname = os.path.dirname(testdir) - - # Copy over test data and irf - os.system('cp -r %s %s' % (dirname+'/data', 'data')) - - # ... otherwise set the calibration database - else: - os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR']) - - # Set PFILES environment variable - try: - os.mkdir('pfiles') - except: - pass - os.environ['PFILES'] = 'pfiles' - - # Copy over pfiles - if not installed: - os.system('cp -r %s/src/*/*.par pfiles/' % (os.environ['TEST_SRCDIR'])) - os.system('chmod u+w pfiles/*') - else: - os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) - os.system('chmod u+w pfiles/*') - # Run test suite success = suites.run()