Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add black linting to tests/core #2551

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/2551.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add black linting to the ``tests/core`` directory
2 changes: 1 addition & 1 deletion tests/core/admin-module/test_admin_addPeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ def test_admin_add_peer(w3, skip_if_testrpc):
skip_if_testrpc(w3)

result = w3.geth.admin.add_peer(
'enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@127.0.0.1:30304', # noqa: E501
"enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@127.0.0.1:30304", # noqa: E501
)
assert result is True
4 changes: 2 additions & 2 deletions tests/core/admin-module/test_admin_nodeInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ def test_admin_node_info(w3, skip_if_testrpc):

node_info = w3.geth.admin.node_info

assert 'enode' in node_info
assert 'id' in node_info
assert "enode" in node_info
assert "id" in node_info
55 changes: 31 additions & 24 deletions tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,54 @@
# --- inherit from `web3.module.Module` class --- #


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module1():
class Module1(Module):
a = 'a'
a = "a"

@property
def b(self):
return 'b'
return "b"

return Module1


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module2():
class Module2(Module):
c = 'c'
c = "c"

@staticmethod
def d():
return 'd'
return "d"

return Module2


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module3():
class Module3(Module):
e = 'e'
e = "e"

return Module3


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module4():
class Module4(Module):
f = 'f'
f = "f"

return Module4


# --- do not inherit from `web3.module.Module` class --- #


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module1_unique():
# uses ``Web3`` instance by accepting it as first arg in the ``__init__()`` method
class Module1:
a = 'a'
a = "a"

def __init__(self, w3):
self._b = "b"
Expand All @@ -71,57 +75,60 @@ def b(self):
@property
def return_eth_chain_id(self):
return self.w3.eth.chain_id

return Module1


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module2_unique():
class Module2:
c = 'c'
c = "c"

@staticmethod
def d():
return 'd'
return "d"

return Module2


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module3_unique():
class Module3:
e = 'e'
e = "e"

return Module3


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module4_unique():
class Module4:
f = 'f'
f = "f"

return Module4


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def module_many_init_args():
class ModuleManyArgs:
def __init__(self, a, b):
self.a = a
self.b = b

return ModuleManyArgs


@pytest_asyncio.fixture()
async def async_w3():
provider = AsyncEthereumTesterProvider()
w3 = Web3(provider, modules={'eth': [AsyncEth]},
middlewares=provider.middlewares)
w3 = Web3(provider, modules={"eth": [AsyncEth]}, middlewares=provider.middlewares)
w3.eth.default_account = await w3.eth.coinbase
return w3


@pytest_asyncio.fixture()
async def async_w3_strict_abi():
provider = AsyncEthereumTesterProvider()
w3 = Web3(provider, modules={'eth': [AsyncEth]},
middlewares=provider.middlewares)
w3 = Web3(provider, modules={"eth": [AsyncEth]}, middlewares=provider.middlewares)
w3.enable_strict_bytes_type_checking()
w3.eth.default_account = await w3.eth.coinbase
return w3
4 changes: 2 additions & 2 deletions tests/core/contracts/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def deploy(w3, Contract, apply_func=identity, args=None):
deploy_txn = Contract.constructor(*args).transact()
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = apply_func(deploy_receipt['contractAddress'])
address = apply_func(deploy_receipt["contractAddress"])
contract = Contract(address=address)
assert contract.address == address
assert len(w3.eth.get_code(contract.address)) > 0
Expand All @@ -22,7 +22,7 @@ async def async_deploy(async_web3, Contract, apply_func=identity, args=None):
deploy_txn = await Contract.constructor(*args).transact()
deploy_receipt = await async_web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = apply_func(deploy_receipt['contractAddress'])
address = apply_func(deploy_receipt["contractAddress"])
contract = Contract(address=address)
assert contract.address == address
assert len(await async_web3.eth.get_code(contract.address)) > 0
Expand Down
559 changes: 307 additions & 252 deletions tests/core/contracts/conftest.py

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions tests/core/contracts/test_args_and_kwargs_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@

def test_error_when_invalid_args_kwargs_combo_provided():
with pytest.raises(TypeError):
merge_args_and_kwargs(GENERATED_FUNCTION_ABI, (1, 2,), {'a': 1, 'b': 2})
merge_args_and_kwargs(
GENERATED_FUNCTION_ABI,
(
1,
2,
),
{"a": 1, "b": 2},
)


@pytest.mark.parametrize(
'args,kwargs,expected_args',
"args,kwargs,expected_args",
(
((1, 4, 2, 3), {}, (1, 4, 2, 3)),
((1, 4, 2), {'d': 3}, (1, 4, 2, 3)),
((1, 4), {'d': 3, 'c': 2}, (1, 4, 2, 3)),
((1,), {'d': 3, 'b': 4, 'c': 2}, (1, 4, 2, 3)),
(tuple(), {'d': 3, 'b': 4, 'a': 1, 'c': 2}, (1, 4, 2, 3)),
((1, 4, 2), {"d": 3}, (1, 4, 2, 3)),
((1, 4), {"d": 3, "c": 2}, (1, 4, 2, 3)),
((1,), {"d": 3, "b": 4, "c": 2}, (1, 4, 2, 3)),
(tuple(), {"d": 3, "b": 4, "a": 1, "c": 2}, (1, 4, 2, 3)),
),
)
def test_merging_of_args_and_kwargs(args, kwargs, expected_args):
Expand Down Expand Up @@ -66,7 +73,7 @@ def test_merging_of_args_and_kwargs_with_no_inputs():

def test_kwargs_is_disallowed_when_merging_with_unnamed_inputs():
with pytest.raises(TypeError):
merge_args_and_kwargs(GENERATED_FUNCTION_ABI, tuple(), {'x': 1, 'y': 2})
merge_args_and_kwargs(GENERATED_FUNCTION_ABI, tuple(), {"x": 1, "y": 2})


def test_args_works_when_merging_with_unnamed_inputs():
Expand Down Expand Up @@ -94,9 +101,9 @@ def test_args_allowed_when_duplicate_named_inputs():

def test_kwargs_not_allowed_for_duplicate_input_names():
with pytest.raises(TypeError):
merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1,), {'a': 2, 'b': 3})
merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1,), {"a": 2, "b": 3})


def test_kwargs_allowed_if_no_intersections_with_duplicate_input_names():
with pytest.raises(TypeError):
merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1,), {'a': 2, 'b': 3})
merge_args_and_kwargs(DUPLICATE_NAMES_FUNCTION_ABI, (1,), {"a": 2, "b": 3})
Loading