Skip to content

Commit

Permalink
[REF] Replace all deprecated self.assertRaisesRegexp methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Dec 14, 2023
1 parent 5bb2912 commit 1d03dc2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 91 deletions.
34 changes: 17 additions & 17 deletions tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_path_expand(self):
self.assertListEqual(path_expand([], witness_type='p2sh-segwit'), ['m', "49'", "0'", "0'", '0', '0'])
self.assertListEqual(path_expand([99], witness_type='p2sh-segwit', multisig=True),
['m', "48'", "0'", "0'", "1'", '0', '99'])
self.assertRaisesRegexp(BKeyError, "Invalid path provided. Path should be shorter than 6 items.",
self.assertRaisesRegex(BKeyError, "Invalid path provided. Path should be shorter than 6 items.",
path_expand, [0, 1, 2, 3, 4, 5, 6])
self.assertRaisesRegexp(BKeyError, "Please provide path as list with at least 1 item",
self.assertRaisesRegex(BKeyError, "Please provide path as list with at least 1 item",
path_expand, 5)


Expand Down Expand Up @@ -110,8 +110,8 @@ def test_format_hdkey_mnemonic(self):
self.assertEqual(get_key_format('abandon car zoo')['format'], 'mnemonic')

def test_format_key_exceptions(self):
self.assertRaisesRegexp(BKeyError, "Key empty, please specify a valid key", get_key_format, '')
self.assertRaisesRegexp(BKeyError, "Attribute 'is_private' must be False or True", get_key_format,
self.assertRaisesRegex(BKeyError, "Key empty, please specify a valid key", get_key_format, '')
self.assertRaisesRegex(BKeyError, "Attribute 'is_private' must be False or True", get_key_format,
'666368e477a8ddd46808c527cc3c506719bb3f52a927b6c13532984b714b56ad', 3)


Expand Down Expand Up @@ -185,11 +185,11 @@ def test_private_key_import_generate_random(self):
self.assertEqual(52, len(self.k.wif()))

def test_private_key_import_error_1(self):
self.assertRaisesRegexp(BKeyError, "Invalid checksum, not a valid WIF key",
self.assertRaisesRegex(BKeyError, "Invalid checksum, not a valid WIF key",
Key, 'L1odb1uUozbfK2NrsMyhJfvRsxGM2axixgPL8vG9BUBnE6W1VyTX')

def test_private_key_import_error_2(self):
self.assertRaisesRegexp(BKeyError, "Unrecognised key format",
self.assertRaisesRegex(BKeyError, "Unrecognised key format",
Key, 'M1odb1uUozbfK2NrsMyhJfvRsxGM2AxixgPL8vG9BUBnE6W1VyTX')

def test_private_key_import_testnet(self):
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_public_key_try_private(self):
self.assertFalse(self.K.private_hex)

def test_public_key_import_error(self):
self.assertRaisesRegexp(BKeyError, "Unrecognised key format",
self.assertRaisesRegex(BKeyError, "Unrecognised key format",
Key, '064781e448a7ff0e1b66f1a249b4c952dae33326cf57c0a643738886f4efcd14d5')

def test_litecoin_private_key(self):
Expand Down Expand Up @@ -449,10 +449,10 @@ def test_hdkey_bip44_account_litecoin(self):

def test_hdkey_derive_from_public_error(self):
k = HDKey().public()
self.assertRaisesRegexp(BKeyError, "Need a private key to create child private key", k.child_private)
self.assertRaisesRegex(BKeyError, "Need a private key to create child private key", k.child_private)
k0 = HDKey()
k1 = k0.child_private(10, hardened=True)
self.assertRaisesRegexp(BKeyError, "Cannot derive hardened key from public private key",
self.assertRaisesRegex(BKeyError, "Cannot derive hardened key from public private key",
k1.child_public, 2147483659)


Expand Down Expand Up @@ -573,7 +573,7 @@ def test_bip38_invalid_keys(self):
return
for v in self.vectors["invalid"]["verify"]:
print("Checking invalid key %s" % v['base58'])
self.assertRaisesRegexp(Exception, "", Key, str(v['base58']))
self.assertRaisesRegex(Exception, "", Key, str(v['base58']))

def test_bip38_other_networks(self):
if not USING_MODULE_SCRYPT:
Expand Down Expand Up @@ -655,16 +655,16 @@ def test_keys_address_encodings(self):
self.assertEqual(a.address, 'tb1q8hehumvm039nxnwwtqdjr7qmm46sfxrdw7vc3g')

def test_keys_address_deserialize_exceptions(self):
self.assertRaisesRegexp(BKeyError, "Invalid address 17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bb, checksum incorrect",
self.assertRaisesRegex(BKeyError, "Invalid address 17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bb, checksum incorrect",
deserialize_address, '17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bb', encoding='base58')
self.assertRaisesRegexp(EncodingError,
self.assertRaisesRegex(EncodingError,
"Address 17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bd is not in specified encoding bs",
deserialize_address, '17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bd', encoding='bs')
self.assertRaisesRegexp(EncodingError,
self.assertRaisesRegex(EncodingError,
"Invalid address 17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bb: "
"Invalid bech32 character in bech string",
deserialize_address, '17N9VQbP89ThunSq7Yo2VooXCFTW1Lp8bb', encoding='bech32')
self.assertRaisesRegexp(EncodingError,
self.assertRaisesRegex(EncodingError,
"Address bc1qk077yl8zf6yty25rgrys8h40j8adun267y3m44 is not in specified "
"encoding base58",
deserialize_address, 'bc1qk077yl8zf6yty25rgrys8h40j8adun267y3m44', encoding='base58')
Expand Down Expand Up @@ -925,11 +925,11 @@ def test_signatures_from_r_and_s(self):

def test_signatures_rs_out_of_curve(self):
outofcurveint = 115792089237316195423570985008687907852837564279074904382605163141518161494339
self.assertRaisesRegexp(BKeyError, "r is not a positive integer smaller than the curve order",
self.assertRaisesRegex(BKeyError, "r is not a positive integer smaller than the curve order",
Signature, outofcurveint, 10)
self.assertRaisesRegexp(BKeyError, "r is not a positive integer smaller than the curve order",
self.assertRaisesRegex(BKeyError, "r is not a positive integer smaller than the curve order",
Signature, 0, 10)
self.assertRaisesRegexp(BKeyError, "s is not a positive integer smaller than the curve order",
self.assertRaisesRegex(BKeyError, "s is not a positive integer smaller than the curve order",
Signature, 11, outofcurveint)

def test_signatures_dunder(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_mnemonic_generate(self):
self.assertEqual(Mnemonic.detect_language(phrase), 'dutch')

def test_mnemonic_generate_error(self):
self.assertRaisesRegexp(ValueError, 'Strength should be divisible by 32', Mnemonic().generate, 11)
self.assertRaisesRegex(ValueError, 'Strength should be divisible by 32', Mnemonic().generate, 11)

def test_mnemonic_to_entropy(self):
phrase = 'usage grid neither voice worry armor sudden core excuse keen stand pudding'
Expand All @@ -68,22 +68,22 @@ def test_mnemonic_to_mnemonic(self):
'chunk gun celery million wood kite tackle twenty story episode raccoon dutch')
self.assertEqual(Mnemonic().to_mnemonic('28acfc94465fd2f6774759d6897ec122', add_checksum=False),
'action filter venture match garlic nut oven modify output dwarf wild cattle')
self.assertRaisesRegexp(ValueError, "Integer value of data should be in secp256k1 domain between 1 and "
self.assertRaisesRegex(ValueError, "Integer value of data should be in secp256k1 domain between 1 and "
"secp256k1_n-1", Mnemonic().to_mnemonic,
'28acfc94465fd2f6774759d6897ec12228acfc94465fd2f6774759d6897ec12228acfc94465fd2f6774')

def test_mnemonic_to_seed_invalid_checksum(self):
phrase = "runway truly foil future recall scatter garage over floor clutch shy boat"
self.assertRaisesRegexp(ValueError, "Invalid checksum 0110 for entropy", Mnemonic().to_seed, phrase)
self.assertRaisesRegex(ValueError, "Invalid checksum 0110 for entropy", Mnemonic().to_seed, phrase)

def test_mnemonic_exceptions(self):
self.assertRaisesRegexp(ValueError, "Strength should be divisible by 32", Mnemonic().generate, 20)
self.assertRaisesRegexp(ValueError, "Data length in bits should be divisible by 32", Mnemonic().checksum,
self.assertRaisesRegex(ValueError, "Strength should be divisible by 32", Mnemonic().generate, 20)
self.assertRaisesRegex(ValueError, "Data length in bits should be divisible by 32", Mnemonic().checksum,
'aabbccddeeff')
self.assertRaisesRegexp(Warning, "Unrecognised word",
self.assertRaisesRegex(Warning, "Unrecognised word",
Mnemonic().sanitize_mnemonic,
'action filter venture match garlic nut oven modify output dwarf wild fiets')
self.assertRaisesRegexp(Warning, "Could not detect language",
self.assertRaisesRegex(Warning, "Could not detect language",
Mnemonic().detect_language,
'floep fliep')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_networks_network_value_for(self):
def test_network_defined(self):
self.assertTrue(network_defined('bitcoin'))
self.assertFalse(network_defined('bitcoiiin'))
self.assertRaisesRegexp(NetworkError, "Network bitcoiin not found in network definitions", Network, 'bitcoiin')
self.assertRaisesRegex(NetworkError, "Network bitcoiin not found in network definitions", Network, 'bitcoiin')

def test_wif_prefix_search(self):
exp_dict = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ def test_script_multisig_errors(self):
'd1b1ec45d76724f26901099416b9265b76ba67c8b0b73d'
'210202be80a0ca69c0e000b97d507f45b98c49f58fec6650b64ff70e6ffccc3e6d00'
'210202be80a0ca69c0e000b97d507f45b98c49f58fec6650b64ff70e6ffccc3e6d0052ae')
self.assertRaisesRegexp(ScriptError, '3 keys found but 2 keys expected',
self.assertRaisesRegex(ScriptError, '3 keys found but 2 keys expected',
Script.parse, scr)
self.assertRaisesRegexp(ScriptError, 'Number of signatures required \(3\) is higher then number of keys \(2\)',
self.assertRaisesRegex(ScriptError, 'Number of signatures required \(3\) is higher then number of keys \(2\)',
Script.parse,
'532102d9d64770e0510c650cfaa0c05ba34f6faa35a18defcf9f2d493c4c225d93fbf221020c39c418c2'
'38ba876d09c4529bdafb2a1295c57ece923997ab693bf0a84189b852ae')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_service_gettransactions_after_txid_litecoin(self):
self.assertEqual(res[0].txid, 'e0c1e90fa2195869905e90d4fa644082dfd0523540c13baea0c7a4e246ef40e4')

def test_service_gettransactions_addresslist_error(self):
self.assertRaisesRegexp(ServiceError, "Address parameter must be of type text",
self.assertRaisesRegex(ServiceError, "Address parameter must be of type text",
ServiceTest().gettransactions,
['1LGJzocooaciEtsxEVAajLhCymCXNvPoLh', '19KedreX9aR64fN7tnNzVLVFHQAUL6dLzr'])

Expand Down Expand Up @@ -689,7 +689,7 @@ def test_service_max_providers(self):
self.assertEqual(srv.resultcount, 1)

def test_service_errors(self):
self.assertRaisesRegexp(ServiceError, "Provider 'unknown_provider' not found in provider definitions",
self.assertRaisesRegex(ServiceError, "Provider 'unknown_provider' not found in provider definitions",
Service, providers='unknown_provider')

def test_service_mempool(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_transactions_deserialize_p2sh_output(self):

def test_transactions_deserialize_errors(self):
rawtx = '01000000000102c114c54564ea09b33c73bfd0237a4d283fe9e73285ad6d34fd3fa42c99f194640300000000ffffffff'
self.assertRaisesRegexp(TransactionError,
self.assertRaisesRegex(TransactionError,
'Input transaction hash not found. Probably malformed raw transaction',
Transaction.parse_hex, rawtx)
# FIXME: tx.parse_hex() should check remaining size
Expand All @@ -225,7 +225,7 @@ def test_transactions_deserialize_errors(self):
# '3c12b67ddd3cf8127fe054dec971c858252c004bf8016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea36' \
# '8e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5' \
# 'ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae000000'
# self.assertRaisesRegexp(TransactionError,
# self.assertRaisesRegex(TransactionError,
# 'Error when deserializing raw transaction, bytes left for locktime must be 4 not 3',
# Transaction.parse, rawtx)
# rawtx = '01000000000101c114c54564ea09b33c73bfd0237a4d283fe9e73285ad6d34fd3fa42c99f194640300000000ffffffff0200' \
Expand All @@ -236,7 +236,7 @@ def test_transactions_deserialize_errors(self):
# '3c12b67ddd3cf8127fe054dec971c858252c004bf8016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea36' \
# '8e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70f01874496feff2103c96d495bfdd5' \
# 'ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000'
# self.assertRaisesRegexp(TransactionError,
# self.assertRaisesRegex(TransactionError,
# "Error when deserializing raw transaction, bytes left for locktime must be 4 not 3",
# Transaction.parse, rawtx)

Expand Down Expand Up @@ -1029,7 +1029,7 @@ def test_transactions_parse_totals(self):

def test_transaction_sendto_wrong_address(self):
t = Transaction(network='bitcoin')
self.assertRaisesRegexp(BKeyError, 'Network bitcoin not found in extracted networks*',
self.assertRaisesRegex(BKeyError, 'Network bitcoin not found in extracted networks*',
t.add_output, 100000, 'LTK1nK5TyGALmSup5SzhgkX1cnVQrC4cLd')

def test_transaction_create_with_address_objects(self):
Expand All @@ -1052,7 +1052,7 @@ def test_transaction_info(self):
self.assertIsNone(t.info())

def test_transaction_errors(self):
self.assertRaisesRegexp(TransactionError, "Please specify a valid witness type: legacy or segwit",
self.assertRaisesRegex(TransactionError, "Please specify a valid witness type: legacy or segwit",
Transaction, witness_type='error')


Expand All @@ -1063,7 +1063,7 @@ def test_transaction_redeemscript_errors(self):
keys = []
for n in range(20):
keys.append(HDKey().public_hex)
self.assertRaisesRegexp(TransactionError, exp_error, serialize_multisig_redeemscript, keys)
self.assertRaisesRegex(TransactionError, exp_error, serialize_multisig_redeemscript, keys)

def test_transaction_script_type_string(self):
# Locking script
Expand Down Expand Up @@ -1178,7 +1178,7 @@ def test_transaction_locktime(self):

def test_transaction_get_unlocking_script_type(self):
self.assertEqual(get_unlocking_script_type('p2pk'), 'signature')
self.assertRaisesRegexp(TransactionError, "Unknown locking script type troep", get_unlocking_script_type,
self.assertRaisesRegex(TransactionError, "Unknown locking script type troep", get_unlocking_script_type,
'troep')

def test_transaction_equal(self):
Expand Down
Loading

0 comments on commit 1d03dc2

Please sign in to comment.