Commit d56bdc8e9c96c3df8b0b2d76f2edff2efb1e35a0

Authored by Jürgen Knödlseder
1 parent 14de508d

Make Python classes pickable (#1938)

pyext/GCaldb.i
1 /*************************************************************************** 1 /***************************************************************************
2 * GCaldb.i - Calibration database class * 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 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -75,4 +75,11 @@ public: @@ -75,4 +75,11 @@ public:
75 GCaldb copy() { 75 GCaldb copy() {
76 return (*self); 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,6 +17,7 @@
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # 18 #
19 # ========================================================================== 19 # ==========================================================================
  20 +import os
20 import gammalib 21 import gammalib
21 import test_support 22 import test_support
22 23
@@ -36,6 +37,9 @@ class Test(gammalib.GPythonTestSuite): @@ -36,6 +37,9 @@ class Test(gammalib.GPythonTestSuite):
36 # Call base class constructor 37 # Call base class constructor
37 gammalib.GPythonTestSuite.__init__(self) 38 gammalib.GPythonTestSuite.__init__(self)
38 39
  40 + # Set CALDB
  41 + os.environ['CALDB'] = os.environ['TEST_DATA']+'/caldb'
  42 +
39 # Return 43 # Return
40 return 44 return
41 45
@@ -764,7 +768,7 @@ class Test(gammalib.GPythonTestSuite): @@ -764,7 +768,7 @@ class Test(gammalib.GPythonTestSuite):
764 times.append(tmax) 768 times.append(tmax)
765 769
766 # Perform pickeling tests of filled classes 770 # Perform pickeling tests of filled classes
767 - #test_support._pickeling(self, gammalib.GCaldb()) 771 + test_support._pickeling(self, gammalib.GCaldb('cta','prod2'))
768 test_support._pickeling(self, gammalib.GEbounds(10, emin, emax)) 772 test_support._pickeling(self, gammalib.GEbounds(10, emin, emax))
769 test_support._pickeling(self, gammalib.GEnergy(emin)) 773 test_support._pickeling(self, gammalib.GEnergy(emin))
770 test_support._pickeling(self, gammalib.GEnergies(10, emin, emax)) 774 test_support._pickeling(self, gammalib.GEnergies(10, emin, emax))