1515import unittest2
1616
1717
18+ class Test_Batches (unittest2 .TestCase ):
19+
20+ def _getTargetClass (self ):
21+ from gcloud .datastore .batch import _Batches
22+
23+ return _Batches
24+
25+ def _makeOne (self ):
26+ return self ._getTargetClass ()()
27+
28+ def test_it (self ):
29+ batch1 , batch2 = object (), object ()
30+ batches = self ._makeOne ()
31+ self .assertEqual (list (batches ), [])
32+ self .assertTrue (batches .top is None )
33+ batches .push (batch1 )
34+ self .assertTrue (batches .top is batch1 )
35+ batches .push (batch2 )
36+ self .assertTrue (batches .top is batch2 )
37+ popped = batches .pop ()
38+ self .assertTrue (popped is batch2 )
39+ self .assertTrue (batches .top is batch1 )
40+ self .assertEqual (list (batches ), [batch1 ])
41+ popped = batches .pop ()
42+ self .assertTrue (batches .top is None )
43+ self .assertEqual (list (batches ), [])
44+
45+
1846class TestBatch (unittest2 .TestCase ):
1947
2048 def _getTargetClass (self ):
@@ -177,14 +205,14 @@ def test_as_context_mgr_wo_error(self):
177205 entity = _Entity (_PROPERTIES )
178206 key = entity .key = _Key (_DATASET )
179207
180- self .assertEqual (_BATCHES . stack , [])
208+ self .assertEqual (list ( _BATCHES ) , [])
181209
182210 with self ._makeOne (dataset_id = _DATASET ,
183211 connection = connection ) as batch :
184- self .assertEqual (_BATCHES . stack , [batch ])
212+ self .assertEqual (list ( _BATCHES ) , [batch ])
185213 batch .put (entity )
186214
187- self .assertEqual (_BATCHES . stack , [])
215+ self .assertEqual (list ( _BATCHES ) , [])
188216
189217 self .assertEqual (
190218 connection ._saved ,
@@ -201,20 +229,20 @@ def test_as_context_mgr_nested(self):
201229 entity2 = _Entity (_PROPERTIES )
202230 key = entity2 .key = _Key (_DATASET )
203231
204- self .assertEqual (_BATCHES . stack , [])
232+ self .assertEqual (list ( _BATCHES ) , [])
205233
206234 with self ._makeOne (dataset_id = _DATASET ,
207235 connection = connection ) as batch1 :
208- self .assertEqual (_BATCHES . stack , [batch1 ])
236+ self .assertEqual (list ( _BATCHES ) , [batch1 ])
209237 batch1 .put (entity1 )
210238 with self ._makeOne (dataset_id = _DATASET ,
211239 connection = connection ) as batch2 :
212- self .assertEqual (_BATCHES . stack , [batch1 , batch2 ])
240+ self .assertEqual (list ( _BATCHES ) , [batch2 , batch1 ])
213241 batch2 .put (entity2 )
214242
215- self .assertEqual (_BATCHES . stack , [batch1 ])
243+ self .assertEqual (list ( _BATCHES ) , [batch1 ])
216244
217- self .assertEqual (_BATCHES . stack , [])
245+ self .assertEqual (list ( _BATCHES ) , [])
218246
219247 self .assertEqual (
220248 connection ._saved ,
@@ -233,18 +261,18 @@ def test_as_context_mgr_w_error(self):
233261 entity = _Entity (_PROPERTIES )
234262 key = entity .key = _Key (_DATASET )
235263
236- self .assertEqual (_BATCHES . stack , [])
264+ self .assertEqual (list ( _BATCHES ) , [])
237265
238266 try :
239267 with self ._makeOne (dataset_id = _DATASET ,
240268 connection = connection ) as batch :
241- self .assertEqual (_BATCHES . stack , [batch ])
269+ self .assertEqual (list ( _BATCHES ) , [batch ])
242270 batch .put (entity )
243271 raise ValueError ("testing" )
244272 except ValueError :
245273 pass
246274
247- self .assertEqual (_BATCHES . stack , [])
275+ self .assertEqual (list ( _BATCHES ) , [])
248276
249277 self .assertEqual (
250278 connection ._saved ,
0 commit comments