Commit b28ac8301f17e0cf3e8639c9a806a832eba31ebf
1 parent
42e375b0
Use testing.py base class for unit testing
Showing
38 changed files
with
987 additions
and
1329 deletions
cscripts/Makefile.am
| @@ -69,8 +69,8 @@ linkscripts = cscaldb \ | @@ -69,8 +69,8 @@ linkscripts = cscaldb \ | ||
| 69 | 69 | ||
| 70 | # Test scripts to be distributed in $(pyexecdir)/cscripts/tests | 70 | # Test scripts to be distributed in $(pyexecdir)/cscripts/tests |
| 71 | testscripts = tests/__init__.py \ | 71 | testscripts = tests/__init__.py \ |
| 72 | + ../test/testing.py \ | ||
| 72 | ../test/test_python_cscripts.py \ | 73 | ../test/test_python_cscripts.py \ |
| 73 | - ../test/test_cscripts_class.py \ | ||
| 74 | ../test/test_cscaldb.py \ | 74 | ../test/test_cscaldb.py \ |
| 75 | ../test/test_csmodelinfo.py \ | 75 | ../test/test_csmodelinfo.py \ |
| 76 | ../test/test_csmodelmerge.py \ | 76 | ../test/test_csmodelmerge.py \ |
pyext/Makefile.am
| @@ -31,6 +31,7 @@ if WITH_PYTHON | @@ -31,6 +31,7 @@ if WITH_PYTHON | ||
| 31 | 31 | ||
| 32 | # Test scripts to be distributed in $(pyexecdir)/ctools/tests | 32 | # Test scripts to be distributed in $(pyexecdir)/ctools/tests |
| 33 | testscripts = ctools/tests/__init__.py \ | 33 | testscripts = ctools/tests/__init__.py \ |
| 34 | + ../test/testing.py \ | ||
| 34 | ../test/test_python_ctools.py \ | 35 | ../test/test_python_ctools.py \ |
| 35 | ../test/test_ctobssim.py \ | 36 | ../test/test_ctobssim.py \ |
| 36 | ../test/test_ctselect.py \ | 37 | ../test/test_ctselect.py \ |
test/test_cscaldb.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +import test_cscripts_class | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================= # | 26 | # ============================= # |
| 27 | # Test class for cscaldb script # | 27 | # Test class for cscaldb script # |
| 28 | # ============================= # | 28 | # ============================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test_cscripts_class.cscripts_test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cscaldb script. | 31 | + Test class for cscaldb script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cslightcrv script by using it | 33 | This test class makes unit tests for the cslightcrv script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test_cscripts_class.cscripts_test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -65,24 +65,19 @@ class Test(gammalib.GPythonTestSuite): | @@ -65,24 +65,19 @@ class Test(gammalib.GPythonTestSuite): | ||
| 65 | """ | 65 | """ |
| 66 | Test cscaldb on the command line. | 66 | Test cscaldb on the command line. |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - cscaldb = '../cscripts/cscaldb.py' | ||
| 71 | - else: | ||
| 72 | - cscaldb = 'cscaldb' | 68 | + # Set script name |
| 69 | + cscaldb = self._script('cscaldb') | ||
| 73 | 70 | ||
| 74 | # Setup cscaldb command | 71 | # Setup cscaldb command |
| 75 | cmd = cscaldb+' logfile="cscaldb_cmd1.log" chatter=1' | 72 | cmd = cscaldb+' logfile="cscaldb_cmd1.log" chatter=1' |
| 76 | 73 | ||
| 77 | - # Execute cscaldb, make sure we catch any exception | ||
| 78 | - try: | ||
| 79 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 80 | - except: | ||
| 81 | - pass | 74 | + # Check if execution of wrong command fails |
| 75 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 76 | + 'Self test of test script') | ||
| 82 | 77 | ||
| 83 | # Check if execution was successful | 78 | # Check if execution was successful |
| 84 | - self.test_assert(rc == 0, | ||
| 85 | - 'Successful cscaldb execution on command line') | 79 | + self.test_assert(self._execute(cmd) == 0, |
| 80 | + 'Check successful execution from command line') | ||
| 86 | 81 | ||
| 87 | # Return | 82 | # Return |
| 88 | return | 83 | return |
| @@ -94,8 +89,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -94,8 +89,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 94 | """ | 89 | """ |
| 95 | # Set-up cscaldb | 90 | # Set-up cscaldb |
| 96 | caldb = cscripts.cscaldb() | 91 | caldb = cscripts.cscaldb() |
| 97 | - caldb['logfile'] = 'cscaldb_py1.log' | ||
| 98 | - caldb['chatter'] = 2 | 92 | + caldb['logfile'] = 'cscaldb_py1.log' |
| 93 | + caldb['chatter'] = 2 | ||
| 99 | 94 | ||
| 100 | # Run script | 95 | # Run script |
| 101 | caldb.logFileOpen() # Make sure we get a log file | 96 | caldb.logFileOpen() # Make sure we get a log file |
test/test_csfindobs.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | -# ================================ # | 26 | +# =============================== # |
| 27 | # Test class for csfindobs script # | 27 | # Test class for csfindobs script # |
| 28 | -# ================================ # | ||
| 29 | -class Test(gammalib.GPythonTestSuite): | 28 | +# =============================== # |
| 29 | +class Test(test): | ||
| 30 | """ | 30 | """ |
| 31 | - Test class for csfindobs script. | 31 | + Test class for csfindobs script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csfindobs script by using it | 33 | This test class makes unit tests for the csfindobs script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 65 | """ | 65 | """ |
| 66 | Test csfindobs on the command line. | 66 | Test csfindobs on the command line. |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - csfindobs = '../cscripts/csfindobs.py' | ||
| 71 | - else: | ||
| 72 | - csfindobs = 'csfindobs' | 68 | + # Set script name |
| 69 | + csfindobs = self._script('csfindobs') | ||
| 73 | 70 | ||
| 74 | # Setup csfindobs command | 71 | # Setup csfindobs command |
| 75 | cmd = csfindobs+' datapath="iactdata/"'+ \ | 72 | cmd = csfindobs+' datapath="iactdata/"'+ \ |
| @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 78 | ' outfile="runlist_cmd1.dat"'+ \ | 75 | ' outfile="runlist_cmd1.dat"'+ \ |
| 79 | ' logfile="csfindobs_cmd1.log" chatter=1' | 76 | ' logfile="csfindobs_cmd1.log" chatter=1' |
| 80 | 77 | ||
| 81 | - # Execute csfindobs, make sure we catch any exception | ||
| 82 | - try: | ||
| 83 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 84 | - except: | ||
| 85 | - pass | 78 | + # Check if execution of wrong command fails |
| 79 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 80 | + 'Self test of test script') | ||
| 86 | 81 | ||
| 87 | # Check if execution was successful | 82 | # Check if execution was successful |
| 88 | - self.test_assert(rc == 0, | ||
| 89 | - 'Successful csfindobs execution on command line') | 83 | + self.test_assert(self._execute(cmd) == 0, |
| 84 | + 'Check successful execution from command line') | ||
| 90 | 85 | ||
| 91 | # Check run list | 86 | # Check run list |
| 92 | self._check_runlist('runlist_cmd1.dat') | 87 | self._check_runlist('runlist_cmd1.dat') |
| @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 98 | ' outfile="runlist_cmd2.dat"'+ \ | 93 | ' outfile="runlist_cmd2.dat"'+ \ |
| 99 | ' logfile="csfindobs_cmd2.log"' | 94 | ' logfile="csfindobs_cmd2.log"' |
| 100 | 95 | ||
| 101 | - # Execute csfindobs, make sure we catch any exception | ||
| 102 | - try: | ||
| 103 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 104 | - except: | ||
| 105 | - pass | ||
| 106 | - | ||
| 107 | # Check if execution failed | 96 | # Check if execution failed |
| 108 | - self.test_assert(rc != 0, | ||
| 109 | - 'Failure of csfindobs execution on command line') | 97 | + self.test_assert(self._execute(cmd) != 0, |
| 98 | + 'Check invalid input file when executed from command line') | ||
| 110 | 99 | ||
| 111 | # Return | 100 | # Return |
| 112 | return | 101 | return |
test/test_csiactcopy.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================ # | 26 | # ================================ # |
| 27 | # Test class for csiactcopy script # | 27 | # Test class for csiactcopy script # |
| 28 | # ================================ # | 28 | # ================================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csiactcopy script. | 31 | + Test class for csiactcopy script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csiactcopy script by using it | 33 | This test class makes unit tests for the csiactcopy script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("csiactcopy") | 54 | + self.name('csiactcopy') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csiactcopy on command line") | ||
| 58 | - self.append(self._test_python, "Test csiactcopy from Python") | 57 | + self.append(self._test_cmd, 'Test csiactcopy on command line') |
| 58 | + self.append(self._test_python, 'Test csiactcopy from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csiactcopy on command line | 63 | # Test csiactcopy on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csiactcopy on the command line. | 66 | + Test csiactcopy on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - csiactcopy = "../cscripts/csiactcopy.py" | ||
| 71 | - else: | ||
| 72 | - csiactcopy = "csiactcopy" | 68 | + # Set script name |
| 69 | + csiactcopy = self._script('csiactcopy') | ||
| 73 | 70 | ||
| 74 | # Setup csiactcopy command | 71 | # Setup csiactcopy command |
| 75 | cmd = csiactcopy+' remote_master="iactdata/master.json"'+ \ | 72 | cmd = csiactcopy+' remote_master="iactdata/master.json"'+ \ |
| @@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 77 | ' outpath="iactdata_cmd1"'+ \ | 74 | ' outpath="iactdata_cmd1"'+ \ |
| 78 | ' logfile="csiactcopy_cmd1.log" chatter=1' | 75 | ' logfile="csiactcopy_cmd1.log" chatter=1' |
| 79 | 76 | ||
| 80 | - # Execute csiactcopy, make sure we catch any exception | ||
| 81 | - try: | ||
| 82 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 83 | - except: | ||
| 84 | - pass | 77 | + # Check if execution of wrong command fails |
| 78 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 79 | + 'Self test of test script') | ||
| 85 | 80 | ||
| 86 | # Check if execution was successful | 81 | # Check if execution was successful |
| 87 | - self.test_assert(rc == 0, | ||
| 88 | - "Successful csiactcopy execution on command line") | 82 | + self.test_assert(self._execute(cmd) == 0, |
| 83 | + 'Check successful execution from command line') | ||
| 89 | 84 | ||
| 90 | # Check copy | 85 | # Check copy |
| 91 | - self._check_copy("iactdata_cmd1") | 86 | + self._check_copy('iactdata_cmd1') |
| 92 | 87 | ||
| 93 | # Setup csiactcopy command | 88 | # Setup csiactcopy command |
| 94 | cmd = csiactcopy+' remote_master="master_that_does_not_exist"'+ \ | 89 | cmd = csiactcopy+' remote_master="master_that_does_not_exist"'+ \ |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' outpath="iactdata_test"'+ \ | 91 | ' outpath="iactdata_test"'+ \ |
| 97 | ' logfile="csiactcopy_cmd2.log"' | 92 | ' logfile="csiactcopy_cmd2.log"' |
| 98 | 93 | ||
| 99 | - # Execute csiactcopy, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - "Failure of csiactcopy execution on command line") | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,15 +101,15 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,15 +101,15 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test csiactcopy from Python | 101 | # Test csiactcopy from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test csiactcopy from Python. | 104 | + Test csiactcopy from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up csiactcopy | 106 | # Set-up csiactcopy |
| 118 | findobs = cscripts.csiactcopy() | 107 | findobs = cscripts.csiactcopy() |
| 119 | - findobs["remote_master"] = "iactdata/master.json" | ||
| 120 | - findobs["prodname"] = "unit-test" | ||
| 121 | - findobs["outpath"] = "iactdata_py1" | ||
| 122 | - findobs["logfile"] = "csiactcopy_py1.log" | ||
| 123 | - findobs["chatter"] = 2 | 108 | + findobs['remote_master'] = 'iactdata/master.json' |
| 109 | + findobs['prodname'] = 'unit-test' | ||
| 110 | + findobs['outpath'] = 'iactdata_py1' | ||
| 111 | + findobs['logfile'] = 'csiactcopy_py1.log' | ||
| 112 | + findobs['chatter'] = 2 | ||
| 124 | 113 | ||
| 125 | # Run csiactcopy script and save run list | 114 | # Run csiactcopy script and save run list |
| 126 | findobs.logFileOpen() # Make sure we get a log file | 115 | findobs.logFileOpen() # Make sure we get a log file |
| @@ -128,7 +117,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -128,7 +117,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 128 | findobs.save() | 117 | findobs.save() |
| 129 | 118 | ||
| 130 | # Check copy | 119 | # Check copy |
| 131 | - self._check_copy("iactdata_py1") | 120 | + self._check_copy('iactdata_py1') |
| 132 | 121 | ||
| 133 | # Return | 122 | # Return |
| 134 | return | 123 | return |
| @@ -139,9 +128,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -139,9 +128,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 139 | Check copy. | 128 | Check copy. |
| 140 | """ | 129 | """ |
| 141 | # Set file names | 130 | # Set file names |
| 142 | - hdu_index_name = gammalib.GFilename(pathname+"/hdu-index.fits") | ||
| 143 | - obs_index_name = gammalib.GFilename(pathname+"/obs-index.fits") | ||
| 144 | - master_name = gammalib.GFilename(pathname+"/master.json") | 131 | + hdu_index_name = gammalib.GFilename(pathname+'/hdu-index.fits') |
| 132 | + obs_index_name = gammalib.GFilename(pathname+'/obs-index.fits') | ||
| 133 | + master_name = gammalib.GFilename(pathname+'/master.json') | ||
| 145 | 134 | ||
| 146 | # Check for existence of files | 135 | # Check for existence of files |
| 147 | self.test_assert(hdu_index_name.exists(), | 136 | self.test_assert(hdu_index_name.exists(), |
test/test_csiactdata.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================ # | 26 | # ================================ # |
| 27 | # Test class for csiactdata script # | 27 | # Test class for csiactdata script # |
| 28 | # ================================ # | 28 | # ================================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csiactdata script. | 31 | + Test class for csiactdata script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csiactdata script by using it | 33 | This test class makes unit tests for the csiactdata script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("csiactdata") | 54 | + self.name('csiactdata') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csiactdata on command line") | ||
| 58 | - self.append(self._test_python, "Test csiactdata from Python") | 57 | + self.append(self._test_cmd, 'Test csiactdata on command line') |
| 58 | + self.append(self._test_python, 'Test csiactdata from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,41 +63,30 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,41 +63,30 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csiactdata on command line | 63 | # Test csiactdata on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csiactdata on the command line. | 66 | + Test csiactdata on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - csiactdata = "../cscripts/csiactdata.py" | ||
| 71 | - else: | ||
| 72 | - csiactdata = "csiactdata" | 68 | + # Set script name |
| 69 | + csiactdata = self._script('csiactdata') | ||
| 73 | 70 | ||
| 74 | # Setup csiactdata command | 71 | # Setup csiactdata command |
| 75 | cmd = csiactdata+' datapath="iactdata"'+ \ | 72 | cmd = csiactdata+' datapath="iactdata"'+ \ |
| 76 | ' logfile="csiactdata_cmd1.log" chatter=1' | 73 | ' logfile="csiactdata_cmd1.log" chatter=1' |
| 77 | 74 | ||
| 78 | - # Execute csiactdata, make sure we catch any exception | ||
| 79 | - try: | ||
| 80 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 81 | - except: | ||
| 82 | - pass | 75 | + # Check if execution of wrong command fails |
| 76 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 77 | + 'Self test of test script') | ||
| 83 | 78 | ||
| 84 | # Check if execution was successful | 79 | # Check if execution was successful |
| 85 | - self.test_assert(rc == 0, | ||
| 86 | - "Successful csiactdata execution on command line") | 80 | + self.test_assert(self._execute(cmd) == 0, |
| 81 | + 'Check successful execution from command line') | ||
| 87 | 82 | ||
| 88 | # Setup csiactdata command | 83 | # Setup csiactdata command |
| 89 | cmd = csiactdata+' datapath="data_path_that_does_not_exist"'+ \ | 84 | cmd = csiactdata+' datapath="data_path_that_does_not_exist"'+ \ |
| 90 | ' logfile="csiactdata_cmd2.log"' | 85 | ' logfile="csiactdata_cmd2.log"' |
| 91 | 86 | ||
| 92 | - # Execute csiactdata, make sure we catch any exception | ||
| 93 | - try: | ||
| 94 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 95 | - except: | ||
| 96 | - pass | ||
| 97 | - | ||
| 98 | # Check if execution failed | 87 | # Check if execution failed |
| 99 | - self.test_assert(rc != 0, | ||
| 100 | - "Failure of csiactdata execution on command line") | 88 | + self.test_assert(self._execute(cmd) != 0, |
| 89 | + 'Check invalid input file when executed from command line') | ||
| 101 | 90 | ||
| 102 | # Return | 91 | # Return |
| 103 | return | 92 | return |
| @@ -105,13 +94,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -105,13 +94,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 105 | # Test csiactdata from Python | 94 | # Test csiactdata from Python |
| 106 | def _test_python(self): | 95 | def _test_python(self): |
| 107 | """ | 96 | """ |
| 108 | - Test csiactdata from Python. | 97 | + Test csiactdata from Python |
| 109 | """ | 98 | """ |
| 110 | # Set-up csiactdata | 99 | # Set-up csiactdata |
| 111 | iactdata = cscripts.csiactdata() | 100 | iactdata = cscripts.csiactdata() |
| 112 | - iactdata["datapath"] = "iactdata" | ||
| 113 | - iactdata["logfile"] = "csiactdata_py1.log" | ||
| 114 | - iactdata["chatter"] = 2 | 101 | + iactdata['datapath'] = 'iactdata' |
| 102 | + iactdata['logfile'] = 'csiactdata_py1.log' | ||
| 103 | + iactdata['chatter'] = 2 | ||
| 115 | 104 | ||
| 116 | # Run csiactdata script and save run list | 105 | # Run csiactdata script and save run list |
| 117 | iactdata.logFileOpen() # Make sure we get a log file | 106 | iactdata.logFileOpen() # Make sure we get a log file |
test/test_csiactobs.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # =============================== # | 26 | # =============================== # |
| 27 | # Test class for csiactobs script # | 27 | # Test class for csiactobs script # |
| 28 | # =============================== # | 28 | # =============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csiactobs script. | 31 | + Test class for csiactobs script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csiactobs script by using it | 33 | This test class makes unit tests for the csiactobs script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("csiactobs") | 54 | + self.name('csiactobs') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csiactobs on command line") | ||
| 58 | - self.append(self._test_python, "Test csiactobs from Python") | 57 | + self.append(self._test_cmd, 'Test csiactobs on command line') |
| 58 | + self.append(self._test_python, 'Test csiactobs from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csiactobs on command line | 63 | # Test csiactobs on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csiactobs on the command line. | 66 | + Test csiactobs on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - csiactobs = "../cscripts/csiactobs.py" | ||
| 71 | - else: | ||
| 72 | - csiactobs = "csiactobs" | 68 | + # Set script name |
| 69 | + csiactobs = self._script('csiactobs') | ||
| 73 | 70 | ||
| 74 | # Setup csiactobs command | 71 | # Setup csiactobs command |
| 75 | cmd = csiactobs+' datapath="iactdata"'+ \ | 72 | cmd = csiactobs+' datapath="iactdata"'+ \ |
| @@ -80,21 +77,19 @@ class Test(gammalib.GPythonTestSuite): | @@ -80,21 +77,19 @@ class Test(gammalib.GPythonTestSuite): | ||
| 80 | ' outmodel="bgd_iactobs_cmd1.xml"'+ \ | 77 | ' outmodel="bgd_iactobs_cmd1.xml"'+ \ |
| 81 | ' logfile="csiactobs_cmd1.log" chatter=1' | 78 | ' logfile="csiactobs_cmd1.log" chatter=1' |
| 82 | 79 | ||
| 83 | - # Execute csiactobs, make sure we catch any exception | ||
| 84 | - try: | ||
| 85 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 86 | - except: | ||
| 87 | - pass | 80 | + # Check if execution of wrong command fails |
| 81 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 82 | + 'Self test of test script') | ||
| 88 | 83 | ||
| 89 | # Check if execution was successful | 84 | # Check if execution was successful |
| 90 | - self.test_assert(rc == 0, | ||
| 91 | - "Successful csiactobs execution on command line") | 85 | + self.test_assert(self._execute(cmd) == 0, |
| 86 | + 'Check successful execution from command line') | ||
| 92 | 87 | ||
| 93 | # Check observation definition XML file | 88 | # Check observation definition XML file |
| 94 | - self._check_obsdef("obs_iactobs_cmd1.xml") | 89 | + self._check_obsdef('obs_iactobs_cmd1.xml') |
| 95 | 90 | ||
| 96 | # Check model definition XML file | 91 | # Check model definition XML file |
| 97 | - self._check_moddef("bgd_iactobs_cmd1.xml") | 92 | + self._check_moddef('bgd_iactobs_cmd1.xml') |
| 98 | 93 | ||
| 99 | # Setup csiactobs command | 94 | # Setup csiactobs command |
| 100 | cmd = csiactobs+' datapath="data_path_that_does_not_exist"'+ \ | 95 | cmd = csiactobs+' datapath="data_path_that_does_not_exist"'+ \ |
| @@ -105,15 +100,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -105,15 +100,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 105 | ' outmodel="bgd_iactobs_cmd2.xml"'+ \ | 100 | ' outmodel="bgd_iactobs_cmd2.xml"'+ \ |
| 106 | ' logfile="csiactobs_cmd2.log" chatter=1' | 101 | ' logfile="csiactobs_cmd2.log" chatter=1' |
| 107 | 102 | ||
| 108 | - # Execute csiactobs, make sure we catch any exception | ||
| 109 | - try: | ||
| 110 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 111 | - except: | ||
| 112 | - pass | ||
| 113 | - | ||
| 114 | # Check if execution failed | 103 | # Check if execution failed |
| 115 | - self.test_assert(rc != 0, | ||
| 116 | - "Failure of csiactobs execution on command line") | 104 | + self.test_assert(self._execute(cmd) != 0, |
| 105 | + 'Check invalid input file when executed from command line') | ||
| 117 | 106 | ||
| 118 | # Return | 107 | # Return |
| 119 | return | 108 | return |
| @@ -121,18 +110,18 @@ class Test(gammalib.GPythonTestSuite): | @@ -121,18 +110,18 @@ class Test(gammalib.GPythonTestSuite): | ||
| 121 | # Test csiactobs from Python | 110 | # Test csiactobs from Python |
| 122 | def _test_python(self): | 111 | def _test_python(self): |
| 123 | """ | 112 | """ |
| 124 | - Test csiactobs from Python. | 113 | + Test csiactobs from Python |
| 125 | """ | 114 | """ |
| 126 | # Set-up csiactobs | 115 | # Set-up csiactobs |
| 127 | iactobs = cscripts.csiactobs() | 116 | iactobs = cscripts.csiactobs() |
| 128 | - iactobs["datapath"] = "iactdata" | ||
| 129 | - iactobs["prodname"] = "unit-test" | ||
| 130 | - iactobs["infile"] = "runlist_py1.dat" | ||
| 131 | - iactobs["bkgpars"] = 1 | ||
| 132 | - iactobs["outobs"] = "obs_iactobs_py1.xml" | ||
| 133 | - iactobs["outmodel"] = "bgd_iactobs_py1.xml" | ||
| 134 | - iactobs["logfile"] = "csiactobs_py1.log" | ||
| 135 | - iactobs["chatter"] = 2 | 117 | + iactobs['datapath'] = 'iactdata' |
| 118 | + iactobs['prodname'] = 'unit-test' | ||
| 119 | + iactobs['infile'] = 'runlist_py1.dat' | ||
| 120 | + iactobs['bkgpars'] = 1 | ||
| 121 | + iactobs['outobs'] = 'obs_iactobs_py1.xml' | ||
| 122 | + iactobs['outmodel'] = 'bgd_iactobs_py1.xml' | ||
| 123 | + iactobs['logfile'] = 'csiactobs_py1.log' | ||
| 124 | + iactobs['chatter'] = 2 | ||
| 136 | 125 | ||
| 137 | # Run csiactobs script and save run list | 126 | # Run csiactobs script and save run list |
| 138 | iactobs.logFileOpen() # Make sure we get a log file | 127 | iactobs.logFileOpen() # Make sure we get a log file |
| @@ -140,10 +129,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -140,10 +129,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 140 | iactobs.save() | 129 | iactobs.save() |
| 141 | 130 | ||
| 142 | # Check observation definition XML file | 131 | # Check observation definition XML file |
| 143 | - self._check_obsdef("obs_iactobs_py1.xml") | 132 | + self._check_obsdef('obs_iactobs_py1.xml') |
| 144 | 133 | ||
| 145 | # Check model definition XML file | 134 | # Check model definition XML file |
| 146 | - self._check_moddef("bgd_iactobs_py1.xml") | 135 | + self._check_moddef('bgd_iactobs_py1.xml') |
| 147 | 136 | ||
| 148 | # Return | 137 | # Return |
| 149 | return | 138 | return |
| @@ -151,7 +140,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -151,7 +140,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 151 | # Check observation definition XML file | 140 | # Check observation definition XML file |
| 152 | def _check_obsdef(self, filename): | 141 | def _check_obsdef(self, filename): |
| 153 | """ | 142 | """ |
| 154 | - Check observation definition XML file. | 143 | + Check observation definition XML file |
| 155 | """ | 144 | """ |
| 156 | # Load observation definition XML file | 145 | # Load observation definition XML file |
| 157 | obs = gammalib.GObservations(filename) | 146 | obs = gammalib.GObservations(filename) |
| @@ -197,7 +186,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -197,7 +186,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 197 | # Check model XML file | 186 | # Check model XML file |
| 198 | def _check_moddef(self, filename): | 187 | def _check_moddef(self, filename): |
| 199 | """ | 188 | """ |
| 200 | - Check model definition XML file. | 189 | + Check model definition XML file |
| 201 | """ | 190 | """ |
| 202 | # Load model definition XML file | 191 | # Load model definition XML file |
| 203 | models = gammalib.GModels(filename) | 192 | models = gammalib.GModels(filename) |
test/test_cslightcrv.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================ # | 26 | # ================================ # |
| 27 | # Test class for cslightcrv script # | 27 | # Test class for cslightcrv script # |
| 28 | # ================================ # | 28 | # ================================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cslightcrv script. | 31 | + Test class for cslightcrv script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cslightcrv script by using it | 33 | This test class makes unit tests for the cslightcrv script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Set members | 45 | # Set members |
| 46 | self._events_name = 'data/crab_events.fits' | 46 | self._events_name = 'data/crab_events.fits' |
| @@ -69,11 +69,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,11 +69,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | """ | 69 | """ |
| 70 | Test cslightcrv on the command line. | 70 | Test cslightcrv on the command line. |
| 71 | """ | 71 | """ |
| 72 | - # Kluge to set the command (installed version has no README file) | ||
| 73 | - if os.path.isfile('README.md'): | ||
| 74 | - cslightcrv = '../cscripts/cslightcrv.py' | ||
| 75 | - else: | ||
| 76 | - cslightcrv = 'cslightcrv' | 72 | + # Set script name |
| 73 | + cslightcrv = self._script('cslightcrv') | ||
| 77 | 74 | ||
| 78 | # Setup cslightcrv command | 75 | # Setup cslightcrv command |
| 79 | cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \ | 76 | cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \ |
| @@ -84,15 +81,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -84,15 +81,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 84 | ' outfile="lightcurve_cmd1.fits"'+ \ | 81 | ' outfile="lightcurve_cmd1.fits"'+ \ |
| 85 | ' logfile="cslightcrv_cmd1.log" chatter=1' | 82 | ' logfile="cslightcrv_cmd1.log" chatter=1' |
| 86 | 83 | ||
| 87 | - # Execute cslightcrv, make sure we catch any exception | ||
| 88 | - try: | ||
| 89 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 90 | - except: | ||
| 91 | - pass | 84 | + # Check if execution of wrong command fails |
| 85 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 86 | + 'Self test of test script') | ||
| 92 | 87 | ||
| 93 | # Check if execution was successful | 88 | # Check if execution was successful |
| 94 | - self.test_assert(rc == 0, | ||
| 95 | - 'Successful cslightcrv execution on command line') | 89 | + self.test_assert(self._execute(cmd) == 0, |
| 90 | + 'Check successful execution from command line') | ||
| 96 | 91 | ||
| 97 | # Check light curve | 92 | # Check light curve |
| 98 | self._check_light_curve('lightcurve_cmd1.fits', 3) | 93 | self._check_light_curve('lightcurve_cmd1.fits', 3) |
| @@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 106 | ' outfile="lightcurve_cmd1.fits"'+ \ | 101 | ' outfile="lightcurve_cmd1.fits"'+ \ |
| 107 | ' logfile="cslightcrv_cmd2.log"' | 102 | ' logfile="cslightcrv_cmd2.log"' |
| 108 | 103 | ||
| 109 | - # Execute cslightcrv, make sure we catch any exception | ||
| 110 | - try: | ||
| 111 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 112 | - except: | ||
| 113 | - pass | ||
| 114 | - | ||
| 115 | # Check if execution failed | 104 | # Check if execution failed |
| 116 | - self.test_assert(rc != 0, | ||
| 117 | - 'Failure of cslightcrv execution on command line') | 105 | + self.test_assert(self._execute(cmd) != 0, |
| 106 | + 'Check invalid input file when executed from command line') | ||
| 118 | 107 | ||
| 119 | # Return | 108 | # Return |
| 120 | return | 109 | return |
| @@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 122 | # Test cslightcrv from Python | 111 | # Test cslightcrv from Python |
| 123 | def _test_python(self): | 112 | def _test_python(self): |
| 124 | """ | 113 | """ |
| 125 | - Test cslightcrv from Python. | 114 | + Test cslightcrv from Python |
| 126 | """ | 115 | """ |
| 127 | # Set-up unbinned cslightcrv | 116 | # Set-up unbinned cslightcrv |
| 128 | lcrv = cscripts.cslightcrv() | 117 | lcrv = cscripts.cslightcrv() |
| @@ -249,7 +238,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -249,7 +238,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 249 | # Check light curve result file | 238 | # Check light curve result file |
| 250 | def _check_light_curve(self, filename, bins): | 239 | def _check_light_curve(self, filename, bins): |
| 251 | """ | 240 | """ |
| 252 | - Check light curve file. | 241 | + Check light curve file |
| 253 | """ | 242 | """ |
| 254 | # Expected column names | 243 | # Expected column names |
| 255 | cols = ['MJD', 'e_MJD', 'Prefactor', 'e_Prefactor', | 244 | cols = ['MJD', 'e_MJD', 'Prefactor', 'e_Prefactor', |
test/test_csmodelinfo.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================= # | 26 | # ================================= # |
| 27 | # Test class for csmodelinfo script # | 27 | # Test class for csmodelinfo script # |
| 28 | # ================================= # | 28 | # ================================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csmodelinfo script. | 31 | + Test class for csmodelinfo script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csmodelinfo script by using it | 33 | This test class makes unit tests for the csmodelinfo script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Set members | 45 | # Set members |
| 46 | self._model_name = "data/crab.xml" | 46 | self._model_name = "data/crab.xml" |
| @@ -54,11 +54,11 @@ class Test(gammalib.GPythonTestSuite): | @@ -54,11 +54,11 @@ class Test(gammalib.GPythonTestSuite): | ||
| 54 | Set all test functions. | 54 | Set all test functions. |
| 55 | """ | 55 | """ |
| 56 | # Set test name | 56 | # Set test name |
| 57 | - self.name("csmodelinfo") | 57 | + self.name('csmodelinfo') |
| 58 | 58 | ||
| 59 | # Append tests | 59 | # Append tests |
| 60 | - self.append(self._test_cmd, "Test csmodelinfo on command line") | ||
| 61 | - self.append(self._test_python, "Test csmodelinfo from Python") | 60 | + self.append(self._test_cmd, 'Test csmodelinfo on command line') |
| 61 | + self.append(self._test_python, 'Test csmodelinfo from Python') | ||
| 62 | 62 | ||
| 63 | # Return | 63 | # Return |
| 64 | return | 64 | return |
| @@ -66,46 +66,35 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,46 +66,35 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | # Test csmodelinfo on command line | 66 | # Test csmodelinfo on command line |
| 67 | def _test_cmd(self): | 67 | def _test_cmd(self): |
| 68 | """ | 68 | """ |
| 69 | - Test csmodelinfo on the command line. | 69 | + Test csmodelinfo on the command line |
| 70 | """ | 70 | """ |
| 71 | - # Kluge to set the command (installed version has no README file) | ||
| 72 | - if os.path.isfile("README.md"): | ||
| 73 | - csmodelinfo = "../cscripts/csmodelinfo.py" | ||
| 74 | - else: | ||
| 75 | - csmodelinfo = "csmodelinfo" | 71 | + # Set script name |
| 72 | + csmodelinfo = self._script('csmodelinfo') | ||
| 76 | 73 | ||
| 77 | # Setup csmodelinfo command | 74 | # Setup csmodelinfo command |
| 78 | cmd = csmodelinfo+' inmodel="'+self._model_name+'"'+ \ | 75 | cmd = csmodelinfo+' inmodel="'+self._model_name+'"'+ \ |
| 79 | ' ds9file="model_cmd1.reg"'+ \ | 76 | ' ds9file="model_cmd1.reg"'+ \ |
| 80 | ' logfile="csmodelinfo_cmd1.log" chatter=1' | 77 | ' logfile="csmodelinfo_cmd1.log" chatter=1' |
| 81 | 78 | ||
| 82 | - # Execute csmodelinfo, make sure we catch any exception | ||
| 83 | - try: | ||
| 84 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 85 | - except: | ||
| 86 | - pass | 79 | + # Check if execution of wrong command fails |
| 80 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 81 | + 'Self test of test script') | ||
| 87 | 82 | ||
| 88 | # Check if execution was successful | 83 | # Check if execution was successful |
| 89 | - self.test_assert(rc == 0, | ||
| 90 | - "Successful csmodelinfo execution on command line") | 84 | + self.test_assert(self._execute(cmd) == 0, |
| 85 | + 'Check successful execution from command line') | ||
| 91 | 86 | ||
| 92 | # Check region file | 87 | # Check region file |
| 93 | - self._check_ds9_file("model_cmd1.reg") | 88 | + self._check_ds9_file('model_cmd1.reg') |
| 94 | 89 | ||
| 95 | # Setup csmodelinfo command | 90 | # Setup csmodelinfo command |
| 96 | cmd = csmodelinfo+' inmodel="model_that_does_not_exist.xml"'+ \ | 91 | cmd = csmodelinfo+' inmodel="model_that_does_not_exist.xml"'+ \ |
| 97 | ' ds9file="model_cmd2.reg"'+ \ | 92 | ' ds9file="model_cmd2.reg"'+ \ |
| 98 | ' logfile="csmodelinfo_cmd2.log"' | 93 | ' logfile="csmodelinfo_cmd2.log"' |
| 99 | 94 | ||
| 100 | - # Execute csmodelinfo, make sure we catch any exception | ||
| 101 | - try: | ||
| 102 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 103 | - except: | ||
| 104 | - pass | ||
| 105 | - | ||
| 106 | # Check if execution failed | 95 | # Check if execution failed |
| 107 | - self.test_assert(rc != 0, | ||
| 108 | - "Failure of csmodelinfo execution on command line") | 96 | + self.test_assert(self._execute(cmd) != 0, |
| 97 | + 'Check invalid input file when executed from command line') | ||
| 109 | 98 | ||
| 110 | # Return | 99 | # Return |
| 111 | return | 100 | return |
| @@ -113,14 +102,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -113,14 +102,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 113 | # Test csmodelinfo from Python | 102 | # Test csmodelinfo from Python |
| 114 | def _test_python(self): | 103 | def _test_python(self): |
| 115 | """ | 104 | """ |
| 116 | - Test csmodelinfo from Python. | 105 | + Test csmodelinfo from Python |
| 117 | """ | 106 | """ |
| 118 | # Set-up csmodelinfo | 107 | # Set-up csmodelinfo |
| 119 | modelinfo = cscripts.csmodelinfo() | 108 | modelinfo = cscripts.csmodelinfo() |
| 120 | - modelinfo["inmodel"] = self._model_name | ||
| 121 | - modelinfo["ds9file"] = "csmodelinfo_py1.reg" | ||
| 122 | - modelinfo["logfile"] = "csmodelinfo_py1.log" | ||
| 123 | - modelinfo["chatter"] = 2 | 109 | + modelinfo['inmodel'] = self._model_name |
| 110 | + modelinfo['ds9file'] = 'csmodelinfo_py1.reg' | ||
| 111 | + modelinfo['logfile'] = 'csmodelinfo_py1.log' | ||
| 112 | + modelinfo['chatter'] = 2 | ||
| 124 | 113 | ||
| 125 | # Run csmodelinfo script and save DS9 file | 114 | # Run csmodelinfo script and save DS9 file |
| 126 | modelinfo.logFileOpen() # Make sure we get a log file | 115 | modelinfo.logFileOpen() # Make sure we get a log file |
| @@ -128,20 +117,20 @@ class Test(gammalib.GPythonTestSuite): | @@ -128,20 +117,20 @@ class Test(gammalib.GPythonTestSuite): | ||
| 128 | modelinfo.save() | 117 | modelinfo.save() |
| 129 | 118 | ||
| 130 | # Check region file | 119 | # Check region file |
| 131 | - self._check_ds9_file("csmodelinfo_py1.reg") | 120 | + self._check_ds9_file('csmodelinfo_py1.reg') |
| 132 | 121 | ||
| 133 | # Set-up csmodelinfo | 122 | # Set-up csmodelinfo |
| 134 | modelinfo = cscripts.csmodelinfo() | 123 | modelinfo = cscripts.csmodelinfo() |
| 135 | - modelinfo["inmodel"] = self._model_name | ||
| 136 | - modelinfo["ds9file"] = "csmodelinfo_py2.reg" | ||
| 137 | - modelinfo["logfile"] = "csmodelinfo_py2.log" | ||
| 138 | - modelinfo["chatter"] = 3 | 124 | + modelinfo['inmodel'] = self._model_name |
| 125 | + modelinfo['ds9file'] = 'csmodelinfo_py2.reg' | ||
| 126 | + modelinfo['logfile'] = 'csmodelinfo_py2.log' | ||
| 127 | + modelinfo['chatter'] = 3 | ||
| 139 | 128 | ||
| 140 | # Execute csmodelinfo script | 129 | # Execute csmodelinfo script |
| 141 | modelinfo.execute() | 130 | modelinfo.execute() |
| 142 | 131 | ||
| 143 | # Check region file | 132 | # Check region file |
| 144 | - self._check_ds9_file("csmodelinfo_py2.reg") | 133 | + self._check_ds9_file('csmodelinfo_py2.reg') |
| 145 | 134 | ||
| 146 | # Return | 135 | # Return |
| 147 | return | 136 | return |
| @@ -149,10 +138,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -149,10 +138,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 149 | # Check region file | 138 | # Check region file |
| 150 | def _check_ds9_file(self, filename): | 139 | def _check_ds9_file(self, filename): |
| 151 | """ | 140 | """ |
| 152 | - Check region file. | 141 | + Check region file |
| 153 | """ | 142 | """ |
| 154 | # Open file | 143 | # Open file |
| 155 | - f = open(filename,"r") | 144 | + f = open(filename,'r') |
| 156 | 145 | ||
| 157 | # Expect "fk5" in first line | 146 | # Expect "fk5" in first line |
| 158 | line = f.readline().strip('\n') | 147 | line = f.readline().strip('\n') |
test/test_csmodelmerge.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================== # | 26 | # ================================== # |
| 27 | # Test class for csmodelmerge script # | 27 | # Test class for csmodelmerge script # |
| 28 | # ================================== # | 28 | # ================================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csmodelmerge script. | 31 | + Test class for csmodelmerge script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csmodelmerge script by using it | 33 | This test class makes unit tests for the csmodelmerge script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -51,11 +51,11 @@ class Test(gammalib.GPythonTestSuite): | @@ -51,11 +51,11 @@ class Test(gammalib.GPythonTestSuite): | ||
| 51 | Set all test functions. | 51 | Set all test functions. |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("csmodelmerge") | 54 | + self.name('csmodelmerge') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csmodelmerge on command line") | ||
| 58 | - self.append(self._test_python, "Test csmodelmerge from Python") | 57 | + self.append(self._test_cmd, 'Test csmodelmerge on command line') |
| 58 | + self.append(self._test_python, 'Test csmodelmerge from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,46 +63,35 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,46 +63,35 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csmodelmerge on command line | 63 | # Test csmodelmerge on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csmodelmerge on the command line. | 66 | + Test csmodelmerge on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - csmodelmerge = "../cscripts/csmodelmerge.py" | ||
| 71 | - else: | ||
| 72 | - csmodelmerge = "csmodelmerge" | 68 | + # Set script name |
| 69 | + csmodelmerge = self._script('csmodelmerge') | ||
| 73 | 70 | ||
| 74 | # Setup csmodelmerge command | 71 | # Setup csmodelmerge command |
| 75 | cmd = csmodelmerge+' inmodels="data/crab.xml data/model_cube_background.xml"'+ \ | 72 | cmd = csmodelmerge+' inmodels="data/crab.xml data/model_cube_background.xml"'+ \ |
| 76 | ' outmodel="mergedmodel_cmd1.xml"'+ \ | 73 | ' outmodel="mergedmodel_cmd1.xml"'+ \ |
| 77 | ' logfile="csmodelmerge_cmd1.log" chatter=1' | 74 | ' logfile="csmodelmerge_cmd1.log" chatter=1' |
| 78 | 75 | ||
| 79 | - # Execute csmodelmerge, make sure we catch any exception | ||
| 80 | - try: | ||
| 81 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 82 | - except: | ||
| 83 | - pass | 76 | + # Check if execution of wrong command fails |
| 77 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 78 | + 'Self test of test script') | ||
| 84 | 79 | ||
| 85 | # Check if execution was successful | 80 | # Check if execution was successful |
| 86 | - self.test_assert(rc == 0, | ||
| 87 | - "Successful csmodelmerge execution on command line") | 81 | + self.test_assert(self._execute(cmd) == 0, |
| 82 | + 'Check successful execution from command line') | ||
| 88 | 83 | ||
| 89 | # Check model file | 84 | # Check model file |
| 90 | - self._check_model_file("mergedmodel_cmd1.xml", 3) | 85 | + self._check_model_file('mergedmodel_cmd1.xml', 3) |
| 91 | 86 | ||
| 92 | # Setup csmodelmerge command | 87 | # Setup csmodelmerge command |
| 93 | cmd = csmodelmerge+' inmodels="model_that_does_not_exist.xml"'+ \ | 88 | cmd = csmodelmerge+' inmodels="model_that_does_not_exist.xml"'+ \ |
| 94 | ' outmodel="mergedmodel_cmd2.xml"'+ \ | 89 | ' outmodel="mergedmodel_cmd2.xml"'+ \ |
| 95 | ' logfile="csmodelmerge_cmd2.log"' | 90 | ' logfile="csmodelmerge_cmd2.log"' |
| 96 | 91 | ||
| 97 | - # Execute csmodelmerge, make sure we catch any exception | ||
| 98 | - try: | ||
| 99 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 100 | - except: | ||
| 101 | - pass | ||
| 102 | - | ||
| 103 | # Check if execution failed | 92 | # Check if execution failed |
| 104 | - self.test_assert(rc != 0, | ||
| 105 | - "Failure of csmodelmerge execution on command line") | 93 | + self.test_assert(self._execute(cmd) != 0, |
| 94 | + 'Check invalid input file when executed from command line') | ||
| 106 | 95 | ||
| 107 | # Return | 96 | # Return |
| 108 | return | 97 | return |
| @@ -110,14 +99,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -110,14 +99,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 110 | # Test csmodelmerge from Python | 99 | # Test csmodelmerge from Python |
| 111 | def _test_python(self): | 100 | def _test_python(self): |
| 112 | """ | 101 | """ |
| 113 | - Test csmodelmerge from Python. | 102 | + Test csmodelmerge from Python |
| 114 | """ | 103 | """ |
| 115 | # Set-up csmodelmerge for space-separated input | 104 | # Set-up csmodelmerge for space-separated input |
| 116 | modelmerge = cscripts.csmodelmerge() | 105 | modelmerge = cscripts.csmodelmerge() |
| 117 | - modelmerge["inmodels"] = "data/crab.xml data/model_cube_background.xml" | ||
| 118 | - modelmerge["outmodel"] = "mergedmodel_py1.xml" | ||
| 119 | - modelmerge["logfile"] = "csmodelmerge_py1.log" | ||
| 120 | - modelmerge["chatter"] = 2 | 106 | + modelmerge['inmodels'] = 'data/crab.xml data/model_cube_background.xml' |
| 107 | + modelmerge['outmodel'] = 'mergedmodel_py1.xml' | ||
| 108 | + modelmerge['logfile'] = 'csmodelmerge_py1.log' | ||
| 109 | + modelmerge['chatter'] = 2 | ||
| 121 | 110 | ||
| 122 | # Run csmodelmerge script and save models | 111 | # Run csmodelmerge script and save models |
| 123 | modelmerge.logFileOpen() # Make sure we get a log file | 112 | modelmerge.logFileOpen() # Make sure we get a log file |
| @@ -125,46 +114,46 @@ class Test(gammalib.GPythonTestSuite): | @@ -125,46 +114,46 @@ class Test(gammalib.GPythonTestSuite): | ||
| 125 | modelmerge.save() | 114 | modelmerge.save() |
| 126 | 115 | ||
| 127 | # Check model file | 116 | # Check model file |
| 128 | - self._check_model_file("mergedmodel_py1.xml", 3) | 117 | + self._check_model_file('mergedmodel_py1.xml', 3) |
| 129 | 118 | ||
| 130 | # Set-up csmodelmerge for semi-colon separated input | 119 | # Set-up csmodelmerge for semi-colon separated input |
| 131 | modelmerge = cscripts.csmodelmerge() | 120 | modelmerge = cscripts.csmodelmerge() |
| 132 | - modelmerge["inmodels"] = "data/crab.xml;data/model_cube_background.xml" | ||
| 133 | - modelmerge["outmodel"] = "mergedmodel_py2.xml" | ||
| 134 | - modelmerge["logfile"] = "csmodelmerge_py2.log" | ||
| 135 | - modelmerge["chatter"] = 3 | 121 | + modelmerge['inmodels'] = 'data/crab.xml;data/model_cube_background.xml' |
| 122 | + modelmerge['outmodel'] = 'mergedmodel_py2.xml' | ||
| 123 | + modelmerge['logfile'] = 'csmodelmerge_py2.log' | ||
| 124 | + modelmerge['chatter'] = 3 | ||
| 136 | 125 | ||
| 137 | # Execute csmodelmerge script | 126 | # Execute csmodelmerge script |
| 138 | modelmerge.execute() | 127 | modelmerge.execute() |
| 139 | 128 | ||
| 140 | # Check model file | 129 | # Check model file |
| 141 | - self._check_model_file("mergedmodel_py2.xml", 3) | 130 | + self._check_model_file('mergedmodel_py2.xml', 3) |
| 142 | 131 | ||
| 143 | # Set-up csmodelmerge for wildcard input | 132 | # Set-up csmodelmerge for wildcard input |
| 144 | modelmerge = cscripts.csmodelmerge() | 133 | modelmerge = cscripts.csmodelmerge() |
| 145 | - modelmerge["inmodels"] = "data/model_cube_background*.xml" | ||
| 146 | - modelmerge["outmodel"] = "mergedmodel_py3.xml" | ||
| 147 | - modelmerge["logfile"] = "csmodelmerge_py3.log" | ||
| 148 | - modelmerge["chatter"] = 4 | 134 | + modelmerge['inmodels'] = 'data/model_cube_background*.xml' |
| 135 | + modelmerge['outmodel'] = 'mergedmodel_py3.xml' | ||
| 136 | + modelmerge['logfile'] = 'csmodelmerge_py3.log' | ||
| 137 | + modelmerge['chatter'] = 4 | ||
| 149 | 138 | ||
| 150 | # Execute csmodelmerge script | 139 | # Execute csmodelmerge script |
| 151 | modelmerge.execute() | 140 | modelmerge.execute() |
| 152 | 141 | ||
| 153 | # Check model file | 142 | # Check model file |
| 154 | - self._check_model_file("mergedmodel_py3.xml", 2) | 143 | + self._check_model_file('mergedmodel_py3.xml', 2) |
| 155 | 144 | ||
| 156 | # Set-up csmodelmerge for ASCII file | 145 | # Set-up csmodelmerge for ASCII file |
| 157 | modelmerge = cscripts.csmodelmerge() | 146 | modelmerge = cscripts.csmodelmerge() |
| 158 | - modelmerge["inmodels"] = "@data/models.txt" | ||
| 159 | - modelmerge["outmodel"] = "mergedmodel_py4.xml" | ||
| 160 | - modelmerge["logfile"] = "csmodelmerge_py4.log" | ||
| 161 | - modelmerge["chatter"] = 4 | 147 | + modelmerge['inmodels'] = '@data/models.txt' |
| 148 | + modelmerge['outmodel'] = 'mergedmodel_py4.xml' | ||
| 149 | + modelmerge['logfile'] = 'csmodelmerge_py4.log' | ||
| 150 | + modelmerge['chatter'] = 4 | ||
| 162 | 151 | ||
| 163 | # Execute csmodelmerge script | 152 | # Execute csmodelmerge script |
| 164 | modelmerge.execute() | 153 | modelmerge.execute() |
| 165 | 154 | ||
| 166 | # Check model file | 155 | # Check model file |
| 167 | - self._check_model_file("mergedmodel_py4.xml", 2) | 156 | + self._check_model_file('mergedmodel_py4.xml', 2) |
| 168 | 157 | ||
| 169 | # Return | 158 | # Return |
| 170 | return | 159 | return |
| @@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 172 | # Check model file | 161 | # Check model file |
| 173 | def _check_model_file(self, filename, number): | 162 | def _check_model_file(self, filename, number): |
| 174 | """ | 163 | """ |
| 175 | - Check model file. | 164 | + Check model file |
| 176 | """ | 165 | """ |
| 177 | # Open models | 166 | # Open models |
| 178 | models = gammalib.GModels(filename) | 167 | models = gammalib.GModels(filename) |
test/test_csobs2caldb.py
| @@ -21,14 +21,15 @@ | @@ -21,14 +21,15 @@ | ||
| 21 | import os | 21 | import os |
| 22 | import gammalib | 22 | import gammalib |
| 23 | import cscripts | 23 | import cscripts |
| 24 | +from testing import test | ||
| 24 | 25 | ||
| 25 | 26 | ||
| 26 | # ================================= # | 27 | # ================================= # |
| 27 | # Test class for csobs2caldb script # | 28 | # Test class for csobs2caldb script # |
| 28 | # ================================= # | 29 | # ================================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 30 | +class Test(test): |
| 30 | """ | 31 | """ |
| 31 | - Test class for csobs2caldb script. | 32 | + Test class for csobs2caldb script |
| 32 | 33 | ||
| 33 | This test class makes unit tests for the csobs2caldb script by using it | 34 | This test class makes unit tests for the csobs2caldb script by using it |
| 34 | from the command line and from Python. | 35 | from the command line and from Python. |
| @@ -37,17 +38,17 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,17 +38,17 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 38 | # Constructor |
| 38 | def __init__(self): | 39 | def __init__(self): |
| 39 | """ | 40 | """ |
| 40 | - Constructor. | 41 | + Constructor |
| 41 | """ | 42 | """ |
| 42 | # Call base class constructor | 43 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 44 | + test.__init__(self) |
| 44 | 45 | ||
| 45 | # Set members | 46 | # Set members |
| 46 | - self._inobs = "data/obs_unbinned.xml" | 47 | + self._inobs = 'data/obs_unbinned.xml' |
| 47 | 48 | ||
| 48 | # Clean calibration database | 49 | # Clean calibration database |
| 49 | - os.system("rm -rf caldb >/dev/null 2>&1") | ||
| 50 | - os.system("mkdir -p caldb >/dev/null 2>&1") | 50 | + os.system('rm -rf caldb >/dev/null 2>&1') |
| 51 | + os.system('mkdir -p caldb >/dev/null 2>&1') | ||
| 51 | 52 | ||
| 52 | # Return | 53 | # Return |
| 53 | return | 54 | return |
| @@ -55,14 +56,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -55,14 +56,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 55 | # Set test functions | 56 | # Set test functions |
| 56 | def set(self): | 57 | def set(self): |
| 57 | """ | 58 | """ |
| 58 | - Set all test functions. | 59 | + Set all test functions |
| 59 | """ | 60 | """ |
| 60 | # Set test name | 61 | # Set test name |
| 61 | - self.name("csobs2caldb") | 62 | + self.name('csobs2caldb') |
| 62 | 63 | ||
| 63 | # Append tests | 64 | # Append tests |
| 64 | - self.append(self._test_cmd, "Test csobs2caldb on command line") | ||
| 65 | - self.append(self._test_python, "Test csobs2caldb from Python") | 65 | + self.append(self._test_cmd, 'Test csobs2caldb on command line') |
| 66 | + self.append(self._test_python, 'Test csobs2caldb from Python') | ||
| 66 | 67 | ||
| 67 | # Return | 68 | # Return |
| 68 | return | 69 | return |
| @@ -70,46 +71,35 @@ class Test(gammalib.GPythonTestSuite): | @@ -70,46 +71,35 @@ class Test(gammalib.GPythonTestSuite): | ||
| 70 | # Test csobs2caldb on command line | 71 | # Test csobs2caldb on command line |
| 71 | def _test_cmd(self): | 72 | def _test_cmd(self): |
| 72 | """ | 73 | """ |
| 73 | - Test csobs2caldb on the command line. | 74 | + Test csobs2caldb on the command line |
| 74 | """ | 75 | """ |
| 75 | - # Kluge to set the command (installed version has no README file) | ||
| 76 | - if os.path.isfile("README.md"): | ||
| 77 | - csobs2caldb = "../cscripts/csobs2caldb.py" | ||
| 78 | - else: | ||
| 79 | - csobs2caldb = "csobs2caldb" | 76 | + # Set script name |
| 77 | + csobs2caldb = self._script('csobs2caldb') | ||
| 80 | 78 | ||
| 81 | # Setup csobs2caldb command | 79 | # Setup csobs2caldb command |
| 82 | cmd = csobs2caldb+' inobs="'+self._inobs+'"'+ \ | 80 | cmd = csobs2caldb+' inobs="'+self._inobs+'"'+ \ |
| 83 | ' caldb="cta" irf="Cmd1" rootdir="caldb"'+ \ | 81 | ' caldb="cta" irf="Cmd1" rootdir="caldb"'+ \ |
| 84 | ' logfile="csobs2caldb_cmd1.log" chatter=1' | 82 | ' logfile="csobs2caldb_cmd1.log" chatter=1' |
| 85 | 83 | ||
| 86 | - # Execute csobs2caldb, make sure we catch any exception | ||
| 87 | - try: | ||
| 88 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 89 | - except: | ||
| 90 | - pass | 84 | + # Check if execution of wrong command fails |
| 85 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 86 | + 'Self test of test script') | ||
| 91 | 87 | ||
| 92 | # Check if execution was successful | 88 | # Check if execution was successful |
| 93 | - self.test_assert(rc == 0, | ||
| 94 | - "Successful csobs2caldb execution on command line") | 89 | + self.test_assert(self._execute(cmd) == 0, |
| 90 | + 'Check successful execution from command line') | ||
| 95 | 91 | ||
| 96 | # Check response | 92 | # Check response |
| 97 | - self._check_response("cta", "Cmd1") | 93 | + self._check_response('cta', 'Cmd1') |
| 98 | 94 | ||
| 99 | # Setup csobs2caldb command | 95 | # Setup csobs2caldb command |
| 100 | cmd = csobs2caldb+' inobs="xml_file_that_does_not_exist.xml"'+ \ | 96 | cmd = csobs2caldb+' inobs="xml_file_that_does_not_exist.xml"'+ \ |
| 101 | ' caldb="cta" irf="Cmd2" rootdir="caldb"'+ \ | 97 | ' caldb="cta" irf="Cmd2" rootdir="caldb"'+ \ |
| 102 | ' logfile="csobs2caldb_cmd2.log"' | 98 | ' logfile="csobs2caldb_cmd2.log"' |
| 103 | 99 | ||
| 104 | - # Execute csobs2caldb, make sure we catch any exception | ||
| 105 | - try: | ||
| 106 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 107 | - except: | ||
| 108 | - pass | ||
| 109 | - | ||
| 110 | # Check if execution failed | 100 | # Check if execution failed |
| 111 | - self.test_assert(rc != 0, | ||
| 112 | - "Failure of csobs2caldb execution on command line") | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 113 | 103 | ||
| 114 | # Return | 104 | # Return |
| 115 | return | 105 | return |
| @@ -117,16 +107,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -117,16 +107,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 117 | # Test csobs2caldb from Python | 107 | # Test csobs2caldb from Python |
| 118 | def _test_python(self): | 108 | def _test_python(self): |
| 119 | """ | 109 | """ |
| 120 | - Test csobs2caldb from Python. | 110 | + Test csobs2caldb from Python |
| 121 | """ | 111 | """ |
| 122 | # Set-up csobs2caldb using "inobs" parameter | 112 | # Set-up csobs2caldb using "inobs" parameter |
| 123 | irf = cscripts.csobs2caldb() | 113 | irf = cscripts.csobs2caldb() |
| 124 | - irf["inobs"] = self._inobs | ||
| 125 | - irf["caldb"] = "cta" | ||
| 126 | - irf["irf"] = "Py1" | ||
| 127 | - irf["rootdir"] = "caldb" | ||
| 128 | - irf["logfile"] = "csobs2caldb_py1.log" | ||
| 129 | - irf["chatter"] = 2 | 114 | + irf['inobs'] = self._inobs |
| 115 | + irf['caldb'] = 'cta' | ||
| 116 | + irf['irf'] = 'Py1' | ||
| 117 | + irf['rootdir'] = 'caldb' | ||
| 118 | + irf['logfile'] = 'csobs2caldb_py1.log' | ||
| 119 | + irf['chatter'] = 2 | ||
| 130 | 120 | ||
| 131 | # Run csobs2caldb script and save IRF | 121 | # Run csobs2caldb script and save IRF |
| 132 | irf.logFileOpen() # Make sure we get a log file | 122 | irf.logFileOpen() # Make sure we get a log file |
| @@ -134,24 +124,24 @@ class Test(gammalib.GPythonTestSuite): | @@ -134,24 +124,24 @@ class Test(gammalib.GPythonTestSuite): | ||
| 134 | irf.save() | 124 | irf.save() |
| 135 | 125 | ||
| 136 | # Check response | 126 | # Check response |
| 137 | - self._check_response("cta", "Py1") | 127 | + self._check_response('cta', 'Py1') |
| 138 | 128 | ||
| 139 | # Load observation container | 129 | # Load observation container |
| 140 | obs = gammalib.GObservations(self._inobs) | 130 | obs = gammalib.GObservations(self._inobs) |
| 141 | 131 | ||
| 142 | # Set-up csobs2caldb using observation container | 132 | # Set-up csobs2caldb using observation container |
| 143 | irf = cscripts.csobs2caldb(obs) | 133 | irf = cscripts.csobs2caldb(obs) |
| 144 | - irf["caldb"] = "cta" | ||
| 145 | - irf["irf"] = "Py2" | ||
| 146 | - irf["rootdir"] = "caldb" | ||
| 147 | - irf["logfile"] = "csobs2caldb_py2.log" | ||
| 148 | - irf["chatter"] = 3 | 134 | + irf['caldb'] = 'cta' |
| 135 | + irf['irf'] = 'Py2' | ||
| 136 | + irf['rootdir'] = 'caldb' | ||
| 137 | + irf['logfile'] = 'csobs2caldb_py2.log' | ||
| 138 | + irf['chatter'] = 3 | ||
| 149 | 139 | ||
| 150 | # Execute csobs2caldb script | 140 | # Execute csobs2caldb script |
| 151 | irf.execute() | 141 | irf.execute() |
| 152 | 142 | ||
| 153 | # Check response | 143 | # Check response |
| 154 | - self._check_response("cta", "Py2") | 144 | + self._check_response('cta', 'Py2') |
| 155 | 145 | ||
| 156 | # Return | 146 | # Return |
| 157 | return | 147 | return |
| @@ -159,24 +149,24 @@ class Test(gammalib.GPythonTestSuite): | @@ -159,24 +149,24 @@ class Test(gammalib.GPythonTestSuite): | ||
| 159 | # Check response | 149 | # Check response |
| 160 | def _check_response(self, caldb, irf): | 150 | def _check_response(self, caldb, irf): |
| 161 | """ | 151 | """ |
| 162 | - Check response. | 152 | + Check response |
| 163 | """ | 153 | """ |
| 164 | # Open calibration database | 154 | # Open calibration database |
| 165 | - db = gammalib.GCaldb("caldb") | ||
| 166 | - db.open("cta", caldb) | 155 | + db = gammalib.GCaldb('caldb') |
| 156 | + db.open('cta', caldb) | ||
| 167 | 157 | ||
| 168 | # Get filenames of response components | 158 | # Get filenames of response components |
| 169 | - expr = "NAME("+irf+")" | ||
| 170 | - aeff = gammalib.GFilename(db.filename("","","EFF_AREA","","",expr)) | ||
| 171 | - psf = gammalib.GFilename(db.filename("","","RPSF","","",expr)) | ||
| 172 | - edisp = gammalib.GFilename(db.filename("","","EDISP","","",expr)) | ||
| 173 | - bgd = gammalib.GFilename(db.filename("","","BGD","","",expr)) | 159 | + expr = 'NAME('+irf+')' |
| 160 | + aeff = gammalib.GFilename(db.filename('','','EFF_AREA','','',expr)) | ||
| 161 | + psf = gammalib.GFilename(db.filename('','','RPSF','','',expr)) | ||
| 162 | + edisp = gammalib.GFilename(db.filename('','','EDISP','','',expr)) | ||
| 163 | + bgd = gammalib.GFilename(db.filename('','','BGD','','',expr)) | ||
| 174 | 164 | ||
| 175 | # Check whether files exist | 165 | # Check whether files exist |
| 176 | - self.test_assert(aeff.exists(), "Effective area file exists") | ||
| 177 | - self.test_assert(psf.exists(), "Point spread function file exists") | ||
| 178 | - self.test_assert(edisp.exists(), "Energy dispersion file exists") | ||
| 179 | - self.test_assert(bgd.exists(), "Background file exists") | 166 | + self.test_assert(aeff.exists(), 'Effective area file exists') |
| 167 | + self.test_assert(psf.exists(), 'Point spread function file exists') | ||
| 168 | + self.test_assert(edisp.exists(), 'Energy dispersion file exists') | ||
| 169 | + self.test_assert(bgd.exists(), 'Background file exists') | ||
| 180 | 170 | ||
| 181 | # Return | 171 | # Return |
| 182 | return | 172 | return |
test/test_csobsdef.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================== # | 26 | # ============================== # |
| 27 | # Test class for csobsdef script # | 27 | # Test class for csobsdef script # |
| 28 | # ============================== # | 28 | # ============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csobsdef script. | 31 | + Test class for csobsdef script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csobsdef script by using it | 33 | This test class makes unit tests for the csobsdef script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('csobsdef') | 54 | self.name('csobsdef') |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csobsdef on command line | 63 | # Test csobsdef on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csobsdef on the command line. | 66 | + Test csobsdef on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - csobsdef = '../cscripts/csobsdef.py' | ||
| 71 | - else: | ||
| 72 | - csobsdef = 'csobsdef' | 68 | + # Set script name |
| 69 | + csobsdef = self._script('csobsdef') | ||
| 73 | 70 | ||
| 74 | # Setup csobsdef command | 71 | # Setup csobsdef command |
| 75 | cmd = csobsdef+' inpnt="data/pntdef.dat"'+ \ | 72 | cmd = csobsdef+' inpnt="data/pntdef.dat"'+ \ |
| @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 78 | ' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \ | 75 | ' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \ |
| 79 | ' logfile="csobsdef_cmd1.log" chatter=1' | 76 | ' logfile="csobsdef_cmd1.log" chatter=1' |
| 80 | 77 | ||
| 81 | - # Execute csobsdef, make sure we catch any exception | ||
| 82 | - try: | ||
| 83 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 84 | - except: | ||
| 85 | - pass | 78 | + # Check if execution of wrong command fails |
| 79 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 80 | + 'Self test of test script') | ||
| 86 | 81 | ||
| 87 | # Check if execution was successful | 82 | # Check if execution was successful |
| 88 | - self.test_assert(rc == 0, | ||
| 89 | - 'Successful csobsdef execution on command line') | 83 | + self.test_assert(self._execute(cmd) == 0, |
| 84 | + 'Check successful execution from command line') | ||
| 90 | 85 | ||
| 91 | # Check observation definition file | 86 | # Check observation definition file |
| 92 | self._check_obsdef_file('csobsdef_cmd1.xml') | 87 | self._check_obsdef_file('csobsdef_cmd1.xml') |
| @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 98 | ' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \ | 93 | ' emin=0.1 emax=100.0 duration=1800.0 rad=5.0'+ \ |
| 99 | ' logfile="csobsdef_cmd2.log"' | 94 | ' logfile="csobsdef_cmd2.log"' |
| 100 | 95 | ||
| 101 | - # Execute csobsdef, make sure we catch any exception | ||
| 102 | - try: | ||
| 103 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 104 | - except: | ||
| 105 | - pass | ||
| 106 | - | ||
| 107 | # Check if execution failed | 96 | # Check if execution failed |
| 108 | - self.test_assert(rc != 0, | ||
| 109 | - 'Failure of csobsdef execution on command line') | 97 | + self.test_assert(self._execute(cmd) != 0, |
| 98 | + 'Check invalid input file when executed from command line') | ||
| 110 | 99 | ||
| 111 | # Return | 100 | # Return |
| 112 | return | 101 | return |
| @@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 114 | # Test csobsdef from Python | 103 | # Test csobsdef from Python |
| 115 | def _test_python(self): | 104 | def _test_python(self): |
| 116 | """ | 105 | """ |
| 117 | - Test csobsdef from Python. | 106 | + Test csobsdef from Python |
| 118 | """ | 107 | """ |
| 119 | # Set-up csobsdef | 108 | # Set-up csobsdef |
| 120 | obsdef = cscripts.csobsdef() | 109 | obsdef = cscripts.csobsdef() |
| @@ -184,7 +173,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -184,7 +173,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 184 | # Check observation definition file | 173 | # Check observation definition file |
| 185 | def _check_obsdef_file(self, filename): | 174 | def _check_obsdef_file(self, filename): |
| 186 | """ | 175 | """ |
| 187 | - Check observation definition file. | 176 | + Check observation definition file |
| 188 | """ | 177 | """ |
| 189 | # Load observation definition file | 178 | # Load observation definition file |
| 190 | obs = gammalib.GObservations(filename) | 179 | obs = gammalib.GObservations(filename) |
test/test_csobsinfo.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # =============================== # | 26 | # =============================== # |
| 27 | # Test class for csobsinfo script # | 27 | # Test class for csobsinfo script # |
| 28 | # =============================== # | 28 | # =============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csobsinfo script. | 31 | + Test class for csobsinfo script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csobsinfo script by using it | 33 | This test class makes unit tests for the csobsinfo script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("csobsinfo") | 54 | + self.name('csobsinfo') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csobsinfo on command line") | ||
| 58 | - self.append(self._test_python, "Test csobsinfo from Python") | 57 | + self.append(self._test_cmd, 'Test csobsinfo on command line') |
| 58 | + self.append(self._test_python, 'Test csobsinfo from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csobsinfo on command line | 63 | # Test csobsinfo on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csobsinfo on the command line. | 66 | + Test csobsinfo on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - csobsinfo = "../cscripts/csobsinfo.py" | ||
| 71 | - else: | ||
| 72 | - csobsinfo = "csobsinfo" | 68 | + # Set script name |
| 69 | + csobsinfo = self._script('csobsinfo') | ||
| 73 | 70 | ||
| 74 | # Setup csobsinfo command | 71 | # Setup csobsinfo command |
| 75 | cmd = csobsinfo+' inobs="data/obs_unbinned.xml"'+ \ | 72 | cmd = csobsinfo+' inobs="data/obs_unbinned.xml"'+ \ |
| @@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -77,18 +74,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 77 | ' offset=yes ra=83.63 dec=22.01'+ \ | 74 | ' offset=yes ra=83.63 dec=22.01'+ \ |
| 78 | ' logfile="csobsinfo_cmd1.log" chatter=1' | 75 | ' logfile="csobsinfo_cmd1.log" chatter=1' |
| 79 | 76 | ||
| 80 | - # Execute csobsinfo, make sure we catch any exception | ||
| 81 | - try: | ||
| 82 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 83 | - except: | ||
| 84 | - pass | 77 | + # Check if execution of wrong command fails |
| 78 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 79 | + 'Self test of test script') | ||
| 85 | 80 | ||
| 86 | # Check if execution was successful | 81 | # Check if execution was successful |
| 87 | - self.test_assert(rc == 0, | ||
| 88 | - "Successful csobsinfo execution on command line") | 82 | + self.test_assert(self._execute(cmd) == 0, |
| 83 | + 'Check successful execution from command line') | ||
| 89 | 84 | ||
| 90 | # Check DS9 file | 85 | # Check DS9 file |
| 91 | - self._check_ds9_file("csobsinfo_cmd1.reg") | 86 | + self._check_ds9_file('csobsinfo_cmd1.reg') |
| 92 | 87 | ||
| 93 | # Setup csobsinfo command | 88 | # Setup csobsinfo command |
| 94 | cmd = csobsinfo+' inobs="obs_definition_that_does_not_exist.xml"'+ \ | 89 | cmd = csobsinfo+' inobs="obs_definition_that_does_not_exist.xml"'+ \ |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' offset=yes ra=83.63 dec=22.01'+ \ | 91 | ' offset=yes ra=83.63 dec=22.01'+ \ |
| 97 | ' logfile="csobsinfo_cmd2.log"' | 92 | ' logfile="csobsinfo_cmd2.log"' |
| 98 | 93 | ||
| 99 | - # Execute csobsinfo, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - "Failure of csobsinfo execution on command line") | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,17 +101,17 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,17 +101,17 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test csobsinfo from Python | 101 | # Test csobsinfo from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test csobsinfo from Python. | 104 | + Test csobsinfo from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up csobsinfo | 106 | # Set-up csobsinfo |
| 118 | obsinfo = cscripts.csobsinfo() | 107 | obsinfo = cscripts.csobsinfo() |
| 119 | - obsinfo["inobs"] = "data/obs_unbinned.xml" | ||
| 120 | - obsinfo["ds9file"] = "csobsinfo_py1.reg" | ||
| 121 | - obsinfo["offset"] = True | ||
| 122 | - obsinfo["ra"] = 83.63 | ||
| 123 | - obsinfo["dec"] = 22.01 | ||
| 124 | - obsinfo["logfile"] = "csobsinfo_py1.log" | ||
| 125 | - obsinfo["chatter"] = 2 | 108 | + obsinfo['inobs'] = 'data/obs_unbinned.xml' |
| 109 | + obsinfo['ds9file'] = 'csobsinfo_py1.reg' | ||
| 110 | + obsinfo['offset'] = True | ||
| 111 | + obsinfo['ra'] = 83.63 | ||
| 112 | + obsinfo['dec'] = 22.01 | ||
| 113 | + obsinfo['logfile'] = 'csobsinfo_py1.log' | ||
| 114 | + obsinfo['chatter'] = 2 | ||
| 126 | 115 | ||
| 127 | # Run csobsinfo script and save XML file | 116 | # Run csobsinfo script and save XML file |
| 128 | obsinfo.logFileOpen() # Make sure we get a log file | 117 | obsinfo.logFileOpen() # Make sure we get a log file |
| @@ -130,23 +119,23 @@ class Test(gammalib.GPythonTestSuite): | @@ -130,23 +119,23 @@ class Test(gammalib.GPythonTestSuite): | ||
| 130 | obsinfo.save() | 119 | obsinfo.save() |
| 131 | 120 | ||
| 132 | # Check DS9 file | 121 | # Check DS9 file |
| 133 | - self._check_ds9_file("csobsinfo_py1.reg") | 122 | + self._check_ds9_file('csobsinfo_py1.reg') |
| 134 | 123 | ||
| 135 | # Set-up csobsinfo | 124 | # Set-up csobsinfo |
| 136 | obsinfo = cscripts.csobsinfo() | 125 | obsinfo = cscripts.csobsinfo() |
| 137 | - obsinfo["inobs"] = "data/obs_unbinned.xml" | ||
| 138 | - obsinfo["ds9file"] = "csobsinfo_py2.reg" | ||
| 139 | - obsinfo["offset"] = True | ||
| 140 | - obsinfo["ra"] = 83.63 | ||
| 141 | - obsinfo["dec"] = 22.01 | ||
| 142 | - obsinfo["logfile"] = "csobsinfo_py2.log" | ||
| 143 | - obsinfo["chatter"] = 3 | 126 | + obsinfo['inobs'] = 'data/obs_unbinned.xml' |
| 127 | + obsinfo['ds9file'] = 'csobsinfo_py2.reg' | ||
| 128 | + obsinfo['offset'] = True | ||
| 129 | + obsinfo['ra'] = 83.63 | ||
| 130 | + obsinfo['dec'] = 22.01 | ||
| 131 | + obsinfo['logfile'] = 'csobsinfo_py2.log' | ||
| 132 | + obsinfo['chatter'] = 3 | ||
| 144 | 133 | ||
| 145 | # Execute csobsinfo script | 134 | # Execute csobsinfo script |
| 146 | obsinfo.execute() | 135 | obsinfo.execute() |
| 147 | 136 | ||
| 148 | # Check DS9 file | 137 | # Check DS9 file |
| 149 | - self._check_ds9_file("csobsinfo_py2.reg") | 138 | + self._check_ds9_file('csobsinfo_py2.reg') |
| 150 | 139 | ||
| 151 | # Return | 140 | # Return |
| 152 | return | 141 | return |
| @@ -154,10 +143,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -154,10 +143,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 154 | # Check DS9 file | 143 | # Check DS9 file |
| 155 | def _check_ds9_file(self, filename): | 144 | def _check_ds9_file(self, filename): |
| 156 | """ | 145 | """ |
| 157 | - Check DS9 file. | 146 | + Check DS9 file |
| 158 | """ | 147 | """ |
| 159 | # Open file | 148 | # Open file |
| 160 | - f = open(filename,"r") | 149 | + f = open(filename,'r') |
| 161 | 150 | ||
| 162 | # Expect "fk5" in first line | 151 | # Expect "fk5" in first line |
| 163 | line = f.readline().strip('\n') | 152 | line = f.readline().strip('\n') |
test/test_cspull.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for cspull script # | 27 | # Test class for cspull script # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cspull script. | 31 | + Test class for cspull script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cspull script by using it | 33 | This test class makes unit tests for the cspull script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,14 +48,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | - self.name("cspull") | 54 | + self.name('cspull') |
| 55 | 55 | ||
| 56 | # Append tests | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test cspull on command line") | ||
| 58 | - self.append(self._test_python, "Test cspull from Python") | 57 | + self.append(self._test_cmd, 'Test cspull on command line') |
| 58 | + self.append(self._test_python, 'Test cspull from Python') | ||
| 59 | 59 | ||
| 60 | # Return | 60 | # Return |
| 61 | return | 61 | return |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test cspull on command line | 63 | # Test cspull on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test cspull on the command line. | 66 | + Test cspull on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile("README.md"): | ||
| 70 | - cspull = "../cscripts/cspull.py" | ||
| 71 | - else: | ||
| 72 | - cspull = "cspull" | 68 | + # Set script name |
| 69 | + cspull = self._script('cspull') | ||
| 73 | 70 | ||
| 74 | # Setup cspull command | 71 | # Setup cspull command |
| 75 | cmd = cspull+' inmodel="data/crab.xml"'+ \ | 72 | cmd = cspull+' inmodel="data/crab.xml"'+ \ |
| @@ -80,18 +77,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -80,18 +77,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 80 | ' npix=200 binsz=0.05'+ \ | 77 | ' npix=200 binsz=0.05'+ \ |
| 81 | ' logfile="cspull_cmd1.log" chatter=1' | 78 | ' logfile="cspull_cmd1.log" chatter=1' |
| 82 | 79 | ||
| 83 | - # Execute cspull, make sure we catch any exception | ||
| 84 | - try: | ||
| 85 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 86 | - except: | ||
| 87 | - pass | 80 | + # Check if execution of wrong command fails |
| 81 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 82 | + 'Self test of test script') | ||
| 88 | 83 | ||
| 89 | # Check if execution was successful | 84 | # Check if execution was successful |
| 90 | - self.test_assert(rc == 0, | ||
| 91 | - "Successful cspull execution on command line") | 85 | + self.test_assert(self._execute(cmd) == 0, |
| 86 | + 'Check successful execution from command line') | ||
| 92 | 87 | ||
| 93 | # Check pull distribution file | 88 | # Check pull distribution file |
| 94 | - self._check_pull_file("cspull_cmd1.dat") | 89 | + self._check_pull_file('cspull_cmd1.dat') |
| 95 | 90 | ||
| 96 | # Setup cspull command | 91 | # Setup cspull command |
| 97 | cmd = cspull+' inmodel="model_that_does_not_exist.xml"'+ \ | 92 | cmd = cspull+' inmodel="model_that_does_not_exist.xml"'+ \ |
| @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 102 | ' npix=200 binsz=0.05'+ \ | 97 | ' npix=200 binsz=0.05'+ \ |
| 103 | ' logfile="cspull_cmd2.log"' | 98 | ' logfile="cspull_cmd2.log"' |
| 104 | 99 | ||
| 105 | - # Execute cspull, make sure we catch any exception | ||
| 106 | - try: | ||
| 107 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 108 | - except: | ||
| 109 | - pass | ||
| 110 | - | ||
| 111 | # Check if execution failed | 100 | # Check if execution failed |
| 112 | - self.test_assert(rc != 0, | ||
| 113 | - "Failure of cspull execution on command line") | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 114 | 103 | ||
| 115 | # Return | 104 | # Return |
| 116 | return | 105 | return |
| @@ -118,25 +107,25 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,25 +107,25 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Test cspull from Python | 107 | # Test cspull from Python |
| 119 | def _test_python(self): | 108 | def _test_python(self): |
| 120 | """ | 109 | """ |
| 121 | - Test cspull from Python. | 110 | + Test cspull from Python |
| 122 | """ | 111 | """ |
| 123 | # Set-up unbinned cspull | 112 | # Set-up unbinned cspull |
| 124 | pull = cscripts.cspull() | 113 | pull = cscripts.cspull() |
| 125 | - pull["inmodel"] = "data/crab.xml" | ||
| 126 | - pull["outfile"] = "cspull_py1.dat" | ||
| 127 | - pull["ntrials"] = 3 | ||
| 128 | - pull["caldb"] = "prod2" | ||
| 129 | - pull["irf"] = "South_0.5h" | ||
| 130 | - pull["ra"] = 83.6331 | ||
| 131 | - pull["dec"] = 22.0145 | ||
| 132 | - pull["emin"] = 0.1 | ||
| 133 | - pull["emax"] = 100.0 | ||
| 134 | - pull["enumbins"] = 0 | ||
| 135 | - pull["tmax"] = 1800.0 | ||
| 136 | - pull["deadc"] = 0.95 | ||
| 137 | - pull["rad"] = 5.0 | ||
| 138 | - pull["logfile"] = "cspull_py1.log" | ||
| 139 | - pull["chatter"] = 2 | 114 | + pull['inmodel'] = 'data/crab.xml' |
| 115 | + pull['outfile'] = 'cspull_py1.dat' | ||
| 116 | + pull['ntrials'] = 3 | ||
| 117 | + pull['caldb'] = 'prod2' | ||
| 118 | + pull['irf'] = 'South_0.5h' | ||
| 119 | + pull['ra'] = 83.6331 | ||
| 120 | + pull['dec'] = 22.0145 | ||
| 121 | + pull['emin'] = 0.1 | ||
| 122 | + pull['emax'] = 100.0 | ||
| 123 | + pull['enumbins'] = 0 | ||
| 124 | + pull['tmax'] = 1800.0 | ||
| 125 | + pull['deadc'] = 0.95 | ||
| 126 | + pull['rad'] = 5.0 | ||
| 127 | + pull['logfile'] = 'cspull_py1.log' | ||
| 128 | + pull['chatter'] = 2 | ||
| 140 | 129 | ||
| 141 | # Run cspull script | 130 | # Run cspull script |
| 142 | pull.logFileOpen() # Make sure we get a log file | 131 | pull.logFileOpen() # Make sure we get a log file |
| @@ -144,93 +133,93 @@ class Test(gammalib.GPythonTestSuite): | @@ -144,93 +133,93 @@ class Test(gammalib.GPythonTestSuite): | ||
| 144 | #pull.save() | 133 | #pull.save() |
| 145 | 134 | ||
| 146 | # Check pull distribution file | 135 | # Check pull distribution file |
| 147 | - self._check_pull_file("cspull_py1.dat") | 136 | + self._check_pull_file('cspull_py1.dat') |
| 148 | 137 | ||
| 149 | # Set-up binned cspull | 138 | # Set-up binned cspull |
| 150 | pull = cscripts.cspull() | 139 | pull = cscripts.cspull() |
| 151 | - pull["inmodel"] = "data/crab.xml" | ||
| 152 | - pull["outfile"] = "cspull_py2.dat" | ||
| 153 | - pull["ntrials"] = 3 | ||
| 154 | - pull["caldb"] = "prod2" | ||
| 155 | - pull["irf"] = "South_0.5h" | ||
| 156 | - pull["ra"] = 83.6331 | ||
| 157 | - pull["dec"] = 22.0145 | ||
| 158 | - pull["emin"] = 0.1 | ||
| 159 | - pull["emax"] = 100.0 | ||
| 160 | - pull["enumbins"] = 10 | ||
| 161 | - pull["tmax"] = 1800.0 | ||
| 162 | - pull["deadc"] = 0.95 | ||
| 163 | - pull["rad"] = 5.0 | ||
| 164 | - pull["npix"] = 100 | ||
| 165 | - pull["binsz"] = 0.02 | ||
| 166 | - pull["coordsys"] = "CEL" | ||
| 167 | - pull["proj"] = "TAN" | ||
| 168 | - pull["logfile"] = "cspull_py2.log" | ||
| 169 | - pull["chatter"] = 3 | 140 | + pull['inmodel'] = 'data/crab.xml' |
| 141 | + pull['outfile'] = 'cspull_py2.dat' | ||
| 142 | + pull['ntrials'] = 3 | ||
| 143 | + pull['caldb'] = 'prod2' | ||
| 144 | + pull['irf'] = 'South_0.5h' | ||
| 145 | + pull['ra'] = 83.6331 | ||
| 146 | + pull['dec'] = 22.0145 | ||
| 147 | + pull['emin'] = 0.1 | ||
| 148 | + pull['emax'] = 100.0 | ||
| 149 | + pull['enumbins'] = 10 | ||
| 150 | + pull['tmax'] = 1800.0 | ||
| 151 | + pull['deadc'] = 0.95 | ||
| 152 | + pull['rad'] = 5.0 | ||
| 153 | + pull['npix'] = 100 | ||
| 154 | + pull['binsz'] = 0.02 | ||
| 155 | + pull['coordsys'] = 'CEL' | ||
| 156 | + pull['proj'] = 'TAN' | ||
| 157 | + pull['logfile'] = 'cspull_py2.log' | ||
| 158 | + pull['chatter'] = 3 | ||
| 170 | 159 | ||
| 171 | # Execute cspull script | 160 | # Execute cspull script |
| 172 | pull.execute() | 161 | pull.execute() |
| 173 | 162 | ||
| 174 | # Check pull distribution file | 163 | # Check pull distribution file |
| 175 | - self._check_pull_file("cspull_py2.dat") | 164 | + self._check_pull_file('cspull_py2.dat') |
| 176 | 165 | ||
| 177 | # Set-up cspull from event list | 166 | # Set-up cspull from event list |
| 178 | pull = cscripts.cspull() | 167 | pull = cscripts.cspull() |
| 179 | - pull["inobs"] = "data/crab_events.fits" | ||
| 180 | - pull["inmodel"] = "data/crab.xml" | ||
| 181 | - pull["outfile"] = "cspull_py3.dat" | ||
| 182 | - pull["ntrials"] = 3 | ||
| 183 | - pull["caldb"] = "prod2" | ||
| 184 | - pull["irf"] = "South_0.5h" | ||
| 185 | - pull["enumbins"] = 0 | ||
| 186 | - pull["logfile"] = "cspull_py3.log" | ||
| 187 | - pull["chatter"] = 4 | 168 | + pull['inobs'] = 'data/crab_events.fits' |
| 169 | + pull['inmodel'] = 'data/crab.xml' | ||
| 170 | + pull['outfile'] = 'cspull_py3.dat' | ||
| 171 | + pull['ntrials'] = 3 | ||
| 172 | + pull['caldb'] = 'prod2' | ||
| 173 | + pull['irf'] = 'South_0.5h' | ||
| 174 | + pull['enumbins'] = 0 | ||
| 175 | + pull['logfile'] = 'cspull_py3.log' | ||
| 176 | + pull['chatter'] = 4 | ||
| 188 | 177 | ||
| 189 | # Execute cspull script | 178 | # Execute cspull script |
| 190 | pull.execute() | 179 | pull.execute() |
| 191 | 180 | ||
| 192 | # Check pull distribution file | 181 | # Check pull distribution file |
| 193 | - self._check_pull_file("cspull_py3.dat") | 182 | + self._check_pull_file('cspull_py3.dat') |
| 194 | 183 | ||
| 195 | # Build observation container with unbinned observation | 184 | # Build observation container with unbinned observation |
| 196 | - cta = gammalib.GCTAObservation("data/crab_events.fits") | 185 | + cta = gammalib.GCTAObservation('data/crab_events.fits') |
| 197 | obs = gammalib.GObservations() | 186 | obs = gammalib.GObservations() |
| 198 | obs.append(cta) | 187 | obs.append(cta) |
| 199 | 188 | ||
| 200 | # Set-up cspull from observation container with unbinned observation | 189 | # Set-up cspull from observation container with unbinned observation |
| 201 | pull = cscripts.cspull(obs) | 190 | pull = cscripts.cspull(obs) |
| 202 | - pull["inmodel"] = "data/crab.xml" | ||
| 203 | - pull["outfile"] = "cspull_py4.dat" | ||
| 204 | - pull["ntrials"] = 3 | ||
| 205 | - pull["caldb"] = "prod2" | ||
| 206 | - pull["irf"] = "South_0.5h" | ||
| 207 | - pull["enumbins"] = 0 | ||
| 208 | - pull["logfile"] = "cspull_py4.log" | ||
| 209 | - pull["chatter"] = 4 | 191 | + pull['inmodel'] = 'data/crab.xml' |
| 192 | + pull['outfile'] = 'cspull_py4.dat' | ||
| 193 | + pull['ntrials'] = 3 | ||
| 194 | + pull['caldb'] = 'prod2' | ||
| 195 | + pull['irf'] = 'South_0.5h' | ||
| 196 | + pull['enumbins'] = 0 | ||
| 197 | + pull['logfile'] = 'cspull_py4.log' | ||
| 198 | + pull['chatter'] = 4 | ||
| 210 | 199 | ||
| 211 | # Execute cspull script | 200 | # Execute cspull script |
| 212 | pull.execute() | 201 | pull.execute() |
| 213 | 202 | ||
| 214 | # Check pull distribution file | 203 | # Check pull distribution file |
| 215 | - self._check_pull_file("cspull_py4.dat") | 204 | + self._check_pull_file('cspull_py4.dat') |
| 216 | 205 | ||
| 217 | # Set-up stacked cspull | 206 | # Set-up stacked cspull |
| 218 | pull = cscripts.cspull() | 207 | pull = cscripts.cspull() |
| 219 | - pull["inobs"] = "data/obs_stacked.xml" | ||
| 220 | - pull["inmodel"] = "data/crab_bkgcube.xml" | ||
| 221 | - pull["outfile"] = "cspull_py5.dat" | ||
| 222 | - pull["ntrials"] = 3 | ||
| 223 | - pull["caldb"] = "prod2" | ||
| 224 | - pull["irf"] = "South_0.5h" | ||
| 225 | - pull["enumbins"] = 0 | ||
| 226 | - pull["logfile"] = "cspull_py5.log" | ||
| 227 | - pull["chatter"] = 4 | 208 | + pull['inobs'] = 'data/obs_stacked.xml' |
| 209 | + pull['inmodel'] = 'data/crab_bkgcube.xml' | ||
| 210 | + pull['outfile'] = 'cspull_py5.dat' | ||
| 211 | + pull['ntrials'] = 3 | ||
| 212 | + pull['caldb'] = 'prod2' | ||
| 213 | + pull['irf'] = 'South_0.5h' | ||
| 214 | + pull['enumbins'] = 0 | ||
| 215 | + pull['logfile'] = 'cspull_py5.log' | ||
| 216 | + pull['chatter'] = 4 | ||
| 228 | 217 | ||
| 229 | # Execute cspull script | 218 | # Execute cspull script |
| 230 | pull.execute() | 219 | pull.execute() |
| 231 | 220 | ||
| 232 | # Check pull distribution file | 221 | # Check pull distribution file |
| 233 | - self._check_pull_file("cspull_py5.dat") | 222 | + self._check_pull_file('cspull_py5.dat') |
| 234 | 223 | ||
| 235 | # Return | 224 | # Return |
| 236 | return | 225 | return |
| @@ -238,7 +227,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -238,7 +227,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 238 | # Check pull file | 227 | # Check pull file |
| 239 | def _check_pull_file(self, filename): | 228 | def _check_pull_file(self, filename): |
| 240 | """ | 229 | """ |
| 241 | - Check pull file. | 230 | + Check pull file |
| 242 | """ | 231 | """ |
| 243 | # Open pull file as CSV file | 232 | # Open pull file as CSV file |
| 244 | pulls = gammalib.GCsv(filename) | 233 | pulls = gammalib.GCsv(filename) |
test/test_csresmap.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================== # | 26 | # ============================== # |
| 27 | # Test class for csresmap script # | 27 | # Test class for csresmap script # |
| 28 | # ============================== # | 28 | # ============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csresmap script. | 31 | + Test class for csresmap script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csresmap script by using it | 33 | This test class makes unit tests for the csresmap script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('csresmap') | 54 | self.name('csresmap') |
| @@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -65,11 +65,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 65 | """ | 65 | """ |
| 66 | Test csresmap on the command line. | 66 | Test csresmap on the command line. |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - csresmap = '../cscripts/csresmap.py' | ||
| 71 | - else: | ||
| 72 | - csresmap = 'csresmap' | 68 | + # Set script name |
| 69 | + csresmap = self._script('csresmap') | ||
| 73 | 70 | ||
| 74 | # Setup csresmap command | 71 | # Setup csresmap command |
| 75 | cmd = csresmap+' inobs="data/crab_events.fits"'+ \ | 72 | cmd = csresmap+' inobs="data/crab_events.fits"'+ \ |
| @@ -82,15 +79,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -82,15 +79,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 82 | ' algorithm="SUBDIV"'+ \ | 79 | ' algorithm="SUBDIV"'+ \ |
| 83 | ' logfile="csresmap_cmd1.log" chatter=1' | 80 | ' logfile="csresmap_cmd1.log" chatter=1' |
| 84 | 81 | ||
| 85 | - # Execute csresmap, make sure we catch any exception | ||
| 86 | - try: | ||
| 87 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 88 | - except: | ||
| 89 | - pass | 82 | + # Check if execution of wrong command fails |
| 83 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 84 | + 'Self test of test script') | ||
| 90 | 85 | ||
| 91 | # Check if execution was successful | 86 | # Check if execution was successful |
| 92 | - self.test_assert(rc == 0, | ||
| 93 | - 'Successful csresmap execution on command line') | 87 | + self.test_assert(self._execute(cmd) == 0, |
| 88 | + 'Check successful execution from command line') | ||
| 94 | 89 | ||
| 95 | # Check result file | 90 | # Check result file |
| 96 | self._check_result_file('csresmap_cmd1.fits') | 91 | self._check_result_file('csresmap_cmd1.fits') |
| @@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -106,15 +101,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 106 | ' algorithm="SUBDIV"'+ \ | 101 | ' algorithm="SUBDIV"'+ \ |
| 107 | ' logfile="csresmap_cmd2.log" chatter=2' | 102 | ' logfile="csresmap_cmd2.log" chatter=2' |
| 108 | 103 | ||
| 109 | - # Execute csresmap, make sure we catch any exception | ||
| 110 | - try: | ||
| 111 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 112 | - except: | ||
| 113 | - pass | ||
| 114 | - | ||
| 115 | # Check if execution failed | 104 | # Check if execution failed |
| 116 | - self.test_assert(rc != 0, | ||
| 117 | - 'Failure of csresmap execution on command line') | 105 | + self.test_assert(self._execute(cmd) != 0, |
| 106 | + 'Check invalid input file when executed from command line') | ||
| 118 | 107 | ||
| 119 | # Return | 108 | # Return |
| 120 | return | 109 | return |
| @@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -122,7 +111,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 122 | # Test csresmap from Python | 111 | # Test csresmap from Python |
| 123 | def _test_python(self): | 112 | def _test_python(self): |
| 124 | """ | 113 | """ |
| 125 | - Test csresmap from Python. | 114 | + Test csresmap from Python |
| 126 | """ | 115 | """ |
| 127 | # Set-up csresmap for event list | 116 | # Set-up csresmap for event list |
| 128 | resmap = cscripts.csresmap() | 117 | resmap = cscripts.csresmap() |
| @@ -181,7 +170,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -181,7 +170,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 181 | # Check result file | 170 | # Check result file |
| 182 | def _check_result_file(self, filename, nx=50, ny=50): | 171 | def _check_result_file(self, filename, nx=50, ny=50): |
| 183 | """ | 172 | """ |
| 184 | - Check result file. | 173 | + Check result file |
| 185 | """ | 174 | """ |
| 186 | # Load residual map | 175 | # Load residual map |
| 187 | residual = gammalib.GSkyMap(filename) | 176 | residual = gammalib.GSkyMap(filename) |
test/test_csroot2caldb.py
| @@ -21,14 +21,15 @@ | @@ -21,14 +21,15 @@ | ||
| 21 | import os | 21 | import os |
| 22 | import gammalib | 22 | import gammalib |
| 23 | import cscripts | 23 | import cscripts |
| 24 | +from testing import test | ||
| 24 | 25 | ||
| 25 | 26 | ||
| 26 | # ================================== # | 27 | # ================================== # |
| 27 | # Test class for csroot2caldb script # | 28 | # Test class for csroot2caldb script # |
| 28 | # ================================== # | 29 | # ================================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 30 | +class Test(test): |
| 30 | """ | 31 | """ |
| 31 | - Test class for csroot2caldb script. | 32 | + Test class for csroot2caldb script |
| 32 | 33 | ||
| 33 | This test class makes unit tests for the cslightcrv script by using it | 34 | This test class makes unit tests for the cslightcrv script by using it |
| 34 | from the command line and from Python. | 35 | from the command line and from Python. |
| @@ -40,10 +41,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -40,10 +41,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 40 | Constructor. | 41 | Constructor. |
| 41 | """ | 42 | """ |
| 42 | # Call base class constructor | 43 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 44 | + test.__init__(self) |
| 44 | 45 | ||
| 45 | # Clean calibration database | 46 | # Clean calibration database |
| 46 | - os.system("rm -rf csroot2caldb_* >/dev/null 2>&1") | 47 | + os.system('rm -rf csroot2caldb_* >/dev/null 2>&1') |
| 47 | 48 | ||
| 48 | # Return | 49 | # Return |
| 49 | return | 50 | return |
| @@ -51,14 +52,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -51,14 +52,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 51 | # Set test functions | 52 | # Set test functions |
| 52 | def set(self): | 53 | def set(self): |
| 53 | """ | 54 | """ |
| 54 | - Set all test functions. | 55 | + Set all test functions |
| 55 | """ | 56 | """ |
| 56 | # Set test name | 57 | # Set test name |
| 57 | - self.name("csroot2caldb") | 58 | + self.name('csroot2caldb') |
| 58 | 59 | ||
| 59 | # Append tests | 60 | # Append tests |
| 60 | - self.append(self._test_cmd, "Test csroot2caldb on command line") | ||
| 61 | - self.append(self._test_python, "Test csroot2caldb from Python") | 61 | + self.append(self._test_cmd, 'Test csroot2caldb on command line') |
| 62 | + self.append(self._test_python, 'Test csroot2caldb from Python') | ||
| 62 | 63 | ||
| 63 | # Return | 64 | # Return |
| 64 | return | 65 | return |
| @@ -66,13 +67,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,13 +67,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | # Test csroot2caldb on command line | 67 | # Test csroot2caldb on command line |
| 67 | def _test_cmd(self): | 68 | def _test_cmd(self): |
| 68 | """ | 69 | """ |
| 69 | - Test csroot2caldb on the command line. | 70 | + Test csroot2caldb on the command line |
| 70 | """ | 71 | """ |
| 71 | - # Kluge to set the command (installed version has no README file) | ||
| 72 | - if os.path.isfile("README.md"): | ||
| 73 | - csroot2caldb = "../cscripts/csroot2caldb.py" | ||
| 74 | - else: | ||
| 75 | - csroot2caldb = "csroot2caldb" | 72 | + # Set script name |
| 73 | + csroot2caldb = self._script('csroot2caldb') | ||
| 76 | 74 | ||
| 77 | # Setup csroot2caldb command | 75 | # Setup csroot2caldb command |
| 78 | cmd = csroot2caldb+' infile="data/irf.root"'+ \ | 76 | cmd = csroot2caldb+' infile="data/irf.root"'+ \ |
| @@ -81,15 +79,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -81,15 +79,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 81 | ' analysis=DESY'+ \ | 79 | ' analysis=DESY'+ \ |
| 82 | ' logfile="csroot2caldb_cmd1.log" chatter=1' | 80 | ' logfile="csroot2caldb_cmd1.log" chatter=1' |
| 83 | 81 | ||
| 84 | - # Execute csroot2caldb, make sure we catch any exception | ||
| 85 | - try: | ||
| 86 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 87 | - except: | ||
| 88 | - pass | 82 | + # Check if execution of wrong command fails |
| 83 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 84 | + 'Self test of test script') | ||
| 89 | 85 | ||
| 90 | # Check if execution was successful | 86 | # Check if execution was successful |
| 91 | - self.test_assert(rc == 0, | ||
| 92 | - "Successful csroot2caldb execution on command line") | 87 | + self.test_assert(self._execute(cmd) == 0, |
| 88 | + 'Check successful execution from command line') | ||
| 93 | 89 | ||
| 94 | # Return | 90 | # Return |
| 95 | return | 91 | return |
| @@ -97,18 +93,18 @@ class Test(gammalib.GPythonTestSuite): | @@ -97,18 +93,18 @@ class Test(gammalib.GPythonTestSuite): | ||
| 97 | # Test csroot2caldb from Python | 93 | # Test csroot2caldb from Python |
| 98 | def _test_python(self): | 94 | def _test_python(self): |
| 99 | """ | 95 | """ |
| 100 | - Test csroot2caldb from Python. | 96 | + Test csroot2caldb from Python |
| 101 | """ | 97 | """ |
| 102 | # Set-up csroot2caldb | 98 | # Set-up csroot2caldb |
| 103 | caldb = cscripts.csroot2caldb() | 99 | caldb = cscripts.csroot2caldb() |
| 104 | - caldb["infile"] = "data/irf.root" | ||
| 105 | - caldb["outdir"] = "csroot2caldb_py1" | ||
| 106 | - caldb["inst"] = "prod3" | ||
| 107 | - caldb["id"] = "South_50h" | ||
| 108 | - caldb["version"] = "prod3" | ||
| 109 | - caldb["analysis"] = "DESY" | ||
| 110 | - caldb["logfile"] = "csroot2caldb_py1.log" | ||
| 111 | - caldb["chatter"] = 2 | 100 | + caldb['infile'] = 'data/irf.root' |
| 101 | + caldb['outdir'] = 'csroot2caldb_py1' | ||
| 102 | + caldb['inst'] = 'prod3' | ||
| 103 | + caldb['id'] = 'South_50h' | ||
| 104 | + caldb['version'] = 'prod3' | ||
| 105 | + caldb['analysis'] = 'DESY' | ||
| 106 | + caldb['logfile'] = 'csroot2caldb_py1.log' | ||
| 107 | + caldb['chatter'] = 2 | ||
| 112 | 108 | ||
| 113 | # Run script | 109 | # Run script |
| 114 | caldb.logFileOpen() # Make sure we get a log file | 110 | caldb.logFileOpen() # Make sure we get a log file |
test/test_cssens.py
| @@ -20,13 +20,13 @@ | @@ -20,13 +20,13 @@ | ||
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | import gammalib | 21 | import gammalib |
| 22 | import cscripts | 22 | import cscripts |
| 23 | -import test_cscripts_class | 23 | +from testing import test |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for cssens script # | 27 | # Test class for cssens script # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(test_cscripts_class.cscripts_test): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | Test class for cssens script | 31 | Test class for cssens script |
| 32 | 32 | ||
| @@ -40,7 +40,7 @@ class Test(test_cscripts_class.cscripts_test): | @@ -40,7 +40,7 @@ class Test(test_cscripts_class.cscripts_test): | ||
| 40 | Constructor | 40 | Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - test_cscripts_class.cscripts_test.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -103,7 +103,7 @@ class Test(test_cscripts_class.cscripts_test): | @@ -103,7 +103,7 @@ class Test(test_cscripts_class.cscripts_test): | ||
| 103 | # Test cssens from Python | 103 | # Test cssens from Python |
| 104 | def _test_python(self): | 104 | def _test_python(self): |
| 105 | """ | 105 | """ |
| 106 | - Test cssens from Python. | 106 | + Test cssens from Python |
| 107 | """ | 107 | """ |
| 108 | # Set-up cssens | 108 | # Set-up cssens |
| 109 | sens = cscripts.cssens() | 109 | sens = cscripts.cssens() |
| @@ -135,7 +135,7 @@ class Test(test_cscripts_class.cscripts_test): | @@ -135,7 +135,7 @@ class Test(test_cscripts_class.cscripts_test): | ||
| 135 | # Check result file | 135 | # Check result file |
| 136 | def _check_result_file(self, filename): | 136 | def _check_result_file(self, filename): |
| 137 | """ | 137 | """ |
| 138 | - Check result file. | 138 | + Check result file |
| 139 | """ | 139 | """ |
| 140 | # Open result file as CSV file | 140 | # Open result file as CSV file |
| 141 | results = gammalib.GCsv(filename, ',') | 141 | results = gammalib.GCsv(filename, ',') |
test/test_csspec.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for csspec script # | 27 | # Test class for csspec script # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csspec script. | 31 | + Test class for csspec script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the csspec script by using it | 33 | This test class makes unit tests for the csspec script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('csspec') | 54 | self.name('csspec') |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test csspec on command line | 63 | # Test csspec on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test csspec on the command line. | 66 | + Test csspec on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - csspec = '../cscripts/csspec.py' | ||
| 71 | - else: | ||
| 72 | - csspec = 'csspec' | 68 | + # Set script name |
| 69 | + csspec = self._script('csspec') | ||
| 73 | 70 | ||
| 74 | # Setup csspec command | 71 | # Setup csspec command |
| 75 | cmd = csspec+' inobs="data/crab_events.fits"'+ \ | 72 | cmd = csspec+' inobs="data/crab_events.fits"'+ \ |
| @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 79 | ' outfile="csspec_cmd1.fits"'+ \ | 76 | ' outfile="csspec_cmd1.fits"'+ \ |
| 80 | ' logfile="csspec_cmd1.log" chatter=1' | 77 | ' logfile="csspec_cmd1.log" chatter=1' |
| 81 | 78 | ||
| 82 | - # Execute csspec, make sure we catch any exception | ||
| 83 | - try: | ||
| 84 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 85 | - except: | ||
| 86 | - pass | 79 | + # Check if execution of wrong command fails |
| 80 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 81 | + 'Self test of test script') | ||
| 87 | 82 | ||
| 88 | # Check if execution was successful | 83 | # Check if execution was successful |
| 89 | - self.test_assert(rc == 0, | ||
| 90 | - 'Successful csspec execution on command line') | 84 | + self.test_assert(self._execute(cmd) == 0, |
| 85 | + 'Check successful execution from command line') | ||
| 91 | 86 | ||
| 92 | # Check result file | 87 | # Check result file |
| 93 | self._check_result_file('csspec_cmd1.fits', 5) | 88 | self._check_result_file('csspec_cmd1.fits', 5) |
| @@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 100 | ' outfile="csspec_cmd2.fits"'+ \ | 95 | ' outfile="csspec_cmd2.fits"'+ \ |
| 101 | ' logfile="csspec_cmd2.log" chatter=1' | 96 | ' logfile="csspec_cmd2.log" chatter=1' |
| 102 | 97 | ||
| 103 | - # Execute csspec, make sure we catch any exception | ||
| 104 | - try: | ||
| 105 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 106 | - except: | ||
| 107 | - pass | ||
| 108 | - | ||
| 109 | # Check if execution failed | 98 | # Check if execution failed |
| 110 | - self.test_assert(rc != 0, | ||
| 111 | - 'Failure of csspec execution on command line') | 99 | + self.test_assert(self._execute(cmd) != 0, |
| 100 | + 'Check invalid input file when executed from command line') | ||
| 112 | 101 | ||
| 113 | # Return | 102 | # Return |
| 114 | return | 103 | return |
| @@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 116 | # Test csspec from Python | 105 | # Test csspec from Python |
| 117 | def _test_python(self): | 106 | def _test_python(self): |
| 118 | """ | 107 | """ |
| 119 | - Test csspec from Python. | 108 | + Test csspec from Python |
| 120 | """ | 109 | """ |
| 121 | # Set-up unbinned csspec | 110 | # Set-up unbinned csspec |
| 122 | spec = cscripts.csspec() | 111 | spec = cscripts.csspec() |
| @@ -170,7 +159,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -170,7 +159,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 170 | # Check result file | 159 | # Check result file |
| 171 | def _check_result_file(self, filename, bins): | 160 | def _check_result_file(self, filename, bins): |
| 172 | """ | 161 | """ |
| 173 | - Check result file. | 162 | + Check result file |
| 174 | """ | 163 | """ |
| 175 | # Open result file | 164 | # Open result file |
| 176 | fits = gammalib.GFits(filename) | 165 | fits = gammalib.GFits(filename) |
test/test_cstsdist.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================== # | 26 | # ============================== # |
| 27 | # Test class for cstsdist script # | 27 | # Test class for cstsdist script # |
| 28 | # ============================== # | 28 | # ============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cstsdist script. | 31 | + Test class for cstsdist script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cstsdist script by using it | 33 | This test class makes unit tests for the cstsdist script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('cstsdist') | 54 | self.name('cstsdist') |
| @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test cstsdist on command line | 63 | # Test cstsdist on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test cstsdist on the command line. | 66 | + Test cstsdist on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - cstsdist = '../cscripts/cstsdist.py' | ||
| 71 | - else: | ||
| 72 | - cstsdist = 'cstsdist' | 68 | + # Set script name |
| 69 | + cstsdist = self._script('cstsdist') | ||
| 73 | 70 | ||
| 74 | # Setup cstsdist command | 71 | # Setup cstsdist command |
| 75 | cmd = cstsdist+' inmodel="data/crab.xml"'+ \ | 72 | cmd = cstsdist+' inmodel="data/crab.xml"'+ \ |
| @@ -80,15 +77,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -80,15 +77,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 80 | ' outfile="cstsdist_cmd1.dat"'+ \ | 77 | ' outfile="cstsdist_cmd1.dat"'+ \ |
| 81 | ' logfile="cstsdist_cmd1.log" chatter=1' | 78 | ' logfile="cstsdist_cmd1.log" chatter=1' |
| 82 | 79 | ||
| 83 | - # Execute cstsdist, make sure we catch any exception | ||
| 84 | - try: | ||
| 85 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 86 | - except: | ||
| 87 | - pass | 80 | + # Check if execution of wrong command fails |
| 81 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 82 | + 'Self test of test script') | ||
| 88 | 83 | ||
| 89 | # Check if execution was successful | 84 | # Check if execution was successful |
| 90 | - self.test_assert(rc == 0, | ||
| 91 | - 'Successful cstsdist execution on command line') | 85 | + self.test_assert(self._execute(cmd) == 0, |
| 86 | + 'Check successful execution from command line') | ||
| 92 | 87 | ||
| 93 | # Check result file | 88 | # Check result file |
| 94 | self._check_result_file('cstsdist_cmd1.dat') | 89 | self._check_result_file('cstsdist_cmd1.dat') |
| @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 102 | ' outfile="cstsdist_cmd2.dat"'+ \ | 97 | ' outfile="cstsdist_cmd2.dat"'+ \ |
| 103 | ' logfile="cstsdist_cmd2.log" chatter=2' | 98 | ' logfile="cstsdist_cmd2.log" chatter=2' |
| 104 | 99 | ||
| 105 | - # Execute cstsdist, make sure we catch any exception | ||
| 106 | - try: | ||
| 107 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 108 | - except: | ||
| 109 | - pass | ||
| 110 | - | ||
| 111 | # Check if execution failed | 100 | # Check if execution failed |
| 112 | - self.test_assert(rc != 0, | ||
| 113 | - 'Failure of cstsdist execution on command line') | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 114 | 103 | ||
| 115 | # Return | 104 | # Return |
| 116 | return | 105 | return |
| @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Test cstsdist from Python | 107 | # Test cstsdist from Python |
| 119 | def _test_python(self): | 108 | def _test_python(self): |
| 120 | """ | 109 | """ |
| 121 | - Test cstsdist from Python. | 110 | + Test cstsdist from Python |
| 122 | """ | 111 | """ |
| 123 | # Set-up cstsdist | 112 | # Set-up cstsdist |
| 124 | tsdist = cscripts.cstsdist() | 113 | tsdist = cscripts.cstsdist() |
| @@ -154,7 +143,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -154,7 +143,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 154 | # Check result file | 143 | # Check result file |
| 155 | def _check_result_file(self, filename): | 144 | def _check_result_file(self, filename): |
| 156 | """ | 145 | """ |
| 157 | - Check result file. | 146 | + Check result file |
| 158 | """ | 147 | """ |
| 159 | # Open result file as CSV file | 148 | # Open result file as CSV file |
| 160 | results = gammalib.GCsv(filename, ',') | 149 | results = gammalib.GCsv(filename, ',') |
test/test_cstsmapmerge.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================== # | 26 | # ================================== # |
| 27 | # Test class for cstsmapmerge script # | 27 | # Test class for cstsmapmerge script # |
| 28 | # ================================== # | 28 | # ================================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cstsmapmerge script. | 31 | + Test class for cstsmapmerge script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cstsmapmerge script by using it | 33 | This test class makes unit tests for the cstsmapmerge script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('cstsmapmerge') | 54 | self.name('cstsmapmerge') |
| @@ -63,28 +63,23 @@ class Test(gammalib.GPythonTestSuite): | @@ -63,28 +63,23 @@ class Test(gammalib.GPythonTestSuite): | ||
| 63 | # Test cstsmapmerge on command line | 63 | # Test cstsmapmerge on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | """ | 65 | """ |
| 66 | - Test cstsmapmerge on the command line. | 66 | + Test cstsmapmerge on the command line |
| 67 | """ | 67 | """ |
| 68 | - # Kluge to set the command (installed version has no README file) | ||
| 69 | - if os.path.isfile('README.md'): | ||
| 70 | - cstsmapmerge = '../cscripts/cstsmapmerge.py' | ||
| 71 | - else: | ||
| 72 | - cstsmapmerge = 'cstsmapmerge' | 68 | + # Set script name |
| 69 | + cstsmapmerge = self._script('cstsmapmerge') | ||
| 73 | 70 | ||
| 74 | # Setup cstsmapmerge command | 71 | # Setup cstsmapmerge command |
| 75 | cmd = cstsmapmerge+' inmaps="data/tsmap_0.fits;data/tsmap_1.fits"'+ \ | 72 | cmd = cstsmapmerge+' inmaps="data/tsmap_0.fits;data/tsmap_1.fits"'+ \ |
| 76 | ' outmap="cstsmapmerge_cmd1.fits"'+ \ | 73 | ' outmap="cstsmapmerge_cmd1.fits"'+ \ |
| 77 | ' logfile="cstsmapmerge_cmd1.log" chatter=1' | 74 | ' logfile="cstsmapmerge_cmd1.log" chatter=1' |
| 78 | 75 | ||
| 79 | - # Execute cstsmapmerge, make sure we catch any exception | ||
| 80 | - try: | ||
| 81 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 82 | - except: | ||
| 83 | - pass | 76 | + # Check if execution of wrong command fails |
| 77 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 78 | + 'Self test of test script') | ||
| 84 | 79 | ||
| 85 | # Check if execution was successful | 80 | # Check if execution was successful |
| 86 | - self.test_assert(rc == 0, | ||
| 87 | - 'Successful cstsmapmerge execution on command line') | 81 | + self.test_assert(self._execute(cmd) == 0, |
| 82 | + 'Check successful execution from command line') | ||
| 88 | 83 | ||
| 89 | # Check result file | 84 | # Check result file |
| 90 | self._check_result_file('cstsmapmerge_cmd1.fits') | 85 | self._check_result_file('cstsmapmerge_cmd1.fits') |
| @@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 94 | ' outmap="cstsmapmerge_cmd2.fits"'+ \ | 89 | ' outmap="cstsmapmerge_cmd2.fits"'+ \ |
| 95 | ' logfile="cstsmapmerge_cmd2.log" chatter=2' | 90 | ' logfile="cstsmapmerge_cmd2.log" chatter=2' |
| 96 | 91 | ||
| 97 | - # Execute cstsmapmerge, make sure we catch any exception | ||
| 98 | - try: | ||
| 99 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 100 | - except: | ||
| 101 | - pass | ||
| 102 | - | ||
| 103 | # Check if execution failed | 92 | # Check if execution failed |
| 104 | - self.test_assert(rc != 0, | ||
| 105 | - 'Failure of cstsmapmerge execution on command line') | 93 | + self.test_assert(self._execute(cmd) != 0, |
| 94 | + 'Check invalid input file when executed from command line') | ||
| 106 | 95 | ||
| 107 | # Return | 96 | # Return |
| 108 | return | 97 | return |
| @@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 110 | # Test cstsmapmerge from Python | 99 | # Test cstsmapmerge from Python |
| 111 | def _test_python(self): | 100 | def _test_python(self): |
| 112 | """ | 101 | """ |
| 113 | - Test cstsmapmerge from Python. | 102 | + Test cstsmapmerge from Python |
| 114 | """ | 103 | """ |
| 115 | # Set-up semi-colon separated cstsmapmerge | 104 | # Set-up semi-colon separated cstsmapmerge |
| 116 | merge = cscripts.cstsmapmerge() | 105 | merge = cscripts.cstsmapmerge() |
| @@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -172,7 +161,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 172 | # Check result file | 161 | # Check result file |
| 173 | def _check_result_file(self, filename): | 162 | def _check_result_file(self, filename): |
| 174 | """ | 163 | """ |
| 175 | - Check result file. | 164 | + Check result file |
| 176 | """ | 165 | """ |
| 177 | # Open result file | 166 | # Open result file |
| 178 | fits = gammalib.GFits(filename) | 167 | fits = gammalib.GFits(filename) |
test/test_csworkflow.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import cscripts | 22 | import cscripts |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ================================ # | 26 | # ================================ # |
| 27 | # Test class for csworkflow script # | 27 | # Test class for csworkflow script # |
| 28 | # ================================ # | 28 | # ================================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for csworkflow script. | 31 | + Test class for csworkflow script |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the cslightcrv script by using it | 33 | This test class makes unit tests for the cslightcrv script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,10 +37,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Return | 45 | # Return |
| 46 | return | 46 | return |
| @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -48,7 +48,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 48 | # Set test functions | 48 | # Set test functions |
| 49 | def set(self): | 49 | def set(self): |
| 50 | """ | 50 | """ |
| 51 | - Set all test functions. | 51 | + Set all test functions |
| 52 | """ | 52 | """ |
| 53 | # Set test name | 53 | # Set test name |
| 54 | self.name('csworkflow') | 54 | self.name('csworkflow') |
| @@ -62,12 +62,11 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,12 +62,11 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | 62 | ||
| 63 | # Test csworkflow on command line | 63 | # Test csworkflow on command line |
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | - | ||
| 66 | - # Kluge to set the command (installed version has no README file) | ||
| 67 | - if os.path.isfile('README.md'): | ||
| 68 | - csworkflow = '../cscripts/csworkflow.py' | ||
| 69 | - else: | ||
| 70 | - csworkflow = 'csworkflow' | 65 | + """ |
| 66 | + Test csworkflow on the command line | ||
| 67 | + """ | ||
| 68 | + # Set script name | ||
| 69 | + csworkflow = self._script('csworkflow') | ||
| 71 | 70 | ||
| 72 | # Remove result file | 71 | # Remove result file |
| 73 | gammalib.GFilename('wf_crab_results.xml').remove() | 72 | gammalib.GFilename('wf_crab_results.xml').remove() |
| @@ -76,16 +75,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -76,16 +75,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 76 | cmd = csworkflow+' inflow="data/workflow.xml"'+ \ | 75 | cmd = csworkflow+' inflow="data/workflow.xml"'+ \ |
| 77 | ' logfile="csworkflow_cmd1.log" chatter=1' | 76 | ' logfile="csworkflow_cmd1.log" chatter=1' |
| 78 | 77 | ||
| 79 | - # Execute csworkflow, make sure we catch any exception | ||
| 80 | - try: | ||
| 81 | - rc = os.system(cmd) | ||
| 82 | - #rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 83 | - except: | ||
| 84 | - pass | 78 | + # Check if execution of wrong command fails |
| 79 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 80 | + 'Self test of test script') | ||
| 85 | 81 | ||
| 86 | # Check if execution was successful | 82 | # Check if execution was successful |
| 87 | - self.test_assert(rc == 0, | ||
| 88 | - 'Successful csworkflow execution on command line') | 83 | + self.test_assert(self._execute(cmd) == 0, |
| 84 | + 'Check successful execution from command line') | ||
| 89 | 85 | ||
| 90 | # Check fit result | 86 | # Check fit result |
| 91 | self._check_fit_result('wf_crab_results.xml') | 87 | self._check_fit_result('wf_crab_results.xml') |
| @@ -95,7 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -95,7 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 95 | 91 | ||
| 96 | # Test csworkflow from Python | 92 | # Test csworkflow from Python |
| 97 | def _test_python(self): | 93 | def _test_python(self): |
| 98 | - | 94 | + """ |
| 95 | + Test csworkflow from Python | ||
| 96 | + """ | ||
| 99 | # Remove result file | 97 | # Remove result file |
| 100 | gammalib.GFilename('wf_crab_results.xml').remove() | 98 | gammalib.GFilename('wf_crab_results.xml').remove() |
| 101 | 99 | ||
| @@ -132,7 +130,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -132,7 +130,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 132 | 130 | ||
| 133 | # Check fit result XML values | 131 | # Check fit result XML values |
| 134 | def _check_fit_result(self, filename): | 132 | def _check_fit_result(self, filename): |
| 135 | - | 133 | + """ |
| 134 | + Check result file | ||
| 135 | + """ | ||
| 136 | # Load fit results | 136 | # Load fit results |
| 137 | models = gammalib.GModels(filename) | 137 | models = gammalib.GModels(filename) |
| 138 | 138 |
test/test_ctbin.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ========================= # | 26 | # ========================= # |
| 27 | # Test class for ctbin tool # | 27 | # Test class for ctbin tool # |
| 28 | # ========================= # | 28 | # ========================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctbin tool. | 31 | + Test class for ctbin tool |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the ctbin tool by using it from | 33 | This test class makes unit tests for the ctbin tool by using it from |
| 34 | the command line and from Python. | 34 | the command line and from Python. |
| @@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Set members | 45 | # Set members |
| 46 | - self._events_name = "data/crab_events.fits" | 46 | + self._events_name = 'data/crab_events.fits' |
| 47 | 47 | ||
| 48 | # Return | 48 | # Return |
| 49 | return | 49 | return |
| @@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 51 | # Set test functions | 51 | # Set test functions |
| 52 | def set(self): | 52 | def set(self): |
| 53 | """ | 53 | """ |
| 54 | - Set all test functions. | 54 | + Set all test functions |
| 55 | """ | 55 | """ |
| 56 | # Set test name | 56 | # Set test name |
| 57 | - self.name("ctbin") | 57 | + self.name('ctbin') |
| 58 | 58 | ||
| 59 | # Append tests | 59 | # Append tests |
| 60 | - self.append(self._test_cmd, "Test ctbin on command line") | ||
| 61 | - self.append(self._test_python, "Test ctbin from Python") | 60 | + self.append(self._test_cmd, 'Test ctbin on command line') |
| 61 | + self.append(self._test_python, 'Test ctbin from Python') | ||
| 62 | 62 | ||
| 63 | # Return | 63 | # Return |
| 64 | return | 64 | return |
| @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | # Test ctbin on command line | 66 | # Test ctbin on command line |
| 67 | def _test_cmd(self): | 67 | def _test_cmd(self): |
| 68 | """ | 68 | """ |
| 69 | - Test ctbin on the command line. | 69 | + Test ctbin on the command line |
| 70 | """ | 70 | """ |
| 71 | - # Kluge to set the command (installed version has no README file) | ||
| 72 | - if os.path.isfile("README.md"): | ||
| 73 | - ctbin = "../src/ctbin/ctbin" | ||
| 74 | - else: | ||
| 75 | - ctbin = "ctbin" | 71 | + # Set tool name |
| 72 | + ctbin = self._tool('ctbin') | ||
| 76 | 73 | ||
| 77 | # Setup ctbin command | 74 | # Setup ctbin command |
| 78 | cmd = ctbin+' inobs="'+self._events_name+'"'+ \ | 75 | cmd = ctbin+' inobs="'+self._events_name+'"'+ \ |
| @@ -81,18 +78,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -81,18 +78,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 81 | ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ | 78 | ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ |
| 82 | ' xref=83.63 yref=22.01 proj="CAR"' | 79 | ' xref=83.63 yref=22.01 proj="CAR"' |
| 83 | 80 | ||
| 84 | - # Execute ctbin, make sure we catch any exception | ||
| 85 | - try: | ||
| 86 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 87 | - except: | ||
| 88 | - pass | 81 | + # Check if execution of wrong command fails |
| 82 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 83 | + 'Self test of test script') | ||
| 89 | 84 | ||
| 90 | # Check if execution was successful | 85 | # Check if execution was successful |
| 91 | - self.test_assert(rc == 0, | ||
| 92 | - "Successful ctbin execution on command line") | 86 | + self.test_assert(self._execute(cmd) == 0, |
| 87 | + 'Check successful execution from command line') | ||
| 93 | 88 | ||
| 94 | # Load counts cube and check content. | 89 | # Load counts cube and check content. |
| 95 | - evt = gammalib.GCTAEventCube("cntmap_cmd1.fits") | 90 | + evt = gammalib.GCTAEventCube('cntmap_cmd1.fits') |
| 96 | self._check_cube(evt, 5542) | 91 | self._check_cube(evt, 5542) |
| 97 | 92 | ||
| 98 | # Setup ctbin command | 93 | # Setup ctbin command |
| @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 102 | ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ | 97 | ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ |
| 103 | ' xref=83.63 yref=22.01 proj="CAR"' | 98 | ' xref=83.63 yref=22.01 proj="CAR"' |
| 104 | 99 | ||
| 105 | - # Execute ctbin, make sure we catch any exception | ||
| 106 | - try: | ||
| 107 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 108 | - except: | ||
| 109 | - pass | ||
| 110 | - | ||
| 111 | # Check if execution failed | 100 | # Check if execution failed |
| 112 | - self.test_assert(rc != 0, | ||
| 113 | - "Failure of ctbin execution on command line") | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 114 | 103 | ||
| 115 | # Return | 104 | # Return |
| 116 | return | 105 | return |
| @@ -118,23 +107,23 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,23 +107,23 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Test ctbin from Python | 107 | # Test ctbin from Python |
| 119 | def _test_python(self): | 108 | def _test_python(self): |
| 120 | """ | 109 | """ |
| 121 | - Test ctbin from Python. | 110 | + Test ctbin from Python |
| 122 | """ | 111 | """ |
| 123 | # Set-up ctbin | 112 | # Set-up ctbin |
| 124 | bin = ctools.ctbin() | 113 | bin = ctools.ctbin() |
| 125 | - bin["inobs"] = self._events_name | ||
| 126 | - bin["outcube"] = "cntmap.fits" | ||
| 127 | - bin["ebinalg"] = "LOG" | ||
| 128 | - bin["emin"] = 0.1 | ||
| 129 | - bin["emax"] = 100.0 | ||
| 130 | - bin["enumbins"] = 20 | ||
| 131 | - bin["nxpix"] = 200 | ||
| 132 | - bin["nypix"] = 200 | ||
| 133 | - bin["binsz"] = 0.02 | ||
| 134 | - bin["coordsys"] = "CEL" | ||
| 135 | - bin["proj"] = "CAR" | ||
| 136 | - bin["xref"] = 83.63 | ||
| 137 | - bin["yref"] = 22.01 | 114 | + bin['inobs'] = self._events_name |
| 115 | + bin['outcube'] = 'cntmap.fits' | ||
| 116 | + bin['ebinalg'] = 'LOG' | ||
| 117 | + bin['emin'] = 0.1 | ||
| 118 | + bin['emax'] = 100.0 | ||
| 119 | + bin['enumbins'] = 20 | ||
| 120 | + bin['nxpix'] = 200 | ||
| 121 | + bin['nypix'] = 200 | ||
| 122 | + bin['binsz'] = 0.02 | ||
| 123 | + bin['coordsys'] = 'CEL' | ||
| 124 | + bin['proj'] = 'CAR' | ||
| 125 | + bin['xref'] = 83.63 | ||
| 126 | + bin['yref'] = 22.01 | ||
| 138 | 127 | ||
| 139 | # Run ctbin tool | 128 | # Run ctbin tool |
| 140 | bin.run() | 129 | bin.run() |
| @@ -160,44 +149,37 @@ class Test(gammalib.GPythonTestSuite): | @@ -160,44 +149,37 @@ class Test(gammalib.GPythonTestSuite): | ||
| 160 | self._check_observation(cpy_bin, 0) | 149 | self._check_observation(cpy_bin, 0) |
| 161 | self._check_cube(cpy_bin.cube(), 0) | 150 | self._check_cube(cpy_bin.cube(), 0) |
| 162 | 151 | ||
| 163 | - # Clear and run copy of ctbin again | ||
| 164 | - #cpy_bin.clear() | ||
| 165 | - #cpy_bin.run() | ||
| 166 | -#RuntimeError: *** ERROR in GXmlAttribute::value(std::string): Invalid XML attribute value: *** ERROR in GPythonTestSuite::test: <type 'exceptions.RuntimeError'> | ||
| 167 | -#*** ERROR in GApplicationPars::operator[](std::string&): Invalid argument. Parameter "debug" has not been found in parameter file. | ||
| 168 | -#Please specify a valid parameter name. | ||
| 169 | - | ||
| 170 | # Save counts cube | 152 | # Save counts cube |
| 171 | bin.save() | 153 | bin.save() |
| 172 | 154 | ||
| 173 | # Load counts cube and check content. | 155 | # Load counts cube and check content. |
| 174 | - evt = gammalib.GCTAEventCube("cntmap.fits") | 156 | + evt = gammalib.GCTAEventCube('cntmap.fits') |
| 175 | self._check_cube(evt, 5542) | 157 | self._check_cube(evt, 5542) |
| 176 | 158 | ||
| 177 | # Prepare observation container for stacked analysis | 159 | # Prepare observation container for stacked analysis |
| 178 | cta = gammalib.GCTAObservation(self._events_name) | 160 | cta = gammalib.GCTAObservation(self._events_name) |
| 179 | obs = gammalib.GObservations() | 161 | obs = gammalib.GObservations() |
| 180 | - cta.id("0001") | 162 | + cta.id('0001') |
| 181 | obs.append(cta) | 163 | obs.append(cta) |
| 182 | - cta.id("0002") | 164 | + cta.id('0002') |
| 183 | obs.append(cta) | 165 | obs.append(cta) |
| 184 | - cta.id("0003") | 166 | + cta.id('0003') |
| 185 | obs.append(cta) | 167 | obs.append(cta) |
| 186 | 168 | ||
| 187 | # Set-up ctbin using an observation container | 169 | # Set-up ctbin using an observation container |
| 188 | bin = ctools.ctbin(obs) | 170 | bin = ctools.ctbin(obs) |
| 189 | - bin["outcube"] = "cntmap.fits" | ||
| 190 | - bin["ebinalg"] = "LOG" | ||
| 191 | - bin["emin"] = 0.1 | ||
| 192 | - bin["emax"] = 100.0 | ||
| 193 | - bin["enumbins"] = 20 | ||
| 194 | - bin["nxpix"] = 200 | ||
| 195 | - bin["nypix"] = 200 | ||
| 196 | - bin["binsz"] = 0.02 | ||
| 197 | - bin["coordsys"] = "CEL" | ||
| 198 | - bin["proj"] = "CAR" | ||
| 199 | - bin["xref"] = 83.63 | ||
| 200 | - bin["yref"] = 22.01 | 171 | + bin['outcube'] = 'cntmap.fits' |
| 172 | + bin['ebinalg'] = 'LOG' | ||
| 173 | + bin['emin'] = 0.1 | ||
| 174 | + bin['emax'] = 100.0 | ||
| 175 | + bin['enumbins'] = 20 | ||
| 176 | + bin['nxpix'] = 200 | ||
| 177 | + bin['nypix'] = 200 | ||
| 178 | + bin['binsz'] = 0.02 | ||
| 179 | + bin['coordsys'] = 'CEL' | ||
| 180 | + bin['proj'] = 'CAR' | ||
| 181 | + bin['xref'] = 83.63 | ||
| 182 | + bin['yref'] = 22.01 | ||
| 201 | 183 | ||
| 202 | # Run ctbin tool | 184 | # Run ctbin tool |
| 203 | bin.run() | 185 | bin.run() |
| @@ -209,65 +191,58 @@ class Test(gammalib.GPythonTestSuite): | @@ -209,65 +191,58 @@ class Test(gammalib.GPythonTestSuite): | ||
| 209 | 191 | ||
| 210 | # Set-up ctbin using an observation container | 192 | # Set-up ctbin using an observation container |
| 211 | bin = ctools.ctbin(obs) | 193 | bin = ctools.ctbin(obs) |
| 212 | - bin["outcube"] = "cntmap2.fits" | ||
| 213 | - bin["ebinalg"] = "LOG" | ||
| 214 | - bin["emin"] = 0.1 | ||
| 215 | - bin["emax"] = 100.0 | ||
| 216 | - bin["enumbins"] = 20 | ||
| 217 | - bin["nxpix"] = 200 | ||
| 218 | - bin["nypix"] = 200 | ||
| 219 | - bin["binsz"] = 0.02 | ||
| 220 | - bin["coordsys"] = "CEL" | ||
| 221 | - bin["proj"] = "CAR" | ||
| 222 | - bin["xref"] = 83.63 | ||
| 223 | - bin["yref"] = 22.01 | 194 | + bin['outcube'] = 'cntmap2.fits' |
| 195 | + bin['ebinalg'] = 'LOG' | ||
| 196 | + bin['emin'] = 0.1 | ||
| 197 | + bin['emax'] = 100.0 | ||
| 198 | + bin['enumbins'] = 20 | ||
| 199 | + bin['nxpix'] = 200 | ||
| 200 | + bin['nypix'] = 200 | ||
| 201 | + bin['binsz'] = 0.02 | ||
| 202 | + bin['coordsys'] = 'CEL' | ||
| 203 | + bin['proj'] = 'CAR' | ||
| 204 | + bin['xref'] = 83.63 | ||
| 205 | + bin['yref'] = 22.01 | ||
| 224 | 206 | ||
| 225 | # Execute ctbin tool | 207 | # Execute ctbin tool |
| 226 | bin.execute() | 208 | bin.execute() |
| 227 | 209 | ||
| 228 | # Load counts cube and check content. | 210 | # Load counts cube and check content. |
| 229 | - evt = gammalib.GCTAEventCube("cntmap2.fits") | 211 | + evt = gammalib.GCTAEventCube('cntmap2.fits') |
| 230 | self._check_cube(evt, 5542, multiplier=3) | 212 | self._check_cube(evt, 5542, multiplier=3) |
| 231 | 213 | ||
| 232 | - # Clear tool | ||
| 233 | - #bin.clear() | ||
| 234 | -#what(): *** ERROR in GApplicationPars::write(std::string&): Unable to open parameter file "pfiles/". | ||
| 235 | - | ||
| 236 | - # Check content of observation and cube | ||
| 237 | - #self.test_value(bin.obs().size(), 0, "There is no observation") | ||
| 238 | - #self.test_value(bin.cube().size(), 0, "0 event bins") | ||
| 239 | - #self.test_value(bin.cube().number(), 0, "0 events") | ||
| 240 | - | ||
| 241 | # Return | 214 | # Return |
| 242 | return | 215 | return |
| 243 | 216 | ||
| 244 | # Check observation | 217 | # Check observation |
| 245 | def _check_observation(self, ctbin, nevents, multiplier=1): | 218 | def _check_observation(self, ctbin, nevents, multiplier=1): |
| 246 | """ | 219 | """ |
| 247 | - Check content of an observation. | 220 | + Check content of an observation |
| 248 | 221 | ||
| 249 | - Args: | ||
| 250 | - ctbin: ctbin instance | ||
| 251 | - nevents: Expected number of events | ||
| 252 | - | ||
| 253 | - Kwargs: | ||
| 254 | - multiplier: Observation multiplier | 222 | + Parameters |
| 223 | + ---------- | ||
| 224 | + ctbin : `~ctools.ctbin` | ||
| 225 | + ctbin instance | ||
| 226 | + nevents : int | ||
| 227 | + Expected number of events | ||
| 228 | + multiplier : float, optional | ||
| 229 | + Observation multiplier | ||
| 255 | """ | 230 | """ |
| 256 | # Test observation container | 231 | # Test observation container |
| 257 | obs = gammalib.GCTAObservation(ctbin.obs()[0]) | 232 | obs = gammalib.GCTAObservation(ctbin.obs()[0]) |
| 258 | pnt = obs.pointing() | 233 | pnt = obs.pointing() |
| 259 | self.test_value(ctbin.obs().size(), 1, | 234 | self.test_value(ctbin.obs().size(), 1, |
| 260 | - "There is one observation") | ||
| 261 | - self.test_assert(obs.instrument() == "CTA", | ||
| 262 | - "Observation is CTA observation") | 235 | + 'There is one observation') |
| 236 | + self.test_assert(obs.instrument() == 'CTA', | ||
| 237 | + 'Observation is CTA observation') | ||
| 263 | self.test_value(obs.ontime(), 1800.0*multiplier, 1.0e-6, | 238 | self.test_value(obs.ontime(), 1800.0*multiplier, 1.0e-6, |
| 264 | - "Ontime is 1800 sec") | 239 | + 'Ontime is 1800 sec') |
| 265 | self.test_value(obs.livetime(), 1710.0*multiplier, 1.0e-6, | 240 | self.test_value(obs.livetime(), 1710.0*multiplier, 1.0e-6, |
| 266 | - "Livetime is 1710 sec") | 241 | + 'Livetime is 1710 sec') |
| 267 | self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, | 242 | self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, |
| 268 | - "Pointing Right Ascension is 83.63 deg") | 243 | + 'Pointing Right Ascension is 83.63 deg') |
| 269 | self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, | 244 | self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, |
| 270 | - "Pointing Declination is 22.01 deg") | 245 | + 'Pointing Declination is 22.01 deg') |
| 271 | 246 | ||
| 272 | # Test event cube | 247 | # Test event cube |
| 273 | self._check_cube(obs.events(), nevents, multiplier=multiplier) | 248 | self._check_cube(obs.events(), nevents, multiplier=multiplier) |
| @@ -278,19 +253,21 @@ class Test(gammalib.GPythonTestSuite): | @@ -278,19 +253,21 @@ class Test(gammalib.GPythonTestSuite): | ||
| 278 | # Check event cube | 253 | # Check event cube |
| 279 | def _check_cube(self, cube, nevents, multiplier=1): | 254 | def _check_cube(self, cube, nevents, multiplier=1): |
| 280 | """ | 255 | """ |
| 281 | - Check content of event cube." | 256 | + Check content of event cube |
| 282 | 257 | ||
| 283 | - Args: | ||
| 284 | - cube: Event cube | ||
| 285 | - nevents: Expected number of events. | ||
| 286 | - | ||
| 287 | - Kwargs: | ||
| 288 | - multiplier: Event number multiplier | 258 | + Parameters |
| 259 | + ---------- | ||
| 260 | + cube : `~gammalib.GCTAEventCube` | ||
| 261 | + Event cube | ||
| 262 | + nevents : int | ||
| 263 | + Expected number of events | ||
| 264 | + multiplier : float | ||
| 265 | + Event number multiplier | ||
| 289 | """ | 266 | """ |
| 290 | # Test event cube | 267 | # Test event cube |
| 291 | - self.test_value(cube.size(), 800000, "800000 event bins") | 268 | + self.test_value(cube.size(), 800000, '800000 event bins') |
| 292 | self.test_value(cube.number(), nevents*multiplier, | 269 | self.test_value(cube.number(), nevents*multiplier, |
| 293 | - str(nevents*multiplier)+" events") | 270 | + str(nevents*multiplier)+' events') |
| 294 | 271 | ||
| 295 | # Return | 272 | # Return |
| 296 | return | 273 | return |
test/test_ctbkgcube.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================= # | 26 | # ============================= # |
| 27 | # Test class for ctbkgcube tool # | 27 | # Test class for ctbkgcube tool # |
| 28 | # ============================= # | 28 | # ============================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | Test class for ctbkgcube tool. | 31 | Test class for ctbkgcube tool. |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctbkgcube') | 50 | self.name('ctbkgcube') |
| @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 61 | """ | 61 | """ |
| 62 | Test ctbkgcube on the command line. | 62 | Test ctbkgcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctbkgcube = '../src/ctbkgcube/ctbkgcube' | ||
| 67 | - else: | ||
| 68 | - ctbkgcube = 'ctbkgcube' | 64 | + # Set tool name |
| 65 | + ctbkgcube = self._tool('ctbkgcube') | ||
| 69 | 66 | ||
| 70 | # Setup ctbkgcube command | 67 | # Setup ctbkgcube command |
| 71 | cmd = ctbkgcube+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctbkgcube+' inobs="data/crab_events.fits"'+ \ |
| @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 79 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 76 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 80 | ' logfile="ctbkgcube_cmd1.log" chatter=1' | 77 | ' logfile="ctbkgcube_cmd1.log" chatter=1' |
| 81 | 78 | ||
| 82 | - # Execute ctbkgcube, make sure we catch any exception | ||
| 83 | - try: | ||
| 84 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 85 | - except: | ||
| 86 | - pass | 79 | + # Check if execution of wrong command fails |
| 80 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 81 | + 'Self test of test script') | ||
| 87 | 82 | ||
| 88 | # Check if execution was successful | 83 | # Check if execution was successful |
| 89 | - self.test_assert(rc == 0, | ||
| 90 | - 'Successful ctbkgcube execution on command line') | 84 | + self.test_assert(self._execute(cmd) == 0, |
| 85 | + 'Check successful execution from command line') | ||
| 91 | 86 | ||
| 92 | # Check result file | 87 | # Check result file |
| 93 | self._check_result_file('ctbkgcube_cmd1.fits') | 88 | self._check_result_file('ctbkgcube_cmd1.fits') |
| @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 104 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 99 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 105 | ' logfile="ctbkgcube_cmd2.log" chatter=1' | 100 | ' logfile="ctbkgcube_cmd2.log" chatter=1' |
| 106 | 101 | ||
| 107 | - # Execute ctbkgcube, make sure we catch any exception | ||
| 108 | - try: | ||
| 109 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 110 | - except: | ||
| 111 | - pass | ||
| 112 | - | ||
| 113 | # Check if execution failed | 102 | # Check if execution failed |
| 114 | - self.test_assert(rc != 0, | ||
| 115 | - 'Failure of ctbkgcube execution on command line') | 103 | + self.test_assert(self._execute(cmd) != 0, |
| 104 | + 'Check invalid input file when executed from command line') | ||
| 116 | 105 | ||
| 117 | # Return | 106 | # Return |
| 118 | return | 107 | return |
| @@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 120 | # Test ctbkgcube from Python | 109 | # Test ctbkgcube from Python |
| 121 | def _test_python(self): | 110 | def _test_python(self): |
| 122 | """ | 111 | """ |
| 123 | - Test ctbkgcube from Python. | 112 | + Test ctbkgcube from Python |
| 124 | """ | 113 | """ |
| 125 | # Set-up ctbkgcube | 114 | # Set-up ctbkgcube |
| 126 | bkgcube = ctools.ctbkgcube() | 115 | bkgcube = ctools.ctbkgcube() |
| @@ -159,7 +148,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -159,7 +148,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 159 | # Check result file | 148 | # Check result file |
| 160 | def _check_result_file(self, filename): | 149 | def _check_result_file(self, filename): |
| 161 | """ | 150 | """ |
| 162 | - Check result file. | 151 | + Check result file |
| 163 | """ | 152 | """ |
| 164 | # Open result file | 153 | # Open result file |
| 165 | result = gammalib.GCTACubeBackground(filename) | 154 | result = gammalib.GCTACubeBackground(filename) |
test/test_ctbutterfly.py
| @@ -18,15 +18,15 @@ | @@ -18,15 +18,15 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # =============================== # | 26 | # =============================== # |
| 27 | # Test class for ctbutterfly tool # | 27 | # Test class for ctbutterfly tool # |
| 28 | # =============================== # | 28 | # =============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | Test class for ctbutterfly tool. | 31 | Test class for ctbutterfly tool. |
| 32 | """ | 32 | """ |
| @@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 36 | Constructor. | 36 | Constructor. |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 61 | """ | 61 | """ |
| 62 | Test ctbutterfly on the command line. | 62 | Test ctbutterfly on the command line. |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctbutterfly = '../src/ctbutterfly/ctbutterfly' | ||
| 67 | - else: | ||
| 68 | - ctbutterfly = 'ctbutterfly' | 64 | + # Set tool name |
| 65 | + ctbutterfly = self._tool('ctbutterfly') | ||
| 69 | 66 | ||
| 70 | # Setup ctbutterfly command | 67 | # Setup ctbutterfly command |
| 71 | cmd = ctbutterfly+' inobs="data/crab_events.fits"'+\ | 68 | cmd = ctbutterfly+' inobs="data/crab_events.fits"'+\ |
| @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 75 | ' emin=0.1 emax=100.0'+ \ | 72 | ' emin=0.1 emax=100.0'+ \ |
| 76 | ' logfile="ctbutterfly_cmd1.log" chatter=1' | 73 | ' logfile="ctbutterfly_cmd1.log" chatter=1' |
| 77 | 74 | ||
| 78 | - # Execute ctbutterfly, make sure we catch any exception | ||
| 79 | - try: | ||
| 80 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 81 | - except: | ||
| 82 | - pass | 75 | + # Check if execution of wrong command fails |
| 76 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 77 | + 'Self test of test script') | ||
| 83 | 78 | ||
| 84 | # Check if execution was successful | 79 | # Check if execution was successful |
| 85 | - self.test_assert(rc == 0, | ||
| 86 | - 'Successful ctbutterfly execution on command line') | 80 | + self.test_assert(self._execute(cmd) == 0, |
| 81 | + 'Check successful execution from command line') | ||
| 87 | 82 | ||
| 88 | # Check result file | 83 | # Check result file |
| 89 | self._check_result_file('ctbutterfly_cmd1.txt') | 84 | self._check_result_file('ctbutterfly_cmd1.txt') |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' emin=0.1 emax=100.0'+ \ | 91 | ' emin=0.1 emax=100.0'+ \ |
| 97 | ' logfile="ctbutterfly_cmd2.log" chatter=1' | 92 | ' logfile="ctbutterfly_cmd2.log" chatter=1' |
| 98 | 93 | ||
| 99 | - # Execute ctbutterfly, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - 'Failure of ctbutterfly execution on command line') | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test ctbutterfly from Python | 101 | # Test ctbutterfly from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test ctbutterfly from Python. | 104 | + Test ctbutterfly from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up ctbutterfly | 106 | # Set-up ctbutterfly |
| 118 | butterfly = ctools.ctbutterfly() | 107 | butterfly = ctools.ctbutterfly() |
| @@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 141 | # Check result file | 130 | # Check result file |
| 142 | def _check_result_file(self, filename): | 131 | def _check_result_file(self, filename): |
| 143 | """ | 132 | """ |
| 144 | - Check result file. | 133 | + Check result file |
| 145 | """ | 134 | """ |
| 146 | # Open result file as CSV file | 135 | # Open result file as CSV file |
| 147 | results = gammalib.GCsv(filename) | 136 | results = gammalib.GCsv(filename) |
test/test_ctcubemask.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================== # | 26 | # ============================== # |
| 27 | # Test class for ctcubemask tool # | 27 | # Test class for ctcubemask tool # |
| 28 | # ============================== # | 28 | # ============================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctcubemask tool. | 31 | + Test class for ctcubemask tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctcubemask') | 50 | self.name('ctcubemask') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctcubemask on command line | 59 | # Test ctcubemask on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctcubemask on the command line. | 62 | + Test ctcubemask on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctcubemask = '../src/ctcubemask/ctcubemask' | ||
| 67 | - else: | ||
| 68 | - ctcubemask = 'ctcubemask' | 64 | + # Set tool name |
| 65 | + ctcubemask = self._tool('ctcubemask') | ||
| 69 | 66 | ||
| 70 | # Setup ctcubemask command | 67 | # Setup ctcubemask command |
| 71 | cmd = ctcubemask+' inobs="data/crab_cntmap.fits"'+ \ | 68 | cmd = ctcubemask+' inobs="data/crab_cntmap.fits"'+ \ |
| @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 75 | ' emin=0.1 emax=100.0'+ \ | 72 | ' emin=0.1 emax=100.0'+ \ |
| 76 | ' logfile="ctcubemask_cmd1.log" chatter=1' | 73 | ' logfile="ctcubemask_cmd1.log" chatter=1' |
| 77 | 74 | ||
| 78 | - # Execute ctcubemask, make sure we catch any exception | ||
| 79 | - try: | ||
| 80 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 81 | - except: | ||
| 82 | - pass | 75 | + # Check if execution of wrong command fails |
| 76 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 77 | + 'Self test of test script') | ||
| 83 | 78 | ||
| 84 | # Check if execution was successful | 79 | # Check if execution was successful |
| 85 | - self.test_assert(rc == 0, | ||
| 86 | - 'Successful ctcubemask execution on command line') | 80 | + self.test_assert(self._execute(cmd) == 0, |
| 81 | + 'Check successful execution from command line') | ||
| 87 | 82 | ||
| 88 | # Check result file | 83 | # Check result file |
| 89 | self._check_result_file('ctcubemask_cmd1.fits') | 84 | self._check_result_file('ctcubemask_cmd1.fits') |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' emin=0.1 emax=100.0'+ \ | 91 | ' emin=0.1 emax=100.0'+ \ |
| 97 | ' logfile="ctcubemask_cmd2.log" chatter=2' | 92 | ' logfile="ctcubemask_cmd2.log" chatter=2' |
| 98 | 93 | ||
| 99 | - # Execute ctcubemask, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - 'Failure of ctcubemask execution on command line') | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test ctcubemask from Python | 101 | # Test ctcubemask from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test ctcubemask from Python. | 104 | + Test ctcubemask from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up ctcubemask | 106 | # Set-up ctcubemask |
| 118 | mask = ctools.ctcubemask() | 107 | mask = ctools.ctcubemask() |
| @@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -141,7 +130,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 141 | # Check result file | 130 | # Check result file |
| 142 | def _check_result_file(self, filename): | 131 | def _check_result_file(self, filename): |
| 143 | """ | 132 | """ |
| 144 | - Check result file. | 133 | + Check result file |
| 145 | """ | 134 | """ |
| 146 | # Load counts cube | 135 | # Load counts cube |
| 147 | cube = gammalib.GCTAEventCube(filename) | 136 | cube = gammalib.GCTAEventCube(filename) |
test/test_ctedispcube.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | -# ============================= # | 26 | +# =============================== # |
| 27 | # Test class for ctedispcube tool # | 27 | # Test class for ctedispcube tool # |
| 28 | -# ============================= # | ||
| 29 | -class Test(gammalib.GPythonTestSuite): | 28 | +# =============================== # |
| 29 | +class Test(test): | ||
| 30 | """ | 30 | """ |
| 31 | - Test class for ctedispcube tool. | 31 | + Test class for ctedispcube tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctedispcube') | 50 | self.name('ctedispcube') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctedispcube on command line | 59 | # Test ctedispcube on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctedispcube on the command line. | 62 | + Test ctedispcube on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctedispcube = '../src/ctedispcube/ctedispcube' | ||
| 67 | - else: | ||
| 68 | - ctedispcube = 'ctedispcube' | 64 | + # Set tool name |
| 65 | + ctedispcube = self._tool('ctedispcube') | ||
| 69 | 66 | ||
| 70 | # Setup ctedispcube command | 67 | # Setup ctedispcube command |
| 71 | cmd = ctedispcube+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctedispcube+' inobs="data/crab_events.fits"'+ \ |
| @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 78 | ' migramax=2.0 migrabins=10'+ \ | 75 | ' migramax=2.0 migrabins=10'+ \ |
| 79 | ' logfile="ctedispcube_cmd1.log" chatter=1' | 76 | ' logfile="ctedispcube_cmd1.log" chatter=1' |
| 80 | 77 | ||
| 81 | - # Execute ctedispcube, make sure we catch any exception | ||
| 82 | - try: | ||
| 83 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 84 | - except: | ||
| 85 | - pass | 78 | + # Check if execution of wrong command fails |
| 79 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 80 | + 'Self test of test script') | ||
| 86 | 81 | ||
| 87 | # Check if execution was successful | 82 | # Check if execution was successful |
| 88 | - self.test_assert(rc == 0, | ||
| 89 | - 'Successful ctedispcube execution on command line') | 83 | + self.test_assert(self._execute(cmd) == 0, |
| 84 | + 'Check successful execution from command line') | ||
| 90 | 85 | ||
| 91 | # Check result file | 86 | # Check result file |
| 92 | self._check_result_file('ctedispcube_cmd1.fits') | 87 | self._check_result_file('ctedispcube_cmd1.fits') |
| @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 102 | ' migramax=2.0 migrabins=10'+ \ | 97 | ' migramax=2.0 migrabins=10'+ \ |
| 103 | ' logfile="ctedispcube_cmd2.log" chatter=2' | 98 | ' logfile="ctedispcube_cmd2.log" chatter=2' |
| 104 | 99 | ||
| 105 | - # Execute ctedispcube, make sure we catch any exception | ||
| 106 | - try: | ||
| 107 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 108 | - except: | ||
| 109 | - pass | ||
| 110 | - | ||
| 111 | # Check if execution failed | 100 | # Check if execution failed |
| 112 | - self.test_assert(rc != 0, | ||
| 113 | - 'Failure of ctedispcube execution on command line') | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 114 | 103 | ||
| 115 | # Return | 104 | # Return |
| 116 | return | 105 | return |
| @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Test ctedispcube from Python | 107 | # Test ctedispcube from Python |
| 119 | def _test_python(self): | 108 | def _test_python(self): |
| 120 | """ | 109 | """ |
| 121 | - Test ctedispcube from Python. | 110 | + Test ctedispcube from Python |
| 122 | """ | 111 | """ |
| 123 | # Set-up ctedispcube | 112 | # Set-up ctedispcube |
| 124 | edispcube = ctools.ctedispcube() | 113 | edispcube = ctools.ctedispcube() |
| @@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 157 | # Check result file | 146 | # Check result file |
| 158 | def _check_result_file(self, filename): | 147 | def _check_result_file(self, filename): |
| 159 | """ | 148 | """ |
| 160 | - Check result file. | 149 | + Check result file |
| 161 | """ | 150 | """ |
| 162 | # Open result file | 151 | # Open result file |
| 163 | result = gammalib.GCTACubeEdisp(filename) | 152 | result = gammalib.GCTACubeEdisp(filename) |
test/test_cterror.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # =========================== # | 26 | # =========================== # |
| 27 | # Test class for cterror tool # | 27 | # Test class for cterror tool # |
| 28 | # =========================== # | 28 | # =========================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for cterror tool. | 31 | + Test class for cterror tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| @@ -36,14 +36,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -36,14 +36,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 36 | Constructor. | 36 | Constructor. |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Set members | 41 | # Set members |
| 42 | - self.events_name = "data/crab_events.fits" | ||
| 43 | - self.model_name = "data/crab.xml" | ||
| 44 | - self.result_name = "cterror_result.xml" | ||
| 45 | - self.caldb = "irf" | ||
| 46 | - self.irf = "cta_dummy_irf" | 42 | + self.events_name = 'data/crab_events.fits' |
| 43 | + self.model_name = 'data/crab.xml' | ||
| 44 | + self.result_name = 'cterror_result.xml' | ||
| 45 | + self.caldb = 'irf' | ||
| 46 | + self.irf = 'cta_dummy_irf' | ||
| 47 | 47 | ||
| 48 | # Return | 48 | # Return |
| 49 | return | 49 | return |
| @@ -51,7 +51,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -51,7 +51,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 51 | # Set test functions | 51 | # Set test functions |
| 52 | def set(self): | 52 | def set(self): |
| 53 | """ | 53 | """ |
| 54 | - Set all test functions. | 54 | + Set all test functions |
| 55 | """ | 55 | """ |
| 56 | # Set test name | 56 | # Set test name |
| 57 | self.name('cterror') | 57 | self.name('cterror') |
| @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | # Test cterror on command line | 66 | # Test cterror on command line |
| 67 | def _test_cmd(self): | 67 | def _test_cmd(self): |
| 68 | """ | 68 | """ |
| 69 | - Test cterror on the command line. | 69 | + Test cterror on the command line |
| 70 | """ | 70 | """ |
| 71 | - # Kluge to set the command (installed version has no README file) | ||
| 72 | - if os.path.isfile('README.md'): | ||
| 73 | - cterror = '../src/cterror/cterror' | ||
| 74 | - else: | ||
| 75 | - cterror = 'cterror' | 71 | + # Set tool name |
| 72 | + cterror = self._tool('cterror') | ||
| 76 | 73 | ||
| 77 | # Setup cterror command | 74 | # Setup cterror command |
| 78 | cmd = cterror+' inobs="data/crab_events.fits"'+ \ | 75 | cmd = cterror+' inobs="data/crab_events.fits"'+ \ |
| @@ -81,15 +78,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -81,15 +78,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 81 | ' outmodel="cterror_cmd1.xml"'+ \ | 78 | ' outmodel="cterror_cmd1.xml"'+ \ |
| 82 | ' logfile="cterror_cmd1.log" chatter=1' | 79 | ' logfile="cterror_cmd1.log" chatter=1' |
| 83 | 80 | ||
| 84 | - # Execute cterror, make sure we catch any exception | ||
| 85 | - try: | ||
| 86 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 87 | - except: | ||
| 88 | - pass | 81 | + # Check if execution of wrong command fails |
| 82 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 83 | + 'Self test of test script') | ||
| 89 | 84 | ||
| 90 | # Check if execution was successful | 85 | # Check if execution was successful |
| 91 | - self.test_assert(rc == 0, | ||
| 92 | - 'Successful cterror execution on command line') | 86 | + self.test_assert(self._execute(cmd) == 0, |
| 87 | + 'Check successful execution from command line') | ||
| 93 | 88 | ||
| 94 | # Check result file | 89 | # Check result file |
| 95 | self._check_result_file('cterror_cmd1.xml') | 90 | self._check_result_file('cterror_cmd1.xml') |
| @@ -101,15 +96,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -101,15 +96,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 101 | ' outmodel="cterror_cmd2.xml"'+ \ | 96 | ' outmodel="cterror_cmd2.xml"'+ \ |
| 102 | ' logfile="cterror_cmd2.log" chatter=1' | 97 | ' logfile="cterror_cmd2.log" chatter=1' |
| 103 | 98 | ||
| 104 | - # Execute cterror, make sure we catch any exception | ||
| 105 | - try: | ||
| 106 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 107 | - except: | ||
| 108 | - pass | ||
| 109 | - | ||
| 110 | # Check if execution failed | 99 | # Check if execution failed |
| 111 | - self.test_assert(rc != 0, | ||
| 112 | - 'Failure of cterror execution on command line') | 100 | + self.test_assert(self._execute(cmd) != 0, |
| 101 | + 'Check invalid input file when executed from command line') | ||
| 113 | 102 | ||
| 114 | # Return | 103 | # Return |
| 115 | return | 104 | return |
| @@ -117,7 +106,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -117,7 +106,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 117 | # Test cterror from Python | 106 | # Test cterror from Python |
| 118 | def _test_python(self): | 107 | def _test_python(self): |
| 119 | """ | 108 | """ |
| 120 | - Test cterror from Python. | 109 | + Test cterror from Python |
| 121 | """ | 110 | """ |
| 122 | # Set-up cterror | 111 | # Set-up cterror |
| 123 | error = ctools.cterror() | 112 | error = ctools.cterror() |
| @@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 144 | # Check result file | 133 | # Check result file |
| 145 | def _check_result_file(self, filename): | 134 | def _check_result_file(self, filename): |
| 146 | """ | 135 | """ |
| 147 | - Check result file. | 136 | + Check result file |
| 148 | """ | 137 | """ |
| 149 | # Open result file | 138 | # Open result file |
| 150 | result = gammalib.GModels(filename) | 139 | result = gammalib.GModels(filename) |
test/test_ctexpcube.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================= # | 26 | # ============================= # |
| 27 | # Test class for ctexpcube tool # | 27 | # Test class for ctexpcube tool # |
| 28 | # ============================= # | 28 | # ============================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctexpcube tool. | 31 | + Test class for ctexpcube tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctexpcube') | 50 | self.name('ctexpcube') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctexpcube on command line | 59 | # Test ctexpcube on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctexpcube on the command line. | 62 | + Test ctexpcube on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctexpcube = '../src/ctexpcube/ctexpcube' | ||
| 67 | - else: | ||
| 68 | - ctexpcube = 'ctexpcube' | 64 | + # Set tool name |
| 65 | + ctexpcube = self._tool('ctexpcube') | ||
| 69 | 66 | ||
| 70 | # Setup ctexpcube command | 67 | # Setup ctexpcube command |
| 71 | cmd = ctexpcube+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctexpcube+' inobs="data/crab_events.fits"'+ \ |
| @@ -77,15 +74,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -77,15 +74,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 77 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 74 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 78 | ' logfile="ctexpcube_cmd1.log" chatter=1' | 75 | ' logfile="ctexpcube_cmd1.log" chatter=1' |
| 79 | 76 | ||
| 80 | - # Execute ctexpcube, make sure we catch any exception | ||
| 81 | - try: | ||
| 82 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 83 | - except: | ||
| 84 | - pass | 77 | + # Check if execution of wrong command fails |
| 78 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 79 | + 'Self test of test script') | ||
| 85 | 80 | ||
| 86 | # Check if execution was successful | 81 | # Check if execution was successful |
| 87 | - self.test_assert(rc == 0, | ||
| 88 | - 'Successful ctexpcube execution on command line') | 82 | + self.test_assert(self._execute(cmd) == 0, |
| 83 | + 'Check successful execution from command line') | ||
| 89 | 84 | ||
| 90 | # Check result file | 85 | # Check result file |
| 91 | self._check_result_file('ctexpcube_cmd1.fits') | 86 | self._check_result_file('ctexpcube_cmd1.fits') |
| @@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -100,15 +95,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 100 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 95 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 101 | ' logfile="ctexpcube_cmd2.log" chatter=1' | 96 | ' logfile="ctexpcube_cmd2.log" chatter=1' |
| 102 | 97 | ||
| 103 | - # Execute ctexpcube, make sure we catch any exception | ||
| 104 | - try: | ||
| 105 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 106 | - except: | ||
| 107 | - pass | ||
| 108 | - | ||
| 109 | # Check if execution failed | 98 | # Check if execution failed |
| 110 | - self.test_assert(rc != 0, | ||
| 111 | - 'Failure of ctexpcube execution on command line') | 99 | + self.test_assert(self._execute(cmd) != 0, |
| 100 | + 'Check invalid input file when executed from command line') | ||
| 112 | 101 | ||
| 113 | # Return | 102 | # Return |
| 114 | return | 103 | return |
| @@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -116,7 +105,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 116 | # Test ctexpcube from Python | 105 | # Test ctexpcube from Python |
| 117 | def _test_python(self): | 106 | def _test_python(self): |
| 118 | """ | 107 | """ |
| 119 | - Test ctexpcube from Python. | 108 | + Test ctexpcube from Python |
| 120 | """ | 109 | """ |
| 121 | # Set-up ctexpcube | 110 | # Set-up ctexpcube |
| 122 | expcube = ctools.ctexpcube() | 111 | expcube = ctools.ctexpcube() |
| @@ -153,7 +142,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -153,7 +142,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 153 | # Check result file | 142 | # Check result file |
| 154 | def _check_result_file(self, filename): | 143 | def _check_result_file(self, filename): |
| 155 | """ | 144 | """ |
| 156 | - Check result file. | 145 | + Check result file |
| 157 | """ | 146 | """ |
| 158 | # Open result file | 147 | # Open result file |
| 159 | result = gammalib.GCTACubeExposure(filename) | 148 | result = gammalib.GCTACubeExposure(filename) |
test/test_ctlike.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ========================== # | 26 | # ========================== # |
| 27 | # Test class for ctlike tool # | 27 | # Test class for ctlike tool # |
| 28 | # ========================== # | 28 | # ========================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctlike tool. | 31 | + Test class for ctlike tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctlike') | 50 | self.name('ctlike') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctlike on command line | 59 | # Test ctlike on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctlike on the command line. | 62 | + Test ctlike on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctlike = '../src/ctlike/ctlike' | ||
| 67 | - else: | ||
| 68 | - ctlike = 'ctlike' | 64 | + # Set tool name |
| 65 | + ctlike = self._tool('ctlike') | ||
| 69 | 66 | ||
| 70 | # Setup ctlike command | 67 | # Setup ctlike command |
| 71 | cmd = ctlike+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctlike+' inobs="data/crab_events.fits"'+ \ |
| @@ -74,15 +71,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -74,15 +71,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 74 | ' outmodel="ctlike_cmd1.xml"'+ \ | 71 | ' outmodel="ctlike_cmd1.xml"'+ \ |
| 75 | ' logfile="ctlike_cmd1.log" chatter=1' | 72 | ' logfile="ctlike_cmd1.log" chatter=1' |
| 76 | 73 | ||
| 77 | - # Execute ctlike, make sure we catch any exception | ||
| 78 | - try: | ||
| 79 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 80 | - except: | ||
| 81 | - pass | 74 | + # Check if execution of wrong command fails |
| 75 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 76 | + 'Self test of test script') | ||
| 82 | 77 | ||
| 83 | # Check if execution was successful | 78 | # Check if execution was successful |
| 84 | - self.test_assert(rc == 0, | ||
| 85 | - 'Successful ctlike execution on command line') | 79 | + self.test_assert(self._execute(cmd) == 0, |
| 80 | + 'Check successful execution from command line') | ||
| 86 | 81 | ||
| 87 | # Check result file | 82 | # Check result file |
| 88 | self._check_result_file('ctlike_cmd1.xml') | 83 | self._check_result_file('ctlike_cmd1.xml') |
| @@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -94,15 +89,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 94 | ' outmodel="ctlike_cmd2.xml"'+ \ | 89 | ' outmodel="ctlike_cmd2.xml"'+ \ |
| 95 | ' logfile="ctlike_cmd2.log" chatter=1' | 90 | ' logfile="ctlike_cmd2.log" chatter=1' |
| 96 | 91 | ||
| 97 | - # Execute ctlike, make sure we catch any exception | ||
| 98 | - try: | ||
| 99 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 100 | - except: | ||
| 101 | - pass | ||
| 102 | - | ||
| 103 | # Check if execution failed | 92 | # Check if execution failed |
| 104 | - self.test_assert(rc != 0, | ||
| 105 | - 'Failure of ctlike execution on command line') | 93 | + self.test_assert(self._execute(cmd) != 0, |
| 94 | + 'Check invalid input file when executed from command line') | ||
| 106 | 95 | ||
| 107 | # Return | 96 | # Return |
| 108 | return | 97 | return |
| @@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -110,7 +99,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 110 | # Test ctlike from Python | 99 | # Test ctlike from Python |
| 111 | def _test_python(self): | 100 | def _test_python(self): |
| 112 | """ | 101 | """ |
| 113 | - Test ctlike from Python. | 102 | + Test ctlike from Python |
| 114 | """ | 103 | """ |
| 115 | # Set-up ctlike | 104 | # Set-up ctlike |
| 116 | like = ctools.ctlike() | 105 | like = ctools.ctlike() |
| @@ -136,7 +125,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -136,7 +125,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 136 | # Check result file | 125 | # Check result file |
| 137 | def _check_result_file(self, filename): | 126 | def _check_result_file(self, filename): |
| 138 | """ | 127 | """ |
| 139 | - Check result file. | 128 | + Check result file |
| 140 | """ | 129 | """ |
| 141 | # Open result file | 130 | # Open result file |
| 142 | result = gammalib.GModels(filename) | 131 | result = gammalib.GModels(filename) |
test/test_ctmapcube.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================= # | 26 | # ============================= # |
| 27 | # Test class for ctmapcube tool # | 27 | # Test class for ctmapcube tool # |
| 28 | # ============================= # | 28 | # ============================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctmapcube tool. | 31 | + Test class for ctmapcube tool |
| 32 | 32 | ||
| 33 | This test class makes unit tests for the ctmapcube tool by using it from | 33 | This test class makes unit tests for the ctmapcube tool by using it from |
| 34 | the command line and from Python. | 34 | the command line and from Python. |
| @@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -37,13 +37,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| 40 | - Constructor. | 40 | + Constructor |
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | 43 | + test.__init__(self) |
| 44 | 44 | ||
| 45 | # Set members | 45 | # Set members |
| 46 | - self._model_name = "data/crab.xml" | 46 | + self._model_name = 'data/crab.xml' |
| 47 | 47 | ||
| 48 | # Return | 48 | # Return |
| 49 | return | 49 | return |
| @@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -51,14 +51,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 51 | # Set test functions | 51 | # Set test functions |
| 52 | def set(self): | 52 | def set(self): |
| 53 | """ | 53 | """ |
| 54 | - Set all test functions. | 54 | + Set all test functions |
| 55 | """ | 55 | """ |
| 56 | # Set test name | 56 | # Set test name |
| 57 | - self.name("ctmapcube") | 57 | + self.name('ctmapcube') |
| 58 | 58 | ||
| 59 | # Append tests | 59 | # Append tests |
| 60 | - self.append(self._test_cmd, "Test ctmapcube on command line") | ||
| 61 | - self.append(self._test_python, "Test ctmapcube from Python") | 60 | + self.append(self._test_cmd, 'Test ctmapcube on command line') |
| 61 | + self.append(self._test_python, 'Test ctmapcube from Python') | ||
| 62 | 62 | ||
| 63 | # Return | 63 | # Return |
| 64 | return | 64 | return |
| @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,13 +66,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | # Test ctmapcube on command line | 66 | # Test ctmapcube on command line |
| 67 | def _test_cmd(self): | 67 | def _test_cmd(self): |
| 68 | """ | 68 | """ |
| 69 | - Test ctmapcube on the command line. | 69 | + Test ctmapcube on the command line |
| 70 | """ | 70 | """ |
| 71 | - # Kluge to set the command (installed version has no README file) | ||
| 72 | - if os.path.isfile("README.md"): | ||
| 73 | - ctmapcube = "../src/ctmapcube/ctmapcube" | ||
| 74 | - else: | ||
| 75 | - ctmapcube = "ctmapcube" | 71 | + # Set tool name |
| 72 | + ctmapcube = self._tool('ctmapcube') | ||
| 76 | 73 | ||
| 77 | # Setup ctmapcube command | 74 | # Setup ctmapcube command |
| 78 | cmd = ctmapcube+' inmodel="'+self._model_name+'"'+ \ | 75 | cmd = ctmapcube+' inmodel="'+self._model_name+'"'+ \ |
| @@ -82,19 +79,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -82,19 +79,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 82 | ' xref=83.63 yref=22.01 proj=CAR'+ \ | 79 | ' xref=83.63 yref=22.01 proj=CAR'+ \ |
| 83 | ' logfile="ctmapcube_cmd1.log" chatter=1' | 80 | ' logfile="ctmapcube_cmd1.log" chatter=1' |
| 84 | 81 | ||
| 85 | - # Execute ctmapcube, make sure we catch any exception | ||
| 86 | - try: | ||
| 87 | - #rc = os.system(cmd) | ||
| 88 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 89 | - except: | ||
| 90 | - pass | 82 | + # Check if execution of wrong command fails |
| 83 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 84 | + 'Self test of test script') | ||
| 91 | 85 | ||
| 92 | # Check if execution was successful | 86 | # Check if execution was successful |
| 93 | - self.test_assert(rc == 0, | ||
| 94 | - "Successful ctmapcube execution on command line") | 87 | + self.test_assert(self._execute(cmd) == 0, |
| 88 | + 'Check successful execution from command line') | ||
| 95 | 89 | ||
| 96 | # Check map cube | 90 | # Check map cube |
| 97 | - self._check_cube("ctmapcube_cmd1.fits") | 91 | + self._check_cube('ctmapcube_cmd1.fits') |
| 98 | 92 | ||
| 99 | # Setup ctmapcube command | 93 | # Setup ctmapcube command |
| 100 | cmd = ctmapcube+' inmodel="events_that_do_not_exist.fits"'+ \ | 94 | cmd = ctmapcube+' inmodel="events_that_do_not_exist.fits"'+ \ |
| @@ -104,16 +98,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -104,16 +98,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 104 | ' xref=83.63 yref=22.01 proj=CAR'+ \ | 98 | ' xref=83.63 yref=22.01 proj=CAR'+ \ |
| 105 | ' logfile="ctmapcube_cmd2.log"' | 99 | ' logfile="ctmapcube_cmd2.log"' |
| 106 | 100 | ||
| 107 | - # Execute ctmapcube, make sure we catch any exception | ||
| 108 | - try: | ||
| 109 | - #rc = os.system(cmd) | ||
| 110 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 111 | - except: | ||
| 112 | - pass | ||
| 113 | - | ||
| 114 | # Check if execution failed | 101 | # Check if execution failed |
| 115 | - self.test_assert(rc != 0, | ||
| 116 | - "Failure of ctmapcube execution on command line") | 102 | + self.test_assert(self._execute(cmd) != 0, |
| 103 | + 'Check invalid input file when executed from command line') | ||
| 117 | 104 | ||
| 118 | # Return | 105 | # Return |
| 119 | return | 106 | return |
| @@ -121,25 +108,25 @@ class Test(gammalib.GPythonTestSuite): | @@ -121,25 +108,25 @@ class Test(gammalib.GPythonTestSuite): | ||
| 121 | # Test ctmapcube from Python | 108 | # Test ctmapcube from Python |
| 122 | def _test_python(self): | 109 | def _test_python(self): |
| 123 | """ | 110 | """ |
| 124 | - Test ctmapcube from Python. | 111 | + Test ctmapcube from Python |
| 125 | """ | 112 | """ |
| 126 | # Set-up ctmapcube | 113 | # Set-up ctmapcube |
| 127 | mapcube = ctools.ctmapcube() | 114 | mapcube = ctools.ctmapcube() |
| 128 | - mapcube["inmodel"] = self._model_name | ||
| 129 | - mapcube["outcube"] = "ctmapcube_py1.fits" | ||
| 130 | - mapcube["ebinalg"] = "LOG" | ||
| 131 | - mapcube["emin"] = 0.1 | ||
| 132 | - mapcube["emax"] = 100.0 | ||
| 133 | - mapcube["enumbins"] = 20 | ||
| 134 | - mapcube["nxpix"] = 200 | ||
| 135 | - mapcube["nypix"] = 200 | ||
| 136 | - mapcube["binsz"] = 0.02 | ||
| 137 | - mapcube["coordsys"] = "CEL" | ||
| 138 | - mapcube["proj"] = "CAR" | ||
| 139 | - mapcube["xref"] = 83.63 | ||
| 140 | - mapcube["yref"] = 22.01 | ||
| 141 | - mapcube["logfile"] = "ctmapcube_py1.log" | ||
| 142 | - mapcube["chatter"] = 2 | 115 | + mapcube['inmodel'] = self._model_name |
| 116 | + mapcube['outcube'] = 'ctmapcube_py1.fits' | ||
| 117 | + mapcube['ebinalg'] = 'LOG' | ||
| 118 | + mapcube['emin'] = 0.1 | ||
| 119 | + mapcube['emax'] = 100.0 | ||
| 120 | + mapcube['enumbins'] = 20 | ||
| 121 | + mapcube['nxpix'] = 200 | ||
| 122 | + mapcube['nypix'] = 200 | ||
| 123 | + mapcube['binsz'] = 0.02 | ||
| 124 | + mapcube['coordsys'] = 'CEL' | ||
| 125 | + mapcube['proj'] = 'CAR' | ||
| 126 | + mapcube['xref'] = 83.63 | ||
| 127 | + mapcube['yref'] = 22.01 | ||
| 128 | + mapcube['logfile'] = 'ctmapcube_py1.log' | ||
| 129 | + mapcube['chatter'] = 2 | ||
| 143 | 130 | ||
| 144 | # Run ctmapcube tool | 131 | # Run ctmapcube tool |
| 145 | mapcube.logFileOpen() # Make sure we get a log file | 132 | mapcube.logFileOpen() # Make sure we get a log file |
| @@ -149,7 +136,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -149,7 +136,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 149 | mapcube.save() | 136 | mapcube.save() |
| 150 | 137 | ||
| 151 | # Check map cube | 138 | # Check map cube |
| 152 | - self._check_cube("ctmapcube_py1.fits") | 139 | + self._check_cube('ctmapcube_py1.fits') |
| 153 | 140 | ||
| 154 | # Return | 141 | # Return |
| 155 | return | 142 | return |
| @@ -157,22 +144,23 @@ class Test(gammalib.GPythonTestSuite): | @@ -157,22 +144,23 @@ class Test(gammalib.GPythonTestSuite): | ||
| 157 | # Check map cube | 144 | # Check map cube |
| 158 | def _check_cube(self, filename): | 145 | def _check_cube(self, filename): |
| 159 | """ | 146 | """ |
| 160 | - Check content of map cube." | 147 | + Check content of map cube |
| 161 | 148 | ||
| 162 | - Args: | ||
| 163 | - filename: Map cube file name. | 149 | + Parameters |
| 150 | + ---------- | ||
| 151 | + filename : str | ||
| 152 | + Map cube file name. | ||
| 164 | """ | 153 | """ |
| 165 | # Load map cube | 154 | # Load map cube |
| 166 | cube = gammalib.GModelSpatialDiffuseCube(filename) | 155 | cube = gammalib.GModelSpatialDiffuseCube(filename) |
| 167 | - #print(cube) | ||
| 168 | 156 | ||
| 169 | # Test map cube | 157 | # Test map cube |
| 170 | #self.test_value(cube.maps(), 20, "20 maps") | 158 | #self.test_value(cube.maps(), 20, "20 maps") |
| 171 | #self.test_value(cube.pixels(), 40000, "40000 map pixels") | 159 | #self.test_value(cube.pixels(), 40000, "40000 map pixels") |
| 172 | # The map cube is not loaded by default !!!! We should add the method so that | 160 | # The map cube is not loaded by default !!!! We should add the method so that |
| 173 | # the attributes are known !!!! | 161 | # the attributes are known !!!! |
| 174 | - self.test_value(cube.maps(), 0, "20 maps") | ||
| 175 | - self.test_value(cube.pixels(), 0, "40000 map pixels") | 162 | + self.test_value(cube.maps(), 0, '20 maps') |
| 163 | + self.test_value(cube.pixels(), 0, '40000 map pixels') | ||
| 176 | 164 | ||
| 177 | # Return | 165 | # Return |
| 178 | return | 166 | return |
test/test_ctmodel.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # =========================== # | 26 | # =========================== # |
| 27 | # Test class for ctmodel tool # | 27 | # Test class for ctmodel tool # |
| 28 | # =========================== # | 28 | # =========================== # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctmodel tool. | 31 | + Test class for ctmodel tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctmodel') | 50 | self.name('ctmodel') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctmodel on command line | 59 | # Test ctmodel on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctmodel on the command line. | 62 | + Test ctmodel on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctmodel = '../src/ctmodel/ctmodel' | ||
| 67 | - else: | ||
| 68 | - ctmodel = 'ctmodel' | 64 | + # Set tool name |
| 65 | + ctmodel = self._tool('ctmodel') | ||
| 69 | 66 | ||
| 70 | # Setup ctmodel command | 67 | # Setup ctmodel command |
| 71 | cmd = ctmodel+' incube="NONE" inobs="NONE" expcube="NONE"'+\ | 68 | cmd = ctmodel+' incube="NONE" inobs="NONE" expcube="NONE"'+\ |
| @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -79,15 +76,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 79 | ' xref=83.63 yref=22.01'+ \ | 76 | ' xref=83.63 yref=22.01'+ \ |
| 80 | ' logfile="ctmodel_cmd1.log" chatter=1' | 77 | ' logfile="ctmodel_cmd1.log" chatter=1' |
| 81 | 78 | ||
| 82 | - # Execute ctmodel, make sure we catch any exception | ||
| 83 | - try: | ||
| 84 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 85 | - except: | ||
| 86 | - pass | 79 | + # Check if execution of wrong command fails |
| 80 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 81 | + 'Self test of test script') | ||
| 87 | 82 | ||
| 88 | # Check if execution was successful | 83 | # Check if execution was successful |
| 89 | - self.test_assert(rc == 0, | ||
| 90 | - 'Successful ctmodel execution on command line') | 84 | + self.test_assert(self._execute(cmd) == 0, |
| 85 | + 'Check successful execution from command line') | ||
| 91 | 86 | ||
| 92 | # Check result file | 87 | # Check result file |
| 93 | self._check_result_file('ctmodel_cmd1.fits') | 88 | self._check_result_file('ctmodel_cmd1.fits') |
| @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 104 | ' xref=83.63 yref=22.01'+ \ | 99 | ' xref=83.63 yref=22.01'+ \ |
| 105 | ' logfile="ctmodel_cmd2.log" chatter=1' | 100 | ' logfile="ctmodel_cmd2.log" chatter=1' |
| 106 | 101 | ||
| 107 | - # Execute ctmodel, make sure we catch any exception | ||
| 108 | - try: | ||
| 109 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 110 | - except: | ||
| 111 | - pass | ||
| 112 | - | ||
| 113 | # Check if execution failed | 102 | # Check if execution failed |
| 114 | - self.test_assert(rc != 0, | ||
| 115 | - 'Failure of ctmodel execution on command line') | 103 | + self.test_assert(self._execute(cmd) != 0, |
| 104 | + 'Check invalid input file when executed from command line') | ||
| 116 | 105 | ||
| 117 | # Return | 106 | # Return |
| 118 | return | 107 | return |
| @@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -120,7 +109,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 120 | # Test ctmodel from Python | 109 | # Test ctmodel from Python |
| 121 | def _test_python(self): | 110 | def _test_python(self): |
| 122 | """ | 111 | """ |
| 123 | - Test ctmodel from Python. | 112 | + Test ctmodel from Python |
| 124 | """ | 113 | """ |
| 125 | # Set-up ctmodel from scratch | 114 | # Set-up ctmodel from scratch |
| 126 | model = ctools.ctmodel() | 115 | model = ctools.ctmodel() |
| @@ -165,7 +154,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -165,7 +154,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 165 | # Check result file | 154 | # Check result file |
| 166 | def _check_result_file(self, filename): | 155 | def _check_result_file(self, filename): |
| 167 | """ | 156 | """ |
| 168 | - Check result file. | 157 | + Check result file |
| 169 | """ | 158 | """ |
| 170 | # Open result file | 159 | # Open result file |
| 171 | fits = gammalib.GFits(filename) | 160 | fits = gammalib.GFits(filename) |
test/test_ctobssim.py
| @@ -18,18 +18,18 @@ | @@ -18,18 +18,18 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 24 | from cscripts import obsutils | 23 | from cscripts import obsutils |
| 24 | +from testing import test | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | # ============================ # | 27 | # ============================ # |
| 28 | # Test class for ctobssim tool # | 28 | # Test class for ctobssim tool # |
| 29 | # ============================ # | 29 | # ============================ # |
| 30 | -class Test(gammalib.GPythonTestSuite): | 30 | +class Test(test): |
| 31 | """ | 31 | """ |
| 32 | - Test class for ctobssim tools. | 32 | + Test class for ctobssim tools |
| 33 | 33 | ||
| 34 | This test class makes unit tests for the ctobssim tool by using it from | 34 | This test class makes unit tests for the ctobssim tool by using it from |
| 35 | the command line and from Python. | 35 | the command line and from Python. |
| @@ -38,15 +38,15 @@ class Test(gammalib.GPythonTestSuite): | @@ -38,15 +38,15 @@ class Test(gammalib.GPythonTestSuite): | ||
| 38 | # Constructor | 38 | # Constructor |
| 39 | def __init__(self): | 39 | def __init__(self): |
| 40 | """ | 40 | """ |
| 41 | - Constructor. | 41 | + Constructor |
| 42 | """ | 42 | """ |
| 43 | # Call base class constructor | 43 | # Call base class constructor |
| 44 | - gammalib.GPythonTestSuite.__init__(self) | 44 | + test.__init__(self) |
| 45 | 45 | ||
| 46 | # Set members | 46 | # Set members |
| 47 | - self._model_name = "data/crab.xml" | ||
| 48 | - self._caldb = "irf" | ||
| 49 | - self._irf = "cta_dummy_irf" | 47 | + self._model_name = 'data/crab.xml' |
| 48 | + self._caldb = 'irf' | ||
| 49 | + self._irf = 'cta_dummy_irf' | ||
| 50 | 50 | ||
| 51 | # Return | 51 | # Return |
| 52 | return | 52 | return |
| @@ -54,14 +54,14 @@ class Test(gammalib.GPythonTestSuite): | @@ -54,14 +54,14 @@ class Test(gammalib.GPythonTestSuite): | ||
| 54 | # Set test functions | 54 | # Set test functions |
| 55 | def set(self): | 55 | def set(self): |
| 56 | """ | 56 | """ |
| 57 | - Set all test functions. | 57 | + Set all test functions |
| 58 | """ | 58 | """ |
| 59 | # Set test name | 59 | # Set test name |
| 60 | - self.name("ctobssim") | 60 | + self.name('ctobssim') |
| 61 | 61 | ||
| 62 | # Append tests | 62 | # Append tests |
| 63 | - self.append(self._test_ctobssim_cmd, "Test ctobssim on command line") | ||
| 64 | - self.append(self._test_ctobssim_python, "Test ctobssim from Python") | 63 | + self.append(self._test_ctobssim_cmd, 'Test ctobssim on command line') |
| 64 | + self.append(self._test_ctobssim_python, 'Test ctobssim from Python') | ||
| 65 | 65 | ||
| 66 | # Return | 66 | # Return |
| 67 | return | 67 | return |
| @@ -69,13 +69,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,13 +69,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | # Test ctobssim on command line | 69 | # Test ctobssim on command line |
| 70 | def _test_ctobssim_cmd(self): | 70 | def _test_ctobssim_cmd(self): |
| 71 | """ | 71 | """ |
| 72 | - Test ctobssim on the command line. | 72 | + Test ctobssim on the command line |
| 73 | """ | 73 | """ |
| 74 | - # Kluge to set the command (installed version has no README file) | ||
| 75 | - if os.path.isfile("README.md"): | ||
| 76 | - ctobssim = "../src/ctobssim/ctobssim" | ||
| 77 | - else: | ||
| 78 | - ctobssim = "ctobssim" | 74 | + # Set tool name |
| 75 | + ctobssim = self._tool('ctobssim') | ||
| 79 | 76 | ||
| 80 | # Setup ctobssim command | 77 | # Setup ctobssim command |
| 81 | cmd = ctobssim+' inmodel="data/crab.xml" outevents="events.fits"'+ \ | 78 | cmd = ctobssim+' inmodel="data/crab.xml" outevents="events.fits"'+ \ |
| @@ -83,18 +80,16 @@ class Test(gammalib.GPythonTestSuite): | @@ -83,18 +80,16 @@ class Test(gammalib.GPythonTestSuite): | ||
| 83 | ' ra=83.63 dec=22.01 rad=10.0'+ \ | 80 | ' ra=83.63 dec=22.01 rad=10.0'+ \ |
| 84 | ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' | 81 | ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' |
| 85 | 82 | ||
| 86 | - # Execute ctobssim, make sure we catch any exception | ||
| 87 | - try: | ||
| 88 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 89 | - except: | ||
| 90 | - pass | 83 | + # Check if execution of wrong command fails |
| 84 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 85 | + 'Self test of test script') | ||
| 91 | 86 | ||
| 92 | # Check if execution was successful | 87 | # Check if execution was successful |
| 93 | - self.test_assert(rc == 0, | ||
| 94 | - "Successful ctobssim execution on command line") | 88 | + self.test_assert(self._execute(cmd) == 0, |
| 89 | + 'Check successful execution from command line') | ||
| 95 | 90 | ||
| 96 | # Load counts cube and check content. | 91 | # Load counts cube and check content. |
| 97 | - evt = gammalib.GCTAEventList("events.fits") | 92 | + evt = gammalib.GCTAEventList('events.fits') |
| 98 | self._test_list(evt, 4119) | 93 | self._test_list(evt, 4119) |
| 99 | 94 | ||
| 100 | # Setup ctobssim command | 95 | # Setup ctobssim command |
| @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -104,15 +99,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 104 | ' ra=83.63 dec=22.01 rad=10.0'+ \ | 99 | ' ra=83.63 dec=22.01 rad=10.0'+ \ |
| 105 | ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' | 100 | ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0' |
| 106 | 101 | ||
| 107 | - # Execute ctobssim, make sure we catch any exception | ||
| 108 | - try: | ||
| 109 | - rc = os.system(cmd+" >/dev/null 2>&1") | ||
| 110 | - except: | ||
| 111 | - pass | ||
| 112 | - | ||
| 113 | # Check if execution failed | 102 | # Check if execution failed |
| 114 | - self.test_assert(rc != 0, | ||
| 115 | - "Failure of ctobssim execution on command line") | 103 | + self.test_assert(self._execute(cmd) != 0, |
| 104 | + 'Check invalid input file when executed from command line') | ||
| 116 | 105 | ||
| 117 | # Return | 106 | # Return |
| 118 | return | 107 | return |
| @@ -120,21 +109,21 @@ class Test(gammalib.GPythonTestSuite): | @@ -120,21 +109,21 @@ class Test(gammalib.GPythonTestSuite): | ||
| 120 | # Test ctobssim from Python | 109 | # Test ctobssim from Python |
| 121 | def _test_ctobssim_python(self): | 110 | def _test_ctobssim_python(self): |
| 122 | """ | 111 | """ |
| 123 | - Test ctobssim from Python. | 112 | + Test ctobssim from Python |
| 124 | """ | 113 | """ |
| 125 | # Set-up ctobssim | 114 | # Set-up ctobssim |
| 126 | sim = ctools.ctobssim() | 115 | sim = ctools.ctobssim() |
| 127 | - sim["inmodel"] = self._model_name | ||
| 128 | - sim["outevents"] = "events.fits" | ||
| 129 | - sim["caldb"] = self._caldb | ||
| 130 | - sim["irf"] = self._irf | ||
| 131 | - sim["ra"] = 83.63 | ||
| 132 | - sim["dec"] = 22.01 | ||
| 133 | - sim["rad"] = 10.0 | ||
| 134 | - sim["tmin"] = 0.0 | ||
| 135 | - sim["tmax"] = 1800.0 | ||
| 136 | - sim["emin"] = 0.1 | ||
| 137 | - sim["emax"] = 100.0 | 116 | + sim['inmodel'] = self._model_name |
| 117 | + sim['outevents'] = 'events.fits' | ||
| 118 | + sim['caldb'] = self._caldb | ||
| 119 | + sim['irf'] = self._irf | ||
| 120 | + sim['ra'] = 83.63 | ||
| 121 | + sim['dec'] = 22.01 | ||
| 122 | + sim['rad'] = 10.0 | ||
| 123 | + sim['tmin'] = 0.0 | ||
| 124 | + sim['tmax'] = 1800.0 | ||
| 125 | + sim['emin'] = 0.1 | ||
| 126 | + sim['emax'] = 100.0 | ||
| 138 | 127 | ||
| 139 | # Run tool | 128 | # Run tool |
| 140 | sim.run() | 129 | sim.run() |
| @@ -147,7 +136,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -147,7 +136,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 147 | sim.save() | 136 | sim.save() |
| 148 | 137 | ||
| 149 | # Load counts cube and check content. | 138 | # Load counts cube and check content. |
| 150 | - evt = gammalib.GCTAEventList("events.fits") | 139 | + evt = gammalib.GCTAEventList('events.fits') |
| 151 | self._test_list(evt, 4119) | 140 | self._test_list(evt, 4119) |
| 152 | 141 | ||
| 153 | # Set-up observation container | 142 | # Set-up observation container |
| @@ -159,8 +148,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -159,8 +148,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 159 | 148 | ||
| 160 | # Set-up ctobssim from observation container | 149 | # Set-up ctobssim from observation container |
| 161 | sim = ctools.ctobssim(obs) | 150 | sim = ctools.ctobssim(obs) |
| 162 | - sim["outevents"] = "sim_events.xml" | ||
| 163 | - sim["inmodel"] = self._model_name | 151 | + sim['outevents'] = 'sim_events.xml' |
| 152 | + sim['inmodel'] = self._model_name | ||
| 164 | 153 | ||
| 165 | # Run tool | 154 | # Run tool |
| 166 | sim.run() | 155 | sim.run() |
| @@ -176,7 +165,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -176,7 +165,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 176 | sim.save() | 165 | sim.save() |
| 177 | 166 | ||
| 178 | # Load events | 167 | # Load events |
| 179 | - obs = gammalib.GObservations("sim_events.xml") | 168 | + obs = gammalib.GObservations('sim_events.xml') |
| 180 | 169 | ||
| 181 | # Retrieve observation and check content | 170 | # Retrieve observation and check content |
| 182 | self._test_list(obs[0].events(), 4063) | 171 | self._test_list(obs[0].events(), 4063) |
| @@ -186,20 +175,20 @@ class Test(gammalib.GPythonTestSuite): | @@ -186,20 +175,20 @@ class Test(gammalib.GPythonTestSuite): | ||
| 186 | 175 | ||
| 187 | # Set-up ctobssim with invalid event file | 176 | # Set-up ctobssim with invalid event file |
| 188 | sim = ctools.ctobssim() | 177 | sim = ctools.ctobssim() |
| 189 | - sim["inmodel"] = "model_file_that_does_not_exist.xml" | ||
| 190 | - sim["outevents"] = "events.fits" | ||
| 191 | - sim["caldb"] = self._caldb | ||
| 192 | - sim["irf"] = self._irf | ||
| 193 | - sim["ra"] = 83.63 | ||
| 194 | - sim["dec"] = 22.01 | ||
| 195 | - sim["rad"] = 10.0 | ||
| 196 | - sim["tmin"] = 0.0 | ||
| 197 | - sim["tmax"] = 1800.0 | ||
| 198 | - sim["emin"] = 0.1 | ||
| 199 | - sim["emax"] = 100.0 | 178 | + sim['inmodel'] = 'model_file_that_does_not_exist.xml' |
| 179 | + sim['outevents'] = 'events.fits' | ||
| 180 | + sim['caldb'] = self._caldb | ||
| 181 | + sim['irf'] = self._irf | ||
| 182 | + sim['ra'] = 83.63 | ||
| 183 | + sim['dec'] = 22.01 | ||
| 184 | + sim['rad'] = 10.0 | ||
| 185 | + sim['tmin'] = 0.0 | ||
| 186 | + sim['tmax'] = 1800.0 | ||
| 187 | + sim['emin'] = 0.1 | ||
| 188 | + sim['emax'] = 100.0 | ||
| 200 | 189 | ||
| 201 | # Run ctbin tool | 190 | # Run ctbin tool |
| 202 | - self.test_try("Run ctobssim with invalid model file") | 191 | + self.test_try('Run ctobssim with invalid model file') |
| 203 | try: | 192 | try: |
| 204 | sim.run() | 193 | sim.run() |
| 205 | self.test_try_failure() | 194 | self.test_try_failure() |
| @@ -213,31 +202,33 @@ class Test(gammalib.GPythonTestSuite): | @@ -213,31 +202,33 @@ class Test(gammalib.GPythonTestSuite): | ||
| 213 | def _test_observation(self, ctobssim, nobs=1, | 202 | def _test_observation(self, ctobssim, nobs=1, |
| 214 | pnts=[{'ra': 83.63, 'dec': 22.01}]): | 203 | pnts=[{'ra': 83.63, 'dec': 22.01}]): |
| 215 | """ | 204 | """ |
| 216 | - Test content of an observation. | 205 | + Test content of an observation |
| 217 | 206 | ||
| 218 | - Args: | ||
| 219 | - ctobssim: ctobssim instance | ||
| 220 | - | ||
| 221 | - Kwargs: | ||
| 222 | - nobs: Number of observations | ||
| 223 | - pnts: List of pointing dictionaries | 207 | + Parameters |
| 208 | + ---------- | ||
| 209 | + ctobssim : `~ctools.ctobssim` | ||
| 210 | + ctobssim instance | ||
| 211 | + nobs : int | ||
| 212 | + Number of observations | ||
| 213 | + pnts : list of dict | ||
| 214 | + List of pointing dictionaries | ||
| 224 | """ | 215 | """ |
| 225 | # Test observation container | 216 | # Test observation container |
| 226 | self.test_value(ctobssim.obs().size(), nobs, | 217 | self.test_value(ctobssim.obs().size(), nobs, |
| 227 | - "There is one observation") | 218 | + 'There is one observation') |
| 228 | for i in range(ctobssim.obs().size()): | 219 | for i in range(ctobssim.obs().size()): |
| 229 | obs = gammalib.GCTAObservation(ctobssim.obs()[i]) | 220 | obs = gammalib.GCTAObservation(ctobssim.obs()[i]) |
| 230 | pnt = obs.pointing() | 221 | pnt = obs.pointing() |
| 231 | - self.test_assert(obs.instrument() == "CTA", | ||
| 232 | - "Observation is CTA observation") | 222 | + self.test_assert(obs.instrument() == 'CTA', |
| 223 | + 'Observation is CTA observation') | ||
| 233 | self.test_value(obs.ontime(), 1800.0, 1.0e-6, | 224 | self.test_value(obs.ontime(), 1800.0, 1.0e-6, |
| 234 | - "Ontime is 1800 sec") | 225 | + 'Ontime is 1800 sec') |
| 235 | self.test_value(obs.livetime(), 1710.0, 1.0e-6, | 226 | self.test_value(obs.livetime(), 1710.0, 1.0e-6, |
| 236 | - "Livetime is 1710 sec") | 227 | + 'Livetime is 1710 sec') |
| 237 | self.test_value(pnt.dir().ra_deg(), pnts[i]['ra'], 1.0e-6, | 228 | self.test_value(pnt.dir().ra_deg(), pnts[i]['ra'], 1.0e-6, |
| 238 | - "Pointing Right Ascension is "+str(pnts[i]['ra'])+" deg") | 229 | + 'Pointing Right Ascension is '+str(pnts[i]['ra'])+' deg') |
| 239 | self.test_value(pnt.dir().dec_deg(), pnts[i]['dec'], 1.0e-6, | 230 | self.test_value(pnt.dir().dec_deg(), pnts[i]['dec'], 1.0e-6, |
| 240 | - "Pointing Declination is "+str(pnts[i]['dec'])+" deg") | 231 | + 'Pointing Declination is '+str(pnts[i]['dec'])+' deg') |
| 241 | 232 | ||
| 242 | # Return | 233 | # Return |
| 243 | return | 234 | return |
| @@ -245,15 +236,18 @@ class Test(gammalib.GPythonTestSuite): | @@ -245,15 +236,18 @@ class Test(gammalib.GPythonTestSuite): | ||
| 245 | # Check event list | 236 | # Check event list |
| 246 | def _test_list(self, list, nevents): | 237 | def _test_list(self, list, nevents): |
| 247 | """ | 238 | """ |
| 248 | - Test content of event list." | 239 | + Test content of event list |
| 249 | 240 | ||
| 250 | - Args: | ||
| 251 | - list: Event list | ||
| 252 | - nevents: Expected number of events. | 241 | + Parameters |
| 242 | + ---------- | ||
| 243 | + list : `~gammalib.GCTAEventList` | ||
| 244 | + Event list | ||
| 245 | + nevents : int | ||
| 246 | + Expected number of events | ||
| 253 | """ | 247 | """ |
| 254 | # Test event list | 248 | # Test event list |
| 255 | - self.test_value(list.size(), nevents, str(nevents)+" elements") | ||
| 256 | - self.test_value(list.number(), nevents, str(nevents)+" events") | 249 | + self.test_value(list.size(), nevents, str(nevents)+' elements') |
| 250 | + self.test_value(list.number(), nevents, str(nevents)+' events') | ||
| 257 | 251 | ||
| 258 | # Return | 252 | # Return |
| 259 | return | 253 | return |
test/test_ctpsfcube.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================= # | 26 | # ============================= # |
| 27 | # Test class for ctpsfcube tool # | 27 | # Test class for ctpsfcube tool # |
| 28 | # ============================= # | 28 | # ============================= # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctpsfcube tool. | 31 | + Test class for ctpsfcube tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctpsfcube') | 50 | self.name('ctpsfcube') |
| @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | @@ -61,11 +61,8 @@ class Test(gammalib.GPythonTestSuite): | ||
| 61 | """ | 61 | """ |
| 62 | Test ctpsfcube on the command line. | 62 | Test ctpsfcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctpsfcube = '../src/ctpsfcube/ctpsfcube' | ||
| 67 | - else: | ||
| 68 | - ctpsfcube = 'ctpsfcube' | 64 | + # Set tool name |
| 65 | + ctpsfcube = self._tool('ctpsfcube') | ||
| 69 | 66 | ||
| 70 | # Setup ctpsfcube command | 67 | # Setup ctpsfcube command |
| 71 | cmd = ctpsfcube+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctpsfcube+' inobs="data/crab_events.fits"'+ \ |
| @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -78,15 +75,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 78 | ' amax=0.3 anumbins=10'+ \ | 75 | ' amax=0.3 anumbins=10'+ \ |
| 79 | ' logfile="ctpsfcube_cmd1.log" chatter=1' | 76 | ' logfile="ctpsfcube_cmd1.log" chatter=1' |
| 80 | 77 | ||
| 81 | - # Execute ctpsfcube, make sure we catch any exception | ||
| 82 | - try: | ||
| 83 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 84 | - except: | ||
| 85 | - pass | 78 | + # Check if execution of wrong command fails |
| 79 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 80 | + 'Self test of test script') | ||
| 86 | 81 | ||
| 87 | # Check if execution was successful | 82 | # Check if execution was successful |
| 88 | - self.test_assert(rc == 0, | ||
| 89 | - 'Successful ctpsfcube execution on command line') | 83 | + self.test_assert(self._execute(cmd) == 0, |
| 84 | + 'Check successful execution from command line') | ||
| 90 | 85 | ||
| 91 | # Check result file | 86 | # Check result file |
| 92 | self._check_result_file('ctpsfcube_cmd1.fits') | 87 | self._check_result_file('ctpsfcube_cmd1.fits') |
| @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -102,15 +97,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 102 | ' amax=0.3 anumbins=10'+ \ | 97 | ' amax=0.3 anumbins=10'+ \ |
| 103 | ' logfile="ctpsfcube_cmd2.log" chatter=1' | 98 | ' logfile="ctpsfcube_cmd2.log" chatter=1' |
| 104 | 99 | ||
| 105 | - # Execute ctpsfcube, make sure we catch any exception | ||
| 106 | - try: | ||
| 107 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 108 | - except: | ||
| 109 | - pass | ||
| 110 | - | ||
| 111 | # Check if execution failed | 100 | # Check if execution failed |
| 112 | - self.test_assert(rc != 0, | ||
| 113 | - 'Failure of ctpsfcube execution on command line') | 101 | + self.test_assert(self._execute(cmd) != 0, |
| 102 | + 'Check invalid input file when executed from command line') | ||
| 114 | 103 | ||
| 115 | # Return | 104 | # Return |
| 116 | return | 105 | return |
| @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -118,7 +107,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 118 | # Test ctpsfcube from Python | 107 | # Test ctpsfcube from Python |
| 119 | def _test_python(self): | 108 | def _test_python(self): |
| 120 | """ | 109 | """ |
| 121 | - Test ctpsfcube from Python. | 110 | + Test ctpsfcube from Python |
| 122 | """ | 111 | """ |
| 123 | # Set-up ctpsfcube | 112 | # Set-up ctpsfcube |
| 124 | psfcube = ctools.ctpsfcube() | 113 | psfcube = ctools.ctpsfcube() |
| @@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -157,7 +146,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 157 | # Check result file | 146 | # Check result file |
| 158 | def _check_result_file(self, filename): | 147 | def _check_result_file(self, filename): |
| 159 | """ | 148 | """ |
| 160 | - Check result file. | 149 | + Check result file |
| 161 | """ | 150 | """ |
| 162 | # Open result file | 151 | # Open result file |
| 163 | result = gammalib.GCTACubePsf(filename) | 152 | result = gammalib.GCTACubePsf(filename) |
test/test_ctselect.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for ctselect tool # | 27 | # Test class for ctselect tool # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctselect tool. | 31 | + Test class for ctselect tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctselect') | 50 | self.name('ctselect') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctselect on command line | 59 | # Test ctselect on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctselect on the command line. | 62 | + Test ctselect on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctselect = '../src/ctselect/ctselect' | ||
| 67 | - else: | ||
| 68 | - ctselect = 'ctselect' | 64 | + # Set tool name |
| 65 | + ctselect = self._tool('ctselect') | ||
| 69 | 66 | ||
| 70 | # Setup ctselect command | 67 | # Setup ctselect command |
| 71 | cmd = ctselect+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctselect+' inobs="data/crab_events.fits"'+ \ |
| @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 75 | ' emin=0.1 emax=100.0'+ \ | 72 | ' emin=0.1 emax=100.0'+ \ |
| 76 | ' logfile="ctselect_cmd1.log" chatter=1' | 73 | ' logfile="ctselect_cmd1.log" chatter=1' |
| 77 | 74 | ||
| 78 | - # Execute ctselect, make sure we catch any exception | ||
| 79 | - try: | ||
| 80 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 81 | - except: | ||
| 82 | - pass | 75 | + # Check if execution of wrong command fails |
| 76 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 77 | + 'Self test of test script') | ||
| 83 | 78 | ||
| 84 | # Check if execution was successful | 79 | # Check if execution was successful |
| 85 | - self.test_assert(rc == 0, | ||
| 86 | - 'Successful ctselect execution on command line') | 80 | + self.test_assert(self._execute(cmd) == 0, |
| 81 | + 'Check successful execution from command line') | ||
| 87 | 82 | ||
| 88 | # Check result file | 83 | # Check result file |
| 89 | self._check_result_file('ctselect_cmd1.fits') | 84 | self._check_result_file('ctselect_cmd1.fits') |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' emin=0.1 emax=100.0'+ \ | 91 | ' emin=0.1 emax=100.0'+ \ |
| 97 | ' logfile="ctselect_cmd2.log" chatter=1' | 92 | ' logfile="ctselect_cmd2.log" chatter=1' |
| 98 | 93 | ||
| 99 | - # Execute ctselect, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - 'Failure of ctselect execution on command line') | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test ctselect from Python | 101 | # Test ctselect from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test ctselect from Python. | 104 | + Test ctselect from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up ctselect | 106 | # Set-up ctselect |
| 118 | select = ctools.ctselect() | 107 | select = ctools.ctselect() |
| @@ -142,7 +131,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -142,7 +131,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 142 | # Check result file | 131 | # Check result file |
| 143 | def _check_result_file(self, filename): | 132 | def _check_result_file(self, filename): |
| 144 | """ | 133 | """ |
| 145 | - Check result file. | 134 | + Check result file |
| 146 | """ | 135 | """ |
| 147 | # Open result file | 136 | # Open result file |
| 148 | result = gammalib.GCTAEventList(filename) | 137 | result = gammalib.GCTAEventList(filename) |
test/test_ctskymap.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for ctskymap tool # | 27 | # Test class for ctskymap tool # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctskymap tool. | 31 | + Test class for ctskymap tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctskymap') | 50 | self.name('ctskymap') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctskymap on command line | 59 | # Test ctskymap on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctskymap on the command line. | 62 | + Test ctskymap on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctskymap = '../src/ctskymap/ctskymap' | ||
| 67 | - else: | ||
| 68 | - ctskymap = 'ctskymap' | 64 | + # Set tool name |
| 65 | + ctskymap = self._tool('ctskymap') | ||
| 69 | 66 | ||
| 70 | # Setup ctskymap command | 67 | # Setup ctskymap command |
| 71 | cmd = ctskymap+' inobs="data/crab_events.fits"'+\ | 68 | cmd = ctskymap+' inobs="data/crab_events.fits"'+\ |
| @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -75,15 +72,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 75 | ' xref=83.63 yref=22.01'+ \ | 72 | ' xref=83.63 yref=22.01'+ \ |
| 76 | ' logfile="ctskymap_cmd1.log" chatter=1' | 73 | ' logfile="ctskymap_cmd1.log" chatter=1' |
| 77 | 74 | ||
| 78 | - # Execute ctskymap, make sure we catch any exception | ||
| 79 | - try: | ||
| 80 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 81 | - except: | ||
| 82 | - pass | 75 | + # Check if execution of wrong command fails |
| 76 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 77 | + 'Self test of test script') | ||
| 83 | 78 | ||
| 84 | # Check if execution was successful | 79 | # Check if execution was successful |
| 85 | - self.test_assert(rc == 0, | ||
| 86 | - 'Successful ctskymap execution on command line') | 80 | + self.test_assert(self._execute(cmd) == 0, |
| 81 | + 'Check successful execution from command line') | ||
| 87 | 82 | ||
| 88 | # Check result file | 83 | # Check result file |
| 89 | self._check_result_file('ctskymap_cmd1.fits') | 84 | self._check_result_file('ctskymap_cmd1.fits') |
| @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -96,15 +91,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 96 | ' xref=83.63 yref=22.01'+ \ | 91 | ' xref=83.63 yref=22.01'+ \ |
| 97 | ' logfile="ctskymap_cmd2.log" chatter=2' | 92 | ' logfile="ctskymap_cmd2.log" chatter=2' |
| 98 | 93 | ||
| 99 | - # Execute ctskymap, make sure we catch any exception | ||
| 100 | - try: | ||
| 101 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 102 | - except: | ||
| 103 | - pass | ||
| 104 | - | ||
| 105 | # Check if execution failed | 94 | # Check if execution failed |
| 106 | - self.test_assert(rc != 0, | ||
| 107 | - 'Failure of ctskymap execution on command line') | 95 | + self.test_assert(self._execute(cmd) != 0, |
| 96 | + 'Check invalid input file when executed from command line') | ||
| 108 | 97 | ||
| 109 | # Return | 98 | # Return |
| 110 | return | 99 | return |
| @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -112,7 +101,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 112 | # Test ctskymap from Python | 101 | # Test ctskymap from Python |
| 113 | def _test_python(self): | 102 | def _test_python(self): |
| 114 | """ | 103 | """ |
| 115 | - Test ctskymap from Python. | 104 | + Test ctskymap from Python |
| 116 | """ | 105 | """ |
| 117 | # Set-up ctskymap | 106 | # Set-up ctskymap |
| 118 | skymap = ctools.ctskymap() | 107 | skymap = ctools.ctskymap() |
| @@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -144,7 +133,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 144 | # Check result file | 133 | # Check result file |
| 145 | def _check_result_file(self, filename): | 134 | def _check_result_file(self, filename): |
| 146 | """ | 135 | """ |
| 147 | - Check result file. | 136 | + Check result file |
| 148 | """ | 137 | """ |
| 149 | # Open result file | 138 | # Open result file |
| 150 | result = gammalib.GSkyMap(filename) | 139 | result = gammalib.GSkyMap(filename) |
test/test_cttsmap.py
| @@ -18,17 +18,17 @@ | @@ -18,17 +18,17 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | -# ========================== # | 26 | +# =========================== # |
| 27 | # Test class for cttsmap tool # | 27 | # Test class for cttsmap tool # |
| 28 | -# ========================== # | ||
| 29 | -class Test(gammalib.GPythonTestSuite): | 28 | +# =========================== # |
| 29 | +class Test(test): | ||
| 30 | """ | 30 | """ |
| 31 | - Test class for cttsmap tool. | 31 | + Test class for cttsmap tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| @@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -36,7 +36,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 36 | Constructor. | 36 | Constructor. |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('cttsmap') | 50 | self.name('cttsmap') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test cttsmap on command line | 59 | # Test cttsmap on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test cttsmap on the command line. | 62 | + Test cttsmap on the command line |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - cttsmap = '../src/cttsmap/cttsmap' | ||
| 67 | - else: | ||
| 68 | - cttsmap = 'cttsmap' | 64 | + # Set tool name |
| 65 | + cttsmap = self._tool('cttsmap') | ||
| 69 | 66 | ||
| 70 | # Setup cttsmap command | 67 | # Setup cttsmap command |
| 71 | cmd = cttsmap+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = cttsmap+' inobs="data/crab_events.fits"'+ \ |
| @@ -76,15 +73,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -76,15 +73,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 76 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 73 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 77 | ' logfile="cttsmap_cmd1.log" chatter=1' | 74 | ' logfile="cttsmap_cmd1.log" chatter=1' |
| 78 | 75 | ||
| 79 | - # Execute cttsmap, make sure we catch any exception | ||
| 80 | - try: | ||
| 81 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 82 | - except: | ||
| 83 | - pass | 76 | + # Check if execution of wrong command fails |
| 77 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 78 | + 'Self test of test script') | ||
| 84 | 79 | ||
| 85 | # Check if execution was successful | 80 | # Check if execution was successful |
| 86 | - self.test_assert(rc == 0, | ||
| 87 | - 'Successful cttsmap execution on command line') | 81 | + self.test_assert(self._execute(cmd) == 0, |
| 82 | + 'Check successful execution from command line') | ||
| 88 | 83 | ||
| 89 | # Check result file | 84 | # Check result file |
| 90 | self._check_result_file('cttsmap_cmd1.fits') | 85 | self._check_result_file('cttsmap_cmd1.fits') |
| @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -98,15 +93,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 98 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | 93 | ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ |
| 99 | ' logfile="cttsmap_cmd2.log" chatter=2' | 94 | ' logfile="cttsmap_cmd2.log" chatter=2' |
| 100 | 95 | ||
| 101 | - # Execute cttsmap, make sure we catch any exception | ||
| 102 | - try: | ||
| 103 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 104 | - except: | ||
| 105 | - pass | ||
| 106 | - | ||
| 107 | # Check if execution failed | 96 | # Check if execution failed |
| 108 | - self.test_assert(rc != 0, | ||
| 109 | - 'Failure of cttsmap execution on command line') | 97 | + self.test_assert(self._execute(cmd) != 0, |
| 98 | + 'Check invalid input file when executed from command line') | ||
| 110 | 99 | ||
| 111 | # Return | 100 | # Return |
| 112 | return | 101 | return |
| @@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -114,7 +103,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 114 | # Test cttsmap from Python | 103 | # Test cttsmap from Python |
| 115 | def _test_python(self): | 104 | def _test_python(self): |
| 116 | """ | 105 | """ |
| 117 | - Test cttsmap from Python. | 106 | + Test cttsmap from Python |
| 118 | """ | 107 | """ |
| 119 | # Set-up cttsmap | 108 | # Set-up cttsmap |
| 120 | tsmap = ctools.cttsmap() | 109 | tsmap = ctools.cttsmap() |
| @@ -148,7 +137,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -148,7 +137,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 148 | # Check result file | 137 | # Check result file |
| 149 | def _check_result_file(self, filename): | 138 | def _check_result_file(self, filename): |
| 150 | """ | 139 | """ |
| 151 | - Check result file. | 140 | + Check result file |
| 152 | """ | 141 | """ |
| 153 | # Open result file | 142 | # Open result file |
| 154 | fits = gammalib.GFits(filename) | 143 | fits = gammalib.GFits(filename) |
test/test_ctulimit.py
| @@ -18,25 +18,25 @@ | @@ -18,25 +18,25 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import os | ||
| 22 | import gammalib | 21 | import gammalib |
| 23 | import ctools | 22 | import ctools |
| 23 | +from testing import test | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # ============================ # | 26 | # ============================ # |
| 27 | # Test class for ctulimit tool # | 27 | # Test class for ctulimit tool # |
| 28 | # ============================ # | 28 | # ============================ # |
| 29 | -class Test(gammalib.GPythonTestSuite): | 29 | +class Test(test): |
| 30 | """ | 30 | """ |
| 31 | - Test class for ctulimit tool. | 31 | + Test class for ctulimit tool |
| 32 | """ | 32 | """ |
| 33 | # Constructor | 33 | # Constructor |
| 34 | def __init__(self): | 34 | def __init__(self): |
| 35 | """ | 35 | """ |
| 36 | - Constructor. | 36 | + Constructor |
| 37 | """ | 37 | """ |
| 38 | # Call base class constructor | 38 | # Call base class constructor |
| 39 | - gammalib.GPythonTestSuite.__init__(self) | 39 | + test.__init__(self) |
| 40 | 40 | ||
| 41 | # Return | 41 | # Return |
| 42 | return | 42 | return |
| @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -44,7 +44,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 44 | # Set test functions | 44 | # Set test functions |
| 45 | def set(self): | 45 | def set(self): |
| 46 | """ | 46 | """ |
| 47 | - Set all test functions. | 47 | + Set all test functions |
| 48 | """ | 48 | """ |
| 49 | # Set test name | 49 | # Set test name |
| 50 | self.name('ctulimit') | 50 | self.name('ctulimit') |
| @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | @@ -59,13 +59,10 @@ class Test(gammalib.GPythonTestSuite): | ||
| 59 | # Test ctulimit on command line | 59 | # Test ctulimit on command line |
| 60 | def _test_cmd(self): | 60 | def _test_cmd(self): |
| 61 | """ | 61 | """ |
| 62 | - Test ctulimit on the command line. | 62 | + Test ctulimit on the command lines |
| 63 | """ | 63 | """ |
| 64 | - # Kluge to set the command (installed version has no README file) | ||
| 65 | - if os.path.isfile('README.md'): | ||
| 66 | - ctulimit = '../src/ctulimit/ctulimit' | ||
| 67 | - else: | ||
| 68 | - ctulimit = 'ctulimit' | 64 | + # Set tool name |
| 65 | + ctulimit = self._tool('ctulimit') | ||
| 69 | 66 | ||
| 70 | # Setup ctulimit command | 67 | # Setup ctulimit command |
| 71 | cmd = ctulimit+' inobs="data/crab_events.fits"'+ \ | 68 | cmd = ctulimit+' inobs="data/crab_events.fits"'+ \ |
| @@ -73,15 +70,13 @@ class Test(gammalib.GPythonTestSuite): | @@ -73,15 +70,13 @@ class Test(gammalib.GPythonTestSuite): | ||
| 73 | ' caldb="prod2" irf="South_0.5h"'+ \ | 70 | ' caldb="prod2" irf="South_0.5h"'+ \ |
| 74 | ' logfile="ctulimit_cmd1.log" chatter=1' | 71 | ' logfile="ctulimit_cmd1.log" chatter=1' |
| 75 | 72 | ||
| 76 | - # Execute ctulimit, make sure we catch any exception | ||
| 77 | - try: | ||
| 78 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 79 | - except: | ||
| 80 | - pass | 73 | + # Check if execution of wrong command fails |
| 74 | + self.test_assert(self._execute('command that does not exist') != 0, | ||
| 75 | + 'Self test of test script') | ||
| 81 | 76 | ||
| 82 | # Check if execution was successful | 77 | # Check if execution was successful |
| 83 | - self.test_assert(rc == 0, | ||
| 84 | - 'Successful ctulimit execution on command line') | 78 | + self.test_assert(self._execute(cmd) == 0, |
| 79 | + 'Check successful execution from command line') | ||
| 85 | 80 | ||
| 86 | # Check result file | 81 | # Check result file |
| 87 | self._check_result_file('ctulimit_cmd1.log') | 82 | self._check_result_file('ctulimit_cmd1.log') |
| @@ -92,15 +87,9 @@ class Test(gammalib.GPythonTestSuite): | @@ -92,15 +87,9 @@ class Test(gammalib.GPythonTestSuite): | ||
| 92 | ' caldb="prod2" irf="South_0.5h"'+ \ | 87 | ' caldb="prod2" irf="South_0.5h"'+ \ |
| 93 | ' logfile="ctulimit_cmd2.log" chatter=1' | 88 | ' logfile="ctulimit_cmd2.log" chatter=1' |
| 94 | 89 | ||
| 95 | - # Execute ctulimit, make sure we catch any exception | ||
| 96 | - try: | ||
| 97 | - rc = os.system(cmd+' >/dev/null 2>&1') | ||
| 98 | - except: | ||
| 99 | - pass | ||
| 100 | - | ||
| 101 | # Check if execution failed | 90 | # Check if execution failed |
| 102 | - self.test_assert(rc != 0, | ||
| 103 | - 'Failure of ctulimit execution on command line') | 91 | + self.test_assert(self._execute(cmd) != 0, |
| 92 | + 'Check invalid input file when executed from command line') | ||
| 104 | 93 | ||
| 105 | # Return | 94 | # Return |
| 106 | return | 95 | return |
| @@ -108,7 +97,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -108,7 +97,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 108 | # Test ctulimit from Python | 97 | # Test ctulimit from Python |
| 109 | def _test_python(self): | 98 | def _test_python(self): |
| 110 | """ | 99 | """ |
| 111 | - Test ctulimit from Python. | 100 | + Test ctulimit from Python |
| 112 | """ | 101 | """ |
| 113 | # Set-up ctulimit | 102 | # Set-up ctulimit |
| 114 | ulimit = ctools.ctulimit() | 103 | ulimit = ctools.ctulimit() |
| @@ -134,7 +123,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -134,7 +123,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 134 | # Check result file | 123 | # Check result file |
| 135 | def _check_result_file(self, filename): | 124 | def _check_result_file(self, filename): |
| 136 | """ | 125 | """ |
| 137 | - Check result file. | 126 | + Check result file |
| 138 | """ | 127 | """ |
| 139 | # Return | 128 | # Return |
| 140 | return | 129 | return |
test/test_cscripts_class.py renamed to test/testing.py
| 1 | # ========================================================================== | 1 | # ========================================================================== |
| 2 | -# cscripts test base class | 2 | +# Python base class for unit tests |
| 3 | # | 3 | # |
| 4 | # Copyright (C) 2016 Juergen Knoedlseder | 4 | # Copyright (C) 2016 Juergen Knoedlseder |
| 5 | # | 5 | # |
| @@ -21,12 +21,12 @@ import os | @@ -21,12 +21,12 @@ import os | ||
| 21 | import gammalib | 21 | import gammalib |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | -# ======================================= # | ||
| 25 | -# Base class for unit testing of cscripts # | ||
| 26 | -# ======================================= # | ||
| 27 | -class cscripts_test(gammalib.GPythonTestSuite): | 24 | +# ================================ # |
| 25 | +# Python base class for unit tests # | ||
| 26 | +# ================================ # | ||
| 27 | +class test(gammalib.GPythonTestSuite): | ||
| 28 | """ | 28 | """ |
| 29 | - Test class for scripts | 29 | + Python base class for unit tests |
| 30 | """ | 30 | """ |
| 31 | 31 | ||
| 32 | # Constructor | 32 | # Constructor |
| @@ -45,7 +45,7 @@ class cscripts_test(gammalib.GPythonTestSuite): | @@ -45,7 +45,7 @@ class cscripts_test(gammalib.GPythonTestSuite): | ||
| 45 | """ | 45 | """ |
| 46 | Set script name | 46 | Set script name |
| 47 | """ | 47 | """ |
| 48 | - # Kluge to set the command. The installed version has no README file | 48 | + # Kluge to set the command. The installed version has no README.md file |
| 49 | if os.path.isfile('README.md'): | 49 | if os.path.isfile('README.md'): |
| 50 | script = '../cscripts/'+name+'.py' | 50 | script = '../cscripts/'+name+'.py' |
| 51 | else: | 51 | else: |
| @@ -54,6 +54,20 @@ class cscripts_test(gammalib.GPythonTestSuite): | @@ -54,6 +54,20 @@ class cscripts_test(gammalib.GPythonTestSuite): | ||
| 54 | # Return script name | 54 | # Return script name |
| 55 | return script | 55 | return script |
| 56 | 56 | ||
| 57 | + # Set tool name | ||
| 58 | + def _tool(self, name): | ||
| 59 | + """ | ||
| 60 | + Set tool name | ||
| 61 | + """ | ||
| 62 | + # Kluge to set the command. The installed version has no README.md file | ||
| 63 | + if os.path.isfile('README.md'): | ||
| 64 | + tool = '../src/'+name+'/'+name | ||
| 65 | + else: | ||
| 66 | + tool = name | ||
| 67 | + | ||
| 68 | + # Return tool name | ||
| 69 | + return tool | ||
| 70 | + | ||
| 57 | # Execute command and catch any exception | 71 | # Execute command and catch any exception |
| 58 | def _execute(self, cmd): | 72 | def _execute(self, cmd): |
| 59 | """ | 73 | """ |