Skip to content

Commit 9a5c56c

Browse files
committed
Exercise doctests in _utils.abi
Includes fixes for previously broken doctests.
1 parent 0cd7aa6 commit 9a5c56c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tests/core/utilities/test_abi.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
1+
import doctest
22
import pytest
33

4+
import web3._utils.abi
45
from web3._utils.abi import (
56
ABITypedData,
67
abi_data_tree,
@@ -162,3 +163,11 @@ def test_map_abi_data(types, data, funcs, expected):
162163
)
163164
def test_get_abi_inputs(function_abi, arg_values, expected):
164165
assert get_abi_inputs(function_abi, arg_values) == expected
166+
167+
168+
def test_docstrings(capsys):
169+
"""Exercise docstrings in the web3._utils.abi module."""
170+
# disable stdout capture so failed tests will show why they failed
171+
with capsys.disabled():
172+
failure_count, _ = doctest.testmod(web3._utils.abi)
173+
assert failure_count == 0

web3/_utils/abi.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ def abi_data_tree(types, data):
596596
As an example:
597597
598598
>>> abi_data_tree(types=["bool[2]", "uint"], data=[[True, False], 0])
599-
[("bool[2]", [("bool", True), ("bool", False)]), ("uint256", 0)]
600-
'''
599+
[ABITypedData(abi_type='bool[2]', data=[ABITypedData(abi_type='bool', data=True), ABITypedData(abi_type='bool', data=False)]), ABITypedData(abi_type='uint256', data=0)]
600+
''' # noqa: E501 (line too long)
601601
return [
602602
abi_sub_tree(data_type, data_value)
603603
for data_type, data_value
@@ -629,9 +629,11 @@ class ABITypedData(namedtuple('ABITypedData', 'abi_type, data')):
629629
'''
630630
This class marks data as having a certain ABI-type.
631631
632+
>>> addr1 = "0x" + "0" * 20
633+
>>> addr2 = "0x" + "f" * 20
632634
>>> a1 = ABITypedData(['address', addr1])
633635
>>> a2 = ABITypedData(['address', addr2])
634-
>>> addrs = ABITypedData(['address[]', [a1, a2])
636+
>>> addrs = ABITypedData(['address[]', [a1, a2]])
635637
636638
You can access the fields using tuple() interface, or with
637639
attributes:

0 commit comments

Comments
 (0)