Skip to content

Commit bffb35f

Browse files
author
MarcoFalke
committed
Merge #13054: tests: Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
68400d8 tests: Use explicit imports (practicalswift) Pull request description: Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports. Wildcard imports make it unclear which names are present in the namespace, confusing both readers and many automated tools. An additional benefit of not using wildcard imports in tests scripts is that readers of a test script then can infer the rough testing scope just by looking at the imports. Before this commit: ``` $ contrib/devtools/lint-python.sh | head -10 ./test/functional/feature_rbf.py:8:1: F403 'from test_framework.util import *' used; unable to detect undefined names ./test/functional/feature_rbf.py:9:1: F403 'from test_framework.script import *' used; unable to detect undefined names ./test/functional/feature_rbf.py:10:1: F403 'from test_framework.mininode import *' used; unable to detect undefined names ./test/functional/feature_rbf.py:15:12: F405 bytes_to_hex_str may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:17:58: F405 CScript may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:25:13: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:26:31: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:26:60: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:30:41: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util ./test/functional/feature_rbf.py:30:68: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util $ ``` After this commit: ``` $ contrib/devtools/lint-python.sh | head -10 $ ``` Tree-SHA512: 3f826d39cffb6438388e5efcb20a9622ff8238247e882d68f7b38609877421b2a8e10e9229575f8eb6a8fa42dec4256986692e92922c86171f750a0e887438d9
2 parents 73a09b4 + 68400d8 commit bffb35f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+143
-94
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test BIP68 implementation."""
66

7+
import time
8+
9+
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment
10+
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, ToHex
11+
from test_framework.script import CScript
712
from test_framework.test_framework import BitcoinTestFramework
8-
from test_framework.util import *
9-
from test_framework.blocktools import *
13+
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, bytes_to_hex_str, get_bip9_status, satoshi_round, sync_blocks
1014

1115
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
1216
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)

test/functional/feature_cltv.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
1351.
99
"""
1010

11-
from test_framework.test_framework import BitcoinTestFramework
12-
from test_framework.util import *
13-
from test_framework.mininode import *
1411
from test_framework.blocktools import create_coinbase, create_block, create_transaction
12+
from test_framework.messages import CTransaction, msg_block, ToHex
13+
from test_framework.mininode import mininode_lock, P2PInterface
1514
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP, CScriptNum
15+
from test_framework.test_framework import BitcoinTestFramework
16+
from test_framework.util import assert_equal, bytes_to_hex_str, hex_str_to_bytes, wait_until
17+
1618
from io import BytesIO
1719

1820
CLTV_HEIGHT = 1351

test/functional/feature_dbcrash.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
import sys
3232
import time
3333

34-
from test_framework.mininode import *
35-
from test_framework.script import *
34+
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, ToHex
3635
from test_framework.test_framework import BitcoinTestFramework
37-
from test_framework.util import *
36+
from test_framework.util import assert_equal, create_confirmed_utxos, hex_str_to_bytes
3837

3938
HTTP_DISCONNECT_ERRORS = [http.client.CannotSendRequest]
4039
try:

test/functional/feature_dersig.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
Test that the DERSIG soft-fork activates at (regtest) height 1251.
88
"""
99

10-
from test_framework.test_framework import BitcoinTestFramework
11-
from test_framework.util import *
12-
from test_framework.mininode import *
1310
from test_framework.blocktools import create_coinbase, create_block, create_transaction
11+
from test_framework.messages import msg_block
12+
from test_framework.mininode import mininode_lock, P2PInterface
1413
from test_framework.script import CScript
14+
from test_framework.test_framework import BitcoinTestFramework
15+
from test_framework.util import assert_equal, bytes_to_hex_str, wait_until
1516

1617
DERSIG_HEIGHT = 1251
1718

test/functional/feature_fee_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from decimal import Decimal
77
import random
88

9-
from test_framework.mininode import CTransaction, CTxIn, CTxOut, COutPoint, ToHex, COIN
9+
from test_framework.messages import CTransaction, CTxIn, CTxOut, COutPoint, ToHex, COIN
1010
from test_framework.script import CScript, OP_1, OP_DROP, OP_2, OP_HASH160, OP_EQUAL, hash160, OP_TRUE
1111
from test_framework.test_framework import BitcoinTestFramework
1212
from test_framework.util import (

test/functional/feature_maxuploadtarget.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from collections import defaultdict
1414
import time
1515

16-
from test_framework.mininode import *
16+
from test_framework.messages import CInv, msg_getdata
17+
from test_framework.mininode import P2PInterface
1718
from test_framework.test_framework import BitcoinTestFramework
18-
from test_framework.util import *
19+
from test_framework.util import assert_equal, mine_large_block
1920

2021
class TestP2PConn(P2PInterface):
2122
def __init__(self):

test/functional/feature_nulldummy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
1414
"""
1515

16-
from test_framework.test_framework import BitcoinTestFramework
17-
from test_framework.util import *
18-
from test_framework.messages import CTransaction
1916
from test_framework.blocktools import create_coinbase, create_block, create_transaction, add_witness_commitment
17+
from test_framework.messages import CTransaction
2018
from test_framework.script import CScript
19+
from test_framework.test_framework import BitcoinTestFramework
20+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str
21+
2122
import time
2223

2324
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"

test/functional/feature_pruning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"""
1111

1212
from test_framework.test_framework import BitcoinTestFramework
13-
from test_framework.util import *
13+
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, connect_nodes, mine_large_block, sync_blocks, wait_until
14+
1415
import os
1516

1617
MIN_BLOCKS_TO_KEEP = 288

test/functional/feature_rbf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the RBF code."""
66

7+
from decimal import Decimal
8+
9+
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
10+
from test_framework.script import CScript, OP_DROP
711
from test_framework.test_framework import BitcoinTestFramework
8-
from test_framework.util import *
9-
from test_framework.script import *
10-
from test_framework.mininode import *
12+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, satoshi_round
1113

1214
MAX_REPLACEMENT_LIMIT = 100
1315

test/functional/feature_segwit.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the SegWit changeover logic."""
66

7+
from decimal import Decimal
8+
79
from test_framework.address import (
10+
key_to_p2pkh,
811
key_to_p2sh_p2wpkh,
912
key_to_p2wpkh,
1013
program_to_witness,
14+
script_to_p2sh,
1115
script_to_p2sh_p2wsh,
1216
script_to_p2wsh,
1317
)
1418
from test_framework.blocktools import witness_script, send_to_witness
15-
from test_framework.test_framework import BitcoinTestFramework
16-
from test_framework.util import *
17-
from test_framework.mininode import sha256, CTransaction, CTxIn, COutPoint, CTxOut, COIN, ToHex, FromHex
18-
from test_framework.address import script_to_p2sh, key_to_p2pkh
19+
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex
1920
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP
21+
from test_framework.test_framework import BitcoinTestFramework
22+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc
23+
2024
from io import BytesIO
2125

2226
NODE_0 = 0

0 commit comments

Comments
 (0)