Commit d56bdc8e9c96c3df8b0b2d76f2edff2efb1e35a0
1 parent
14de508d
Make Python classes pickable (#1938)
Showing
2 changed files
with
13 additions
and
2 deletions
pyext/GCaldb.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCaldb.i - Calibration database class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -75,4 +75,11 @@ public: |
| 75 | 75 | GCaldb copy() { |
| 76 | 76 | return (*self); |
| 77 | 77 | } |
| 78 | +%pythoncode { | |
| 79 | + def __getstate__(self): | |
| 80 | + state = (self.mission(), self.instrument()) | |
| 81 | + return state | |
| 82 | + def __setstate__(self, state): | |
| 83 | + self.__init__(state[0], state[1]) | |
| 84 | +} | |
| 78 | 85 | }; | ... | ... |
test/test_GObservation.py
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | # |
| 19 | 19 | # ========================================================================== |
| 20 | +import os | |
| 20 | 21 | import gammalib |
| 21 | 22 | import test_support |
| 22 | 23 | |
| ... | ... | @@ -36,6 +37,9 @@ class Test(gammalib.GPythonTestSuite): |
| 36 | 37 | # Call base class constructor |
| 37 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 38 | 39 | |
| 40 | + # Set CALDB | |
| 41 | + os.environ['CALDB'] = os.environ['TEST_DATA']+'/caldb' | |
| 42 | + | |
| 39 | 43 | # Return |
| 40 | 44 | return |
| 41 | 45 | |
| ... | ... | @@ -764,7 +768,7 @@ class Test(gammalib.GPythonTestSuite): |
| 764 | 768 | times.append(tmax) |
| 765 | 769 | |
| 766 | 770 | # Perform pickeling tests of filled classes |
| 767 | - #test_support._pickeling(self, gammalib.GCaldb()) | |
| 771 | + test_support._pickeling(self, gammalib.GCaldb('cta','prod2')) | |
| 768 | 772 | test_support._pickeling(self, gammalib.GEbounds(10, emin, emax)) |
| 769 | 773 | test_support._pickeling(self, gammalib.GEnergy(emin)) |
| 770 | 774 | test_support._pickeling(self, gammalib.GEnergies(10, emin, emax)) | ... | ... |