1
-
2
1
try :
3
2
from cassandra .io .asyncioreactor import AsyncioConnection
4
3
import asynctest
5
4
ASYNCIO_AVAILABLE = True
6
5
except (ImportError , SyntaxError ):
6
+ AysncioConnection = None
7
7
ASYNCIO_AVAILABLE = False
8
8
9
- from tests import is_monkey_patched
9
+ from tests import is_monkey_patched , connection_class
10
10
from tests .unit .io .utils import TimerCallback , TimerTestMixin
11
11
12
12
from mock import patch
13
13
14
14
import unittest
15
15
import time
16
16
17
+ skip_me = (is_monkey_patched () or
18
+ (not ASYNCIO_AVAILABLE ) or
19
+ (connection_class is not AsyncioConnection ))
20
+
17
21
22
+ @unittest .skipIf (is_monkey_patched (), 'runtime is monkey patched for another reactor' )
23
+ @unittest .skipIf (connection_class is not AsyncioConnection ,
24
+ 'not running asyncio tests; current connection_class is {}' .format (connection_class ))
18
25
@unittest .skipUnless (ASYNCIO_AVAILABLE , "asyncio is not available for this runtime" )
19
26
class AsyncioTimerTests (TimerTestMixin , unittest .TestCase ):
20
27
21
28
@classmethod
22
29
def setUpClass (cls ):
23
- if is_monkey_patched () or not ASYNCIO_AVAILABLE :
30
+ if skip_me :
24
31
return
25
32
cls .connection_class = AsyncioConnection
26
33
AsyncioConnection .initialize_reactor ()
27
34
28
35
@classmethod
29
36
def tearDownClass (cls ):
30
- if ASYNCIO_AVAILABLE :
37
+ if skip_me :
38
+ return
39
+ if ASYNCIO_AVAILABLE and AsyncioConnection ._loop :
31
40
AsyncioConnection ._loop .stop ()
32
41
33
42
@property
@@ -39,6 +48,8 @@ def _timers(self):
39
48
raise RuntimeError ('no TimerManager for AsyncioConnection' )
40
49
41
50
def setUp (self ):
51
+ if skip_me :
52
+ return
42
53
socket_patcher = patch ('socket.socket' )
43
54
self .addCleanup (socket_patcher .stop )
44
55
socket_patcher .start ()
0 commit comments