@@ -100,8 +100,8 @@ def test_ensure_future(self):
100100
101101class BaseFutureTests :
102102
103- def _new_future (self , loop = None ):
104- raise NotImplementedError
103+ def _new_future (self , * args , ** kwargs ):
104+ return self . cls ( * args , ** kwargs )
105105
106106 def setUp (self ):
107107 super ().setUp ()
@@ -147,6 +147,39 @@ def test_constructor_positional(self):
147147 # Make sure Future doesn't accept a positional argument
148148 self .assertRaises (TypeError , self ._new_future , 42 )
149149
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+
150183 def test_cancel (self ):
151184 f = self ._new_future (loop = self .loop )
152185 self .assertTrue (f .cancel ())
@@ -501,15 +534,11 @@ def __del__(self):
501534@unittest .skipUnless (hasattr (futures , '_CFuture' ),
502535 'requires the C _asyncio module' )
503536class CFutureTests (BaseFutureTests , test_utils .TestCase ):
504-
505- def _new_future (self , * args , ** kwargs ):
506- return futures ._CFuture (* args , ** kwargs )
537+ cls = getattr (futures , '_CFuture' )
507538
508539
509540class PyFutureTests (BaseFutureTests , test_utils .TestCase ):
510-
511- def _new_future (self , * args , ** kwargs ):
512- return futures ._PyFuture (* args , ** kwargs )
541+ cls = futures ._PyFuture
513542
514543
515544class BaseFutureDoneCallbackTests ():
0 commit comments