File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 4
4
import time
5
5
6
6
import uvloop
7
+ import unittest
7
8
8
9
from unittest import mock
9
10
from uvloop ._testbase import UVTestCase , AIOTestCase
@@ -398,3 +399,17 @@ class TestBaseUV(_TestBase, UVTestCase):
398
399
399
400
class TestBaseAIO (_TestBase , AIOTestCase ):
400
401
pass
402
+
403
+
404
+ class TestPolicy (unittest .TestCase ):
405
+
406
+ def test_uvloop_policy (self ):
407
+ try :
408
+ asyncio .set_event_loop_policy (uvloop .EventLoopPolicy ())
409
+ loop = asyncio .new_event_loop ()
410
+ try :
411
+ self .assertIsInstance (loop , uvloop ._Loop )
412
+ finally :
413
+ loop .close ()
414
+ finally :
415
+ asyncio .set_event_loop_policy (None )
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
3
+ from asyncio .events import BaseDefaultEventLoopPolicy as __BasePolicy
4
+
3
5
from . import includes as __includes
4
6
from .loop import Loop as __BaseLoop
5
7
6
8
9
+ __all__ = ('new_event_loop' , 'EventLoopPolicy' )
10
+
11
+
7
12
class _Loop (__BaseLoop , asyncio .AbstractEventLoop ):
8
13
pass
9
14
10
15
11
16
def new_event_loop ():
17
+ """Return a new event loop."""
12
18
return _Loop ()
19
+
20
+
21
+ class EventLoopPolicy (__BasePolicy ):
22
+ """Event loop policy.
23
+
24
+ The preferred way to make your application use uvloop:
25
+
26
+ >>> import asyncio
27
+ >>> import uvloop
28
+ >>> asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
29
+ >>> asyncio.get_event_loop()
30
+ <uvloop._Loop running=False closed=False debug=False>
31
+ """
32
+
33
+ def _loop_factory (self ):
34
+ return new_event_loop ()
Original file line number Diff line number Diff line change @@ -764,9 +764,12 @@ cdef class Loop:
764
764
# Public API
765
765
766
766
def __repr__ (self ):
767
- return (' <%s running=%s closed=%s debug=%s >'
768
- % (self .__class__.__name__ , self .is_running(),
769
- self .is_closed(), self .get_debug()))
767
+ return ' <{}.{} running={} closed={} debug={}>' .format(
768
+ self .__class__.__module__,
769
+ self .__class__.__name__ ,
770
+ self .is_running(),
771
+ self .is_closed(),
772
+ self .get_debug())
770
773
771
774
def call_soon (self , callback , *args ):
772
775
if self ._debug == 1 :
You can’t perform that action at this time.
0 commit comments