Skip to content

Commit 0569189

Browse files
committed
Fix tests related to attribute dict formatter changes
- fix test_process_params to expect one result formatter - add attribute dict middlewares to sync and async local filter middleware tests - add attrdict middleware check to async http provider test
1 parent 975fcad commit 0569189

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

tests/core/method-class/test_method.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@ def test_process_params(
337337
object(), *args, **kwargs
338338
)
339339
assert request_params == expected_request_result
340-
first_formatter = (output_formatter[0].first,)
341-
all_other_formatters = output_formatter[0].funcs
342340

343-
# the expected result formatters length is 2
344-
assert len(first_formatter + all_other_formatters) == 2
341+
first_formatter = (output_formatter[0],)
342+
343+
# the expected result formatters length is 1
344+
assert len(first_formatter) == 1
345345

346346

347347
def keywords(module, keyword_one, keyword_two):

tests/core/middleware/test_filter_middleware.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
AsyncEth,
1616
)
1717
from web3.middleware import (
18+
async_attrdict_middleware,
1819
async_construct_result_generator_middleware,
1920
async_local_filter_middleware,
21+
attrdict_middleware,
2022
construct_result_generator_middleware,
2123
local_filter_middleware,
2224
)
@@ -105,6 +107,7 @@ def w3_base():
105107
@pytest.fixture(scope="function")
106108
def w3(w3_base, result_generator_middleware):
107109
w3_base.middleware_onion.add(result_generator_middleware)
110+
w3_base.middleware_onion.add(attrdict_middleware)
108111
w3_base.middleware_onion.add(local_filter_middleware)
109112
return w3_base
110113

@@ -284,6 +287,7 @@ def async_w3_base():
284287
@pytest.fixture(scope="function")
285288
def async_w3(async_w3_base, async_result_generator_middleware):
286289
async_w3_base.middleware_onion.add(async_result_generator_middleware)
290+
async_w3_base.middleware_onion.add(async_attrdict_middleware)
287291
async_w3_base.middleware_onion.add(async_local_filter_middleware)
288292
return async_w3_base
289293

tests/core/providers/test_async_http_provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Geth,
2121
)
2222
from web3.middleware import (
23+
async_attrdict_middleware,
2324
async_buffered_gas_estimate_middleware,
2425
async_gas_price_strategy_middleware,
2526
async_validation_middleware,
@@ -63,12 +64,13 @@ def test_web3_with_async_http_provider_has_default_middlewares_and_modules() ->
6364

6465
# the following length check should fail and will need to be added to once more
6566
# async middlewares are added to the defaults
66-
assert len(async_w3.middleware_onion.middlewares) == 3
67+
assert len(async_w3.middleware_onion.middlewares) == 4
6768

6869
assert (
6970
async_w3.middleware_onion.get("gas_price_strategy")
7071
== async_gas_price_strategy_middleware
7172
)
73+
assert async_w3.middleware_onion.get("attrdict") == async_attrdict_middleware
7274
assert async_w3.middleware_onion.get("validation") == async_validation_middleware
7375
assert (
7476
async_w3.middleware_onion.get("gas_estimate")

web3/_utils/method_formatters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ def is_attrdict(val: Any) -> bool:
152152
return isinstance(val, AttributeDict)
153153

154154

155-
not_attrdict = complement(is_attrdict)
156-
157-
158155
@curry
159156
def type_aware_apply_formatters_to_dict(
160157
formatters: Formatters,
161158
value: Union[AttributeDict[str, Any], Dict[str, Any]],
162159
) -> Union[ReadableAttributeDict[str, Any], Dict[str, Any]]:
160+
"""
161+
Preserve ``AttributeDict`` types if original ``value`` was an ``AttributeDict``.
162+
"""
163163
formatted_dict: Dict[str, Any] = apply_formatters_to_dict(formatters, dict(value))
164164
return (
165165
AttributeDict.recursive(formatted_dict)

0 commit comments

Comments
 (0)