@@ -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 ())
@@ -499,15 +532,11 @@ def __del__(self):
499532@unittest .skipUnless (hasattr (futures , '_CFuture' ),
500533 'requires the C _asyncio module' )
501534class CFutureTests (BaseFutureTests , test_utils .TestCase ):
502-
503- def _new_future (self , * args , ** kwargs ):
504- return futures ._CFuture (* args , ** kwargs )
535+ cls = getattr (futures , '_CFuture' )
505536
506537
507538class PyFutureTests (BaseFutureTests , test_utils .TestCase ):
508-
509- def _new_future (self , * args , ** kwargs ):
510- return futures ._PyFuture (* args , ** kwargs )
539+ cls = futures ._PyFuture
511540
512541
513542class BaseFutureDoneCallbackTests ():
0 commit comments