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 44import time
55
66import uvloop
7+ import unittest
78
89from unittest import mock
910from uvloop ._testbase import UVTestCase , AIOTestCase
@@ -398,3 +399,17 @@ class TestBaseUV(_TestBase, UVTestCase):
398399
399400class TestBaseAIO (_TestBase , AIOTestCase ):
400401 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 11import asyncio
22
3+ from asyncio .events import BaseDefaultEventLoopPolicy as __BasePolicy
4+
35from . import includes as __includes
46from .loop import Loop as __BaseLoop
57
68
9+ __all__ = ('new_event_loop' , 'EventLoopPolicy' )
10+
11+
712class _Loop (__BaseLoop , asyncio .AbstractEventLoop ):
813 pass
914
1015
1116def new_event_loop ():
17+ """Return a new event loop."""
1218 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:
764764 # Public API
765765
766766 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())
770773
771774 def call_soon (self , callback , *args ):
772775 if self ._debug == 1 :
You can’t perform that action at this time.
0 commit comments