Commit c4bf507e52bfc35d4360afef8a5d4870c93116c2
1 parent
a67e143b
Enhance error messages in case of an exception (now logs also the exception).
Showing
14 changed files
with
103 additions
and
73 deletions
test/test_ctbin.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctbin tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -83,16 +83,18 @@ class Test(gammalib.GPythonTestSuite): |
| 83 | 83 | try: |
| 84 | 84 | bin.run() |
| 85 | 85 | self.test_try_success() |
| 86 | - except: | |
| 87 | - self.test_try_failure("Exception occured in ctbin.") | |
| 86 | + except Exception, e: | |
| 87 | + msg = "Exception occured in ctbin: %s." % (e,) | |
| 88 | + self.test_try_failure(msg) | |
| 88 | 89 | |
| 89 | 90 | # Save counts cube |
| 90 | 91 | self.test_try("Save counts cube") |
| 91 | 92 | try: |
| 92 | 93 | bin.save() |
| 93 | 94 | self.test_try_success() |
| 94 | - except: | |
| 95 | - self.test_try_failure("Exception occured in saving counts cube.") | |
| 95 | + except Exception, e: | |
| 96 | + msg = "Exception occured in saving counts cube: %s." % (e,) | |
| 97 | + self.test_try_failure(msg) | |
| 96 | 98 | |
| 97 | 99 | # Return |
| 98 | 100 | return | ... | ... |
test/test_ctbkgcube.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctbkgcube tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -91,16 +91,18 @@ class Test(gammalib.GPythonTestSuite): |
| 91 | 91 | try: |
| 92 | 92 | bkgcube.run() |
| 93 | 93 | self.test_try_success() |
| 94 | - except: | |
| 95 | - self.test_try_failure("Exception occured in ctbkgcube.") | |
| 94 | + except Exception, e: | |
| 95 | + msg = "Exception occured in ctbkgcube: %s." % (e,) | |
| 96 | + self.test_try_failure(msg) | |
| 96 | 97 | |
| 97 | 98 | # Save background cube |
| 98 | 99 | self.test_try("Save background cube") |
| 99 | 100 | try: |
| 100 | 101 | bkgcube.save() |
| 101 | 102 | self.test_try_success() |
| 102 | - except: | |
| 103 | - self.test_try_failure("Exception occured in saving background cube.") | |
| 103 | + except Exception, e: | |
| 104 | + msg = "Exception occured in saving background cube: %s." % (e,) | |
| 105 | + self.test_try_failure(msg) | |
| 104 | 106 | |
| 105 | 107 | # Return |
| 106 | 108 | return | ... | ... |
test/test_ctbutterfly.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctbutterfly tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Michal Mayer | |
| 5 | +# Copyright (C) 2014-2016 Michal Mayer | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -81,16 +81,18 @@ class Test(gammalib.GPythonTestSuite): |
| 81 | 81 | try: |
| 82 | 82 | butterfly.run() |
| 83 | 83 | self.test_try_success() |
| 84 | - except: | |
| 85 | - self.test_try_failure("Exception occured in butterfly.") | |
| 84 | + except Exception, e: | |
| 85 | + msg = "Exception occured in ctbutterfly: %s." % (e,) | |
| 86 | + self.test_try_failure(msg) | |
| 86 | 87 | |
| 87 | 88 | # Save results |
| 88 | 89 | self.test_try("Save results") |
| 89 | 90 | try: |
| 90 | 91 | butterfly.save() |
| 91 | 92 | self.test_try_success() |
| 92 | - except: | |
| 93 | - self.test_try_failure("Exception occured in saving results.") | |
| 93 | + except Exception, e: | |
| 94 | + msg = "Exception occured in saving butterfly diagram: %s." % (e,) | |
| 95 | + self.test_try_failure(msg) | |
| 94 | 96 | |
| 95 | 97 | # Return |
| 96 | 98 | return | ... | ... |
test/test_ctcubemask.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctcubemask tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -79,16 +79,18 @@ class Test(gammalib.GPythonTestSuite): |
| 79 | 79 | try: |
| 80 | 80 | mask.run() |
| 81 | 81 | self.test_try_success() |
| 82 | - except: | |
| 83 | - self.test_try_failure("Exception occured in ctcubemask.") | |
| 82 | + except Exception, e: | |
| 83 | + msg = "Exception occured in ctcubemask: %s." % (e,) | |
| 84 | + self.test_try_failure(msg) | |
| 84 | 85 | |
| 85 | 86 | # Save counts cube |
| 86 | 87 | self.test_try("Save counts cube") |
| 87 | 88 | try: |
| 88 | 89 | mask.save() |
| 89 | 90 | self.test_try_success() |
| 90 | - except: | |
| 91 | - self.test_try_failure("Exception occured in saving counts cube.") | |
| 91 | + except Exception, e: | |
| 92 | + msg = "Exception occured in saving counts cube: %s." % (e,) | |
| 93 | + self.test_try_failure(msg) | |
| 92 | 94 | |
| 93 | 95 | # Return |
| 94 | 96 | return | ... | ... |
test/test_cterror.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the cterror tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2015 Florent Forest | |
| 5 | +# Copyright (C) 2015-2016 Florent Forest | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -80,16 +80,18 @@ class Test(gammalib.GPythonTestSuite): |
| 80 | 80 | try: |
| 81 | 81 | error.run() |
| 82 | 82 | self.test_try_success() |
| 83 | - except: | |
| 84 | - self.test_try_failure("Exception occured in cterror.") | |
| 83 | + except Exception, e: | |
| 84 | + msg = "Exception occured in cterror: %s." % (e,) | |
| 85 | + self.test_try_failure(msg) | |
| 85 | 86 | |
| 86 | 87 | # Save results |
| 87 | 88 | self.test_try("Save results") |
| 88 | 89 | try: |
| 89 | 90 | error.save() |
| 90 | 91 | self.test_try_success() |
| 91 | - except: | |
| 92 | - self.test_try_failure("Exception occured in saving results.") | |
| 92 | + except Exception, e: | |
| 93 | + msg = "Exception occured in saving results: %s." % (e,) | |
| 94 | + self.test_try_failure(msg) | |
| 93 | 95 | |
| 94 | 96 | # Return |
| 95 | 97 | return | ... | ... |
test/test_ctexpcube.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctexpcube tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -88,16 +88,18 @@ class Test(gammalib.GPythonTestSuite): |
| 88 | 88 | try: |
| 89 | 89 | expcube.run() |
| 90 | 90 | self.test_try_success() |
| 91 | - except: | |
| 92 | - self.test_try_failure("Exception occured in ctexpcube.") | |
| 91 | + except Exception, e: | |
| 92 | + msg = "Exception occured in ctexpcube: %s." % (e,) | |
| 93 | + self.test_try_failure(msg) | |
| 93 | 94 | |
| 94 | 95 | # Save exposure cube |
| 95 | 96 | self.test_try("Save exposure cube") |
| 96 | 97 | try: |
| 97 | 98 | expcube.save() |
| 98 | 99 | self.test_try_success() |
| 99 | - except: | |
| 100 | - self.test_try_failure("Exception occured in saving exposure cube.") | |
| 100 | + except Exception, e: | |
| 101 | + msg = "Exception occured in saving exposure cube: %s." % (e,) | |
| 102 | + self.test_try_failure(msg) | |
| 101 | 103 | |
| 102 | 104 | # Return |
| 103 | 105 | return | ... | ... |
test/test_ctlike.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctlike tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -78,16 +78,18 @@ class Test(gammalib.GPythonTestSuite): |
| 78 | 78 | try: |
| 79 | 79 | like.run() |
| 80 | 80 | self.test_try_success() |
| 81 | - except: | |
| 82 | - self.test_try_failure("Exception occured in ctlike.") | |
| 81 | + except Exception, e: | |
| 82 | + msg = "Exception occured in ctlike: %s." % (e,) | |
| 83 | + self.test_try_failure(msg) | |
| 83 | 84 | |
| 84 | 85 | # Save results |
| 85 | 86 | self.test_try("Save results") |
| 86 | 87 | try: |
| 87 | 88 | like.save() |
| 88 | 89 | self.test_try_success() |
| 89 | - except: | |
| 90 | - self.test_try_failure("Exception occured in saving results.") | |
| 90 | + except Exception, e: | |
| 91 | + msg = "Exception occured in saving results: %s." % (e,) | |
| 92 | + self.test_try_failure(msg) | |
| 91 | 93 | |
| 92 | 94 | # Return |
| 93 | 95 | return | ... | ... |
test/test_ctmodel.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctmodel tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -96,16 +96,18 @@ class Test(gammalib.GPythonTestSuite): |
| 96 | 96 | try: |
| 97 | 97 | model.run() |
| 98 | 98 | self.test_try_success() |
| 99 | - except: | |
| 100 | - self.test_try_failure("Exception occured in ctmodel.") | |
| 99 | + except Exception, e: | |
| 100 | + msg = "Exception occured in ctmodel: %s." % (e,) | |
| 101 | + self.test_try_failure(msg) | |
| 101 | 102 | |
| 102 | 103 | # Save counts cube |
| 103 | 104 | self.test_try("Save model cube") |
| 104 | 105 | try: |
| 105 | 106 | model.save() |
| 106 | 107 | self.test_try_success() |
| 107 | - except: | |
| 108 | - self.test_try_failure("Exception occured in saving model cube.") | |
| 108 | + except Exception, e: | |
| 109 | + msg = "Exception occured in saving model cube: %s." % (e,) | |
| 110 | + self.test_try_failure(msg) | |
| 109 | 111 | |
| 110 | 112 | # Return |
| 111 | 113 | return | ... | ... |
test/test_ctobssim.py
| ... | ... | @@ -84,8 +84,9 @@ class Test(gammalib.GPythonTestSuite): |
| 84 | 84 | try: |
| 85 | 85 | sim.run() |
| 86 | 86 | self.test_try_success() |
| 87 | - except: | |
| 88 | - self.test_try_failure("Exception occured in ctobssim.") | |
| 87 | + except Exception, e: | |
| 88 | + msg = "Exception occured in ctobssim: %s." % (e,) | |
| 89 | + self.test_try_failure(msg) | |
| 89 | 90 | |
| 90 | 91 | # Retrieve observation and check content |
| 91 | 92 | obs = gammalib.GCTAObservation(sim.obs()[0]) |
| ... | ... | @@ -104,8 +105,9 @@ class Test(gammalib.GPythonTestSuite): |
| 104 | 105 | try: |
| 105 | 106 | sim.save() |
| 106 | 107 | self.test_try_success() |
| 107 | - except: | |
| 108 | - self.test_try_failure("Exception occured in saving events.") | |
| 108 | + except Exception, e: | |
| 109 | + msg = "Exception occured in saving events: %s." % (e,) | |
| 110 | + self.test_try_failure(msg) | |
| 109 | 111 | |
| 110 | 112 | # Test ctobssim on observation container |
| 111 | 113 | def test_container(self): |
| ... | ... | @@ -124,8 +126,9 @@ class Test(gammalib.GPythonTestSuite): |
| 124 | 126 | try: |
| 125 | 127 | sim.run() |
| 126 | 128 | self.test_try_success() |
| 127 | - except: | |
| 128 | - self.test_try_failure("Exception occured in ctobssim.") | |
| 129 | + except Exception, e: | |
| 130 | + msg = "Exception occured in ctobssim: %s." % (e,) | |
| 131 | + self.test_try_failure(msg) | |
| 129 | 132 | |
| 130 | 133 | # Retrieve observation and check content |
| 131 | 134 | self.test_value(sim.obs().size(), 4, "There are not 4 observations") |
| ... | ... | @@ -135,8 +138,9 @@ class Test(gammalib.GPythonTestSuite): |
| 135 | 138 | try: |
| 136 | 139 | sim.save() |
| 137 | 140 | self.test_try_success() |
| 138 | - except: | |
| 139 | - self.test_try_failure("Exception occured in saving events.") | |
| 141 | + except Exception, e: | |
| 142 | + msg = "Exception occured in saving events: %s." % (e,) | |
| 143 | + self.test_try_failure(msg) | |
| 140 | 144 | |
| 141 | 145 | # Setup observation container |
| 142 | 146 | def set_obs(self, number): | ... | ... |
test/test_ctpsfcube.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctpsfcube tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -90,16 +90,18 @@ class Test(gammalib.GPythonTestSuite): |
| 90 | 90 | try: |
| 91 | 91 | psfcube.run() |
| 92 | 92 | self.test_try_success() |
| 93 | - except: | |
| 94 | - self.test_try_failure("Exception occured in ctpsfcube.") | |
| 93 | + except Exception, e: | |
| 94 | + msg = "Exception occured in ctpsfcube: %s." % (e,) | |
| 95 | + self.test_try_failure(msg) | |
| 95 | 96 | |
| 96 | 97 | # Save PSF cube |
| 97 | 98 | self.test_try("Save PSF cube") |
| 98 | 99 | try: |
| 99 | 100 | psfcube.save() |
| 100 | 101 | self.test_try_success() |
| 101 | - except: | |
| 102 | - self.test_try_failure("Exception occured in saving PSF cube.") | |
| 102 | + except Exception, e: | |
| 103 | + msg = "Exception occured in saving PSF cube: %s." % (e,) | |
| 104 | + self.test_try_failure(msg) | |
| 103 | 105 | |
| 104 | 106 | # Return |
| 105 | 107 | return | ... | ... |
test/test_ctselect.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctselect tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -79,16 +79,18 @@ class Test(gammalib.GPythonTestSuite): |
| 79 | 79 | try: |
| 80 | 80 | select.run() |
| 81 | 81 | self.test_try_success() |
| 82 | - except: | |
| 83 | - self.test_try_failure("Exception occured in ctselect.") | |
| 82 | + except Exception, e: | |
| 83 | + msg = "Exception occured in ctselect: %s." % (e,) | |
| 84 | + self.test_try_failure(msg) | |
| 84 | 85 | |
| 85 | 86 | # Save events |
| 86 | 87 | self.test_try("Save events") |
| 87 | 88 | try: |
| 88 | 89 | select.save() |
| 89 | 90 | self.test_try_success() |
| 90 | - except: | |
| 91 | - self.test_try_failure("Exception occured in saving events.") | |
| 91 | + except Exception, e: | |
| 92 | + msg = "Exception occured in saving events: %s." % (e,) | |
| 93 | + self.test_try_failure(msg) | |
| 92 | 94 | |
| 93 | 95 | # Return |
| 94 | 96 | return | ... | ... |
test/test_ctskymap.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctskymap tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -81,16 +81,18 @@ class Test(gammalib.GPythonTestSuite): |
| 81 | 81 | try: |
| 82 | 82 | skymap.run() |
| 83 | 83 | self.test_try_success() |
| 84 | - except: | |
| 85 | - self.test_try_failure("Exception occured in ctskymap.") | |
| 84 | + except Exception, e: | |
| 85 | + msg = "Exception occured in ctskymap: %s." % (e,) | |
| 86 | + self.test_try_failure(msg) | |
| 86 | 87 | |
| 87 | 88 | # Save counts cube |
| 88 | 89 | self.test_try("Save sky map") |
| 89 | 90 | try: |
| 90 | 91 | skymap.save() |
| 91 | 92 | self.test_try_success() |
| 92 | - except: | |
| 93 | - self.test_try_failure("Exception occured in saving sky map.") | |
| 93 | + except Exception, e: | |
| 94 | + msg = "Exception occured in saving sky map: %s." % (e,) | |
| 95 | + self.test_try_failure(msg) | |
| 94 | 96 | |
| 95 | 97 | # Return |
| 96 | 98 | return | ... | ... |
test/test_cttsmap.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the cttsmap tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014 Juergen Knoedlseder | |
| 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -86,16 +86,18 @@ class Test(gammalib.GPythonTestSuite): |
| 86 | 86 | try: |
| 87 | 87 | tsmap.run() |
| 88 | 88 | self.test_try_success() |
| 89 | - except: | |
| 90 | - self.test_try_failure("Exception occured in cttsmap.") | |
| 89 | + except Exception, e: | |
| 90 | + msg = "Exception occured in cttsmap: %s." % (e,) | |
| 91 | + self.test_try_failure(msg) | |
| 91 | 92 | |
| 92 | 93 | # Save results |
| 93 | 94 | self.test_try("Save results") |
| 94 | 95 | try: |
| 95 | 96 | tsmap.save() |
| 96 | 97 | self.test_try_success() |
| 97 | - except: | |
| 98 | - self.test_try_failure("Exception occured in saving results.") | |
| 98 | + except Exception, e: | |
| 99 | + msg = "Exception occured in saving results: %s." % (e,) | |
| 100 | + self.test_try_failure(msg) | |
| 99 | 101 | |
| 100 | 102 | # Return |
| 101 | 103 | return | ... | ... |
test/test_ctulimit.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # This scripts performs unit tests for the ctulimit tool. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2015 Michael Mayer | |
| 5 | +# Copyright (C) 2015-2016 Michael Mayer | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -78,16 +78,18 @@ class Test(gammalib.GPythonTestSuite): |
| 78 | 78 | try: |
| 79 | 79 | ulimit.run() |
| 80 | 80 | self.test_try_success() |
| 81 | - except: | |
| 82 | - self.test_try_failure("Exception occured in ctulimit.") | |
| 81 | + except Exception, e: | |
| 82 | + msg = "Exception occured in ctulimit: %s." % (e,) | |
| 83 | + self.test_try_failure(msg) | |
| 83 | 84 | |
| 84 | 85 | # Save results |
| 85 | 86 | self.test_try("Save results") |
| 86 | 87 | try: |
| 87 | 88 | ulimit.save() |
| 88 | 89 | self.test_try_success() |
| 89 | - except: | |
| 90 | - self.test_try_failure("Exception occured in saving results.") | |
| 90 | + except Exception, e: | |
| 91 | + msg = "Exception occured in saving results: %s." % (e,) | |
| 92 | + self.test_try_failure(msg) | |
| 91 | 93 | |
| 92 | 94 | # Return |
| 93 | 95 | return | ... | ... |