1717RGX_REPR = re .compile (STR_RGX_REPR )
1818
1919
20- class LockTests (unittest .TestCase ):
20+ class LockTests (test_utils .TestCase ):
2121
2222 def setUp (self ):
23- self .loop = test_utils .TestLoop ()
24- asyncio .set_event_loop (None )
25-
26- def tearDown (self ):
27- self .loop .close ()
23+ self .loop = self .new_test_loop ()
2824
2925 def test_ctor_loop (self ):
3026 loop = mock .Mock ()
@@ -35,12 +31,9 @@ def test_ctor_loop(self):
3531 self .assertIs (lock ._loop , self .loop )
3632
3733 def test_ctor_noloop (self ):
38- try :
39- asyncio .set_event_loop (self .loop )
40- lock = asyncio .Lock ()
41- self .assertIs (lock ._loop , self .loop )
42- finally :
43- asyncio .set_event_loop (None )
34+ asyncio .set_event_loop (self .loop )
35+ lock = asyncio .Lock ()
36+ self .assertIs (lock ._loop , self .loop )
4437
4538 def test_repr (self ):
4639 lock = asyncio .Lock (loop = self .loop )
@@ -240,14 +233,10 @@ def test_context_manager_no_yield(self):
240233 self .assertFalse (lock .locked ())
241234
242235
243- class EventTests (unittest .TestCase ):
236+ class EventTests (test_utils .TestCase ):
244237
245238 def setUp (self ):
246- self .loop = test_utils .TestLoop ()
247- asyncio .set_event_loop (None )
248-
249- def tearDown (self ):
250- self .loop .close ()
239+ self .loop = self .new_test_loop ()
251240
252241 def test_ctor_loop (self ):
253242 loop = mock .Mock ()
@@ -258,12 +247,9 @@ def test_ctor_loop(self):
258247 self .assertIs (ev ._loop , self .loop )
259248
260249 def test_ctor_noloop (self ):
261- try :
262- asyncio .set_event_loop (self .loop )
263- ev = asyncio .Event ()
264- self .assertIs (ev ._loop , self .loop )
265- finally :
266- asyncio .set_event_loop (None )
250+ asyncio .set_event_loop (self .loop )
251+ ev = asyncio .Event ()
252+ self .assertIs (ev ._loop , self .loop )
267253
268254 def test_repr (self ):
269255 ev = asyncio .Event (loop = self .loop )
@@ -376,14 +362,10 @@ def c1(result):
376362 self .assertTrue (t .result ())
377363
378364
379- class ConditionTests (unittest .TestCase ):
365+ class ConditionTests (test_utils .TestCase ):
380366
381367 def setUp (self ):
382- self .loop = test_utils .TestLoop ()
383- asyncio .set_event_loop (None )
384-
385- def tearDown (self ):
386- self .loop .close ()
368+ self .loop = self .new_test_loop ()
387369
388370 def test_ctor_loop (self ):
389371 loop = mock .Mock ()
@@ -394,12 +376,9 @@ def test_ctor_loop(self):
394376 self .assertIs (cond ._loop , self .loop )
395377
396378 def test_ctor_noloop (self ):
397- try :
398- asyncio .set_event_loop (self .loop )
399- cond = asyncio .Condition ()
400- self .assertIs (cond ._loop , self .loop )
401- finally :
402- asyncio .set_event_loop (None )
379+ asyncio .set_event_loop (self .loop )
380+ cond = asyncio .Condition ()
381+ self .assertIs (cond ._loop , self .loop )
403382
404383 def test_wait (self ):
405384 cond = asyncio .Condition (loop = self .loop )
@@ -678,14 +657,10 @@ def test_context_manager_no_yield(self):
678657 self .assertFalse (cond .locked ())
679658
680659
681- class SemaphoreTests (unittest .TestCase ):
660+ class SemaphoreTests (test_utils .TestCase ):
682661
683662 def setUp (self ):
684- self .loop = test_utils .TestLoop ()
685- asyncio .set_event_loop (None )
686-
687- def tearDown (self ):
688- self .loop .close ()
663+ self .loop = self .new_test_loop ()
689664
690665 def test_ctor_loop (self ):
691666 loop = mock .Mock ()
@@ -696,12 +671,9 @@ def test_ctor_loop(self):
696671 self .assertIs (sem ._loop , self .loop )
697672
698673 def test_ctor_noloop (self ):
699- try :
700- asyncio .set_event_loop (self .loop )
701- sem = asyncio .Semaphore ()
702- self .assertIs (sem ._loop , self .loop )
703- finally :
704- asyncio .set_event_loop (None )
674+ asyncio .set_event_loop (self .loop )
675+ sem = asyncio .Semaphore ()
676+ self .assertIs (sem ._loop , self .loop )
705677
706678 def test_initial_value_zero (self ):
707679 sem = asyncio .Semaphore (0 , loop = self .loop )
0 commit comments