Skip to content

Commit 9837a35

Browse files
committed
Replace try-except blocks with contextlib.suppress across test files for cleaner exception handling.
1 parent 46e0c70 commit 9837a35

4 files changed

Lines changed: 11 additions & 28 deletions

File tree

tests/test_address.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from decimal import Decimal
23

34
import pytest
@@ -19,11 +20,8 @@ def test_query_is_built_correctly(self):
1920
"errors": [],
2021
},
2122
)
22-
try:
23+
with contextlib.suppress(KeyError):
2324
get_address("test_hash_123")
24-
except KeyError:
25-
# catch where get_address_info fails to serialize mis-built response
26-
pass
2725

2826
query = m.last_request.json()["query"]
2927
assert 'address(hash: "test_hash_123") {' in query
@@ -88,17 +86,14 @@ def test_query_is_built_correctly(self):
8886
"errors": [],
8987
},
9088
)
91-
try:
89+
with contextlib.suppress(KeyError):
9290
get_addresses(
9391
[
9492
"hash_1",
9593
"hash_2",
9694
"hash_3",
9795
]
9896
)
99-
except KeyError:
100-
# catch where get_address_info fails to serialize mis-built response
101-
pass
10297

10398
query = m.last_request.json()["query"]
10499
assert 'addresses(hashes: ["hash_1", "hash_2", "hash_3"]) {' in query

tests/test_block.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from datetime import datetime, timezone
23
from decimal import Decimal
34

@@ -18,11 +19,8 @@ def test_query_is_built_correctly(self):
1819
"errors": [],
1920
},
2021
)
21-
try:
22+
with contextlib.suppress(KeyError):
2223
get_block(123)
23-
except KeyError:
24-
# catch where get_block_info fails to serialize mis-built response
25-
pass
2624

2725
query = m.last_request.json()["query"]
2826
assert "block(number: 123)" in query

tests/test_token_transfers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from decimal import Decimal
23

34
import requests_mock
@@ -17,11 +18,8 @@ def test_query_is_built_correctly(self):
1718
"errors": [],
1819
},
1920
)
20-
try:
21+
with contextlib.suppress(KeyError):
2122
get_token_transfers("hash", previous_cursor="prev")
22-
except KeyError:
23-
# catch where get_token_transfers fails to serialize mis-built response
24-
pass
2523

2624
query = m.last_request.json()["query"]
2725
assert (

tests/test_transaction.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from decimal import Decimal
23

34
import requests_mock
@@ -23,11 +24,8 @@ def test_query_is_built_correctly(self):
2324
"errors": [],
2425
},
2526
)
26-
try:
27+
with contextlib.suppress(KeyError):
2728
get_transaction("test_hash_123")
28-
except KeyError:
29-
# catch where get_transaction_info fails to serialize mis-built response
30-
pass
3129

3230
query = m.last_request.json()["query"]
3331
assert 'transaction(hash: "test_hash_123")' in query
@@ -113,11 +111,8 @@ def test_query_is_built_correctly(self):
113111
"errors": [],
114112
},
115113
)
116-
try:
114+
with contextlib.suppress(TypeError):
117115
get_internal_transactions("hash", previous_cursor="prev")
118-
except TypeError:
119-
# catch where get_internal_transactions fails to serialize mis-built response
120-
pass
121116

122117
query = m.last_request.json()["query"]
123118
assert 'transaction(hash: "hash") {' in query
@@ -304,11 +299,8 @@ def test_query_is_built_correctly(self):
304299
"errors": [],
305300
},
306301
)
307-
try:
302+
with contextlib.suppress(KeyError):
308303
get_transactions_from_address("hash", previous_cursor="prev")
309-
except KeyError:
310-
# catch where get_internal_transactions fails to serialize mis-built response
311-
pass
312304

313305
query = m.last_request.json()["query"]
314306
assert 'address(hash: "hash") {' in query

0 commit comments

Comments
 (0)