File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 23
23
Iterator ,
24
24
List ,
25
25
NoReturn ,
26
+ Tuple ,
26
27
TypeVar ,
27
28
Union ,
28
29
overload ,
@@ -97,6 +98,12 @@ def __getitem__(self, item: Any) -> Any:
97
98
def __getattr__ (self , attr : str ) -> Any :
98
99
return getattr (self ._body , attr )
99
100
101
+ def __getstate__ (self ) -> Tuple [_BodyType , ApiResponseMeta ]:
102
+ return self ._body , self ._meta
103
+
104
+ def __setstate__ (self , state : Tuple [_BodyType , ApiResponseMeta ]) -> None :
105
+ self ._body , self ._meta = state
106
+
100
107
def __len__ (self ) -> int :
101
108
return len (self ._body )
102
109
Original file line number Diff line number Diff line change 15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
17
18
+ import pickle
19
+
18
20
import pytest
19
21
20
22
from elastic_transport import (
@@ -139,3 +141,19 @@ def test_constructor_allowed():
139
141
140
142
resp = ObjectApiResponse (meta = meta , body = {}, body_cls = int )
141
143
assert resp == {}
144
+
145
+
146
+ @pytest .mark .parametrize (
147
+ "response_cls, body" ,
148
+ [
149
+ (TextApiResponse , "Hello World" ),
150
+ (BinaryApiResponse , b"Hello World" ),
151
+ (ObjectApiResponse , {"Hello" : "World" }),
152
+ (ListApiResponse , ["Hello" , "World" ]),
153
+ ],
154
+ )
155
+ def test_pickle (response_cls , body ):
156
+ resp = response_cls (meta = meta , body = body )
157
+ pickled_resp = pickle .loads (pickle .dumps (resp ))
158
+ assert pickled_resp == resp
159
+ assert pickled_resp .meta == resp .meta
You can’t perform that action at this time.
0 commit comments