File tree Expand file tree Collapse file tree 3 files changed +26
-15
lines changed Expand file tree Collapse file tree 3 files changed +26
-15
lines changed Original file line number Diff line number Diff line change 3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test the ZMQ notification interface."""
6
- import configparser
7
6
import struct
8
7
9
- from test_framework .test_framework import BitcoinTestFramework , SkipTest
8
+ from test_framework .test_framework import (
9
+ BitcoinTestFramework , skip_if_no_bitcoind_zmq , skip_if_no_py3_zmq )
10
10
from test_framework .mininode import CTransaction
11
11
from test_framework .util import (assert_equal ,
12
12
bytes_to_hex_str ,
@@ -38,18 +38,9 @@ def set_test_params(self):
38
38
self .num_nodes = 2
39
39
40
40
def setup_nodes (self ):
41
- # Try to import python3-zmq. Skip this test if the import fails.
42
- try :
43
- import zmq
44
- except ImportError :
45
- raise SkipTest ("python3-zmq module not available." )
46
-
47
- # Check that bitcoin has been built with ZMQ enabled.
48
- config = configparser .ConfigParser ()
49
- config .read_file (open (self .options .configfile ))
50
-
51
- if not config ["components" ].getboolean ("ENABLE_ZMQ" ):
52
- raise SkipTest ("bitcoind has not been built with zmq enabled." )
41
+ skip_if_no_py3_zmq ()
42
+ skip_if_no_bitcoind_zmq (self )
43
+ import zmq
53
44
54
45
# Initialize ZMQ context and socket.
55
46
# All messages are received in the same socket which means
Original file line number Diff line number Diff line change 4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test for the ZMQ RPC methods."""
6
6
7
- from test_framework .test_framework import BitcoinTestFramework
7
+ from test_framework .test_framework import (
8
+ BitcoinTestFramework , skip_if_no_py3_zmq , skip_if_no_bitcoind_zmq )
8
9
from test_framework .util import assert_equal
9
10
10
11
@@ -17,6 +18,8 @@ def set_test_params(self):
17
18
self .setup_clean_chain = True
18
19
19
20
def run_test (self ):
21
+ skip_if_no_py3_zmq ()
22
+ skip_if_no_bitcoind_zmq (self )
20
23
self ._test_getzmqnotifications ()
21
24
22
25
def _test_getzmqnotifications (self ):
Original file line number Diff line number Diff line change @@ -475,3 +475,20 @@ class SkipTest(Exception):
475
475
"""This exception is raised to skip a test"""
476
476
def __init__ (self , message ):
477
477
self .message = message
478
+
479
+
480
+ def skip_if_no_py3_zmq ():
481
+ """Attempt to import the zmq package and skip the test if the import fails."""
482
+ try :
483
+ import zmq # noqa
484
+ except ImportError :
485
+ raise SkipTest ("python3-zmq module not available." )
486
+
487
+
488
+ def skip_if_no_bitcoind_zmq (test_instance ):
489
+ """Skip the running test if bitcoind has not been compiled with zmq support."""
490
+ config = configparser .ConfigParser ()
491
+ config .read_file (open (test_instance .options .configfile ))
492
+
493
+ if not config ["components" ].getboolean ("ENABLE_ZMQ" ):
494
+ raise SkipTest ("bitcoind has not been built with zmq enabled." )
You can’t perform that action at this time.
0 commit comments