@@ -100,8 +100,8 @@ def test_ensure_future(self):
100
100
101
101
class BaseFutureTests :
102
102
103
- def _new_future (self , loop = None ):
104
- raise NotImplementedError
103
+ def _new_future (self , * args , ** kwargs ):
104
+ return self . cls ( * args , ** kwargs )
105
105
106
106
def setUp (self ):
107
107
super ().setUp ()
@@ -147,6 +147,39 @@ def test_constructor_positional(self):
147
147
# Make sure Future doesn't accept a positional argument
148
148
self .assertRaises (TypeError , self ._new_future , 42 )
149
149
150
+ def test_uninitialized (self ):
151
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
152
+ self .assertRaises (asyncio .InvalidStateError , fut .result )
153
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
154
+ self .assertRaises (asyncio .InvalidStateError , fut .exception )
155
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
156
+ with self .assertRaises ((RuntimeError , AttributeError )):
157
+ fut .set_result (None )
158
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
159
+ with self .assertRaises ((RuntimeError , AttributeError )):
160
+ fut .set_exception (Exception )
161
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
162
+ with self .assertRaises ((RuntimeError , AttributeError )):
163
+ fut .cancel ()
164
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
165
+ with self .assertRaises ((RuntimeError , AttributeError )):
166
+ fut .add_done_callback (lambda f : None )
167
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
168
+ with self .assertRaises ((RuntimeError , AttributeError )):
169
+ fut .remove_done_callback (lambda f : None )
170
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
171
+ with self .assertRaises ((RuntimeError , AttributeError )):
172
+ fut ._schedule_callbacks ()
173
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
174
+ try :
175
+ repr (fut )
176
+ except AttributeError :
177
+ pass
178
+ fut = self .cls .__new__ (self .cls , loop = self .loop )
179
+ fut .cancelled ()
180
+ fut .done ()
181
+ iter (fut )
182
+
150
183
def test_cancel (self ):
151
184
f = self ._new_future (loop = self .loop )
152
185
self .assertTrue (f .cancel ())
@@ -501,15 +534,11 @@ def __del__(self):
501
534
@unittest .skipUnless (hasattr (futures , '_CFuture' ),
502
535
'requires the C _asyncio module' )
503
536
class CFutureTests (BaseFutureTests , test_utils .TestCase ):
504
-
505
- def _new_future (self , * args , ** kwargs ):
506
- return futures ._CFuture (* args , ** kwargs )
537
+ cls = getattr (futures , '_CFuture' )
507
538
508
539
509
540
class PyFutureTests (BaseFutureTests , test_utils .TestCase ):
510
-
511
- def _new_future (self , * args , ** kwargs ):
512
- return futures ._PyFuture (* args , ** kwargs )
541
+ cls = futures ._PyFuture
513
542
514
543
515
544
class BaseFutureDoneCallbackTests ():
0 commit comments