Skip to content

Commit f362a2a

Browse files
Use black for linting tests directory (#4245)
* Remove flake8 & run black on tests * Run make lint --------- Co-authored-by: Justin Traglia <[email protected]>
1 parent 807ea65 commit f362a2a

File tree

236 files changed

+13797
-5647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+13797
-5647
lines changed

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,11 @@ serve_docs: _copy_docs
173173
# Checks
174174
###############################################################################
175175

176-
FLAKE8_CONFIG = $(CURDIR)/flake8.ini
177176
MYPY_CONFIG = $(CURDIR)/mypy.ini
178177
PYLINT_CONFIG = $(CURDIR)/pylint.ini
179178

180179
PYLINT_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), $(PYSPEC_DIR)/eth2spec/$S)
181180
MYPY_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), -p eth2spec.$S)
182-
TEST_GENERATORS_DIR = ./tests/generators
183181
MARKDOWN_FILES = $(wildcard $(SPEC_DIR)/*/*.md) \
184182
$(wildcard $(SPEC_DIR)/*/*/*.md) \
185183
$(wildcard $(SPEC_DIR)/_features/*/*.md) \
@@ -190,8 +188,7 @@ MARKDOWN_FILES = $(wildcard $(SPEC_DIR)/*/*.md) \
190188
lint: pyspec
191189
@$(MDFORMAT_VENV) --number $(MARKDOWN_FILES)
192190
@$(CODESPELL_VENV) . --skip "./.git,$(VENV),$(PYSPEC_DIR)/.mypy_cache" -I .codespell-whitelist
193-
@$(PYTHON_VENV) -m flake8 --config $(FLAKE8_CONFIG) $(PYSPEC_DIR)/eth2spec
194-
@$(PYTHON_VENV) -m flake8 --config $(FLAKE8_CONFIG) $(TEST_GENERATORS_DIR)
191+
@$(PYTHON_VENV) -m black $(CURDIR)/tests
195192
@$(PYTHON_VENV) -m pylint --rcfile $(PYLINT_CONFIG) $(PYLINT_SCOPE)
196193
@$(PYTHON_VENV) -m mypy --config-file $(MYPY_CONFIG) $(MYPY_SCOPE)
197194

flake8.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ test = [
3636
"pytest==8.3.5",
3737
]
3838
lint = [
39+
"black==25.1.0",
3940
"codespell==2.4.1",
40-
"flake8==7.2.0",
4141
"mdformat-gfm-alerts==1.0.1",
4242
"mdformat-gfm==0.4.1",
4343
"mdformat-toc==0.3.0",
@@ -57,3 +57,6 @@ docs = [
5757
"mkdocs-material==9.6.10",
5858
"mkdocs==1.6.1",
5959
]
60+
61+
[tool.black]
62+
line-length = 100

specs/_deprecated/sharding/validator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def verify_sample(state: BeaconState, block: BeaconBlock, sample: SignedShardSam
8989

9090
# Verify KZG proof
9191
verify_kzg_multiproof(block.body.payload_data.value.sharded_commitments_container.sharded_commitments[sample.row],
92-
roots_in_rbo[sample.column * FIELD_ELEMENTS_PER_SAMPLE:(sample.column + 1) * FIELD_ELEMENTS_PER_SAMPLE]
92+
roots_in_rbo[sample.column * FIELD_ELEMENTS_PER_SAMPLE:(sample.column + 1) * FIELD_ELEMENTS_PER_SAMPLE],
9393
sample.data,
9494
sample.proof)
9595
```
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# See setup.py about usage of VERSION.txt
22
import os
3-
with open(os.path.join(os.path.dirname(__file__), 'VERSION.txt')) as f:
3+
4+
with open(os.path.join(os.path.dirname(__file__), "VERSION.txt")) as f:
45
__version__ = f.read().strip()

tests/core/pyspec/eth2spec/config/config_util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def parse_config_vars(conf: Dict[str, Any]) -> Dict[str, Any]:
1414
out[k] = [int(item) if item.isdigit() else item for item in v]
1515
elif isinstance(v, str) and v.startswith("0x"):
1616
out[k] = bytes.fromhex(v[2:])
17-
elif k != 'PRESET_BASE' and k != 'CONFIG_NAME':
17+
elif k != "PRESET_BASE" and k != "CONFIG_NAME":
1818
out[k] = int(v)
1919
else:
2020
out[k] = v
@@ -27,7 +27,7 @@ def load_preset(preset_files: Iterable[Union[Path, BinaryIO, TextIO]]) -> Dict[s
2727
"""
2828
preset = {}
2929
for fork_file in preset_files:
30-
yaml = YAML(typ='base')
30+
yaml = YAML(typ="base")
3131
fork_preset: dict = yaml.load(fork_file)
3232
if fork_preset is None: # for empty YAML files
3333
continue
@@ -43,7 +43,7 @@ def load_config_file(config_path: Union[Path, BinaryIO, TextIO]) -> Dict[str, An
4343
"""
4444
Loads the given configuration file.
4545
"""
46-
yaml = YAML(typ='base')
46+
yaml = YAML(typ="base")
4747
config_data = yaml.load(config_path)
4848
return parse_config_vars(config_data)
4949

@@ -56,8 +56,8 @@ def load_config_file(config_path: Union[Path, BinaryIO, TextIO]) -> Dict[str, An
5656
def load_defaults(spec_configs_path: Path) -> None:
5757
global mainnet_config_data, minimal_config_data
5858

59-
mainnet_config_data = load_config_file(spec_configs_path / 'mainnet.yaml')
60-
minimal_config_data = load_config_file(spec_configs_path / 'minimal.yaml')
59+
mainnet_config_data = load_config_file(spec_configs_path / "mainnet.yaml")
60+
minimal_config_data = load_config_file(spec_configs_path / "minimal.yaml")
6161

6262
global loaded_defaults
6363
loaded_defaults = True

tests/core/pyspec/eth2spec/debug/decode.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
from typing import Any
22
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
33
from eth2spec.utils.ssz.ssz_typing import (
4-
uint, Container, List, boolean,
5-
Vector, ByteVector, ByteList, Union, View
4+
uint,
5+
Container,
6+
List,
7+
boolean,
8+
Vector,
9+
ByteVector,
10+
ByteList,
11+
Union,
12+
View,
613
)
714

815

@@ -20,12 +27,13 @@ def decode(data: Any, typ):
2027
for field_name, field_type in typ.fields().items():
2128
temp[field_name] = decode(data[field_name], field_type)
2229
if field_name + "_hash_tree_root" in data:
23-
assert (data[field_name + "_hash_tree_root"][2:] ==
24-
hash_tree_root(temp[field_name]).hex())
30+
assert (
31+
data[field_name + "_hash_tree_root"][2:]
32+
== hash_tree_root(temp[field_name]).hex()
33+
)
2534
ret = typ(**temp)
2635
if "hash_tree_root" in data:
27-
assert (data["hash_tree_root"][2:] ==
28-
hash_tree_root(ret).hex())
36+
assert data["hash_tree_root"][2:] == hash_tree_root(ret).hex()
2937
return ret
3038
elif issubclass(typ, Union):
3139
selector = int(data["selector"])
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from eth2spec.utils.ssz.ssz_impl import hash_tree_root, serialize
22
from eth2spec.utils.ssz.ssz_typing import (
3-
uint, boolean,
4-
Bitlist, Bitvector, Container, Vector, List, Union
3+
uint,
4+
boolean,
5+
Bitlist,
6+
Bitvector,
7+
Container,
8+
Vector,
9+
List,
10+
Union,
511
)
612

713

@@ -14,28 +20,28 @@ def encode(value, include_hash_tree_roots=False):
1420
elif isinstance(value, boolean):
1521
return value == 1
1622
elif isinstance(value, (Bitlist, Bitvector)):
17-
return '0x' + serialize(value).hex()
23+
return "0x" + serialize(value).hex()
1824
elif isinstance(value, list): # normal python lists
1925
return [encode(element, include_hash_tree_roots) for element in value]
2026
elif isinstance(value, (List, Vector)):
2127
return [encode(element, include_hash_tree_roots) for element in value]
2228
elif isinstance(value, bytes): # bytes, ByteList, ByteVector
23-
return '0x' + value.hex()
29+
return "0x" + value.hex()
2430
elif isinstance(value, Container):
2531
ret = {}
2632
for field_name in value.fields().keys():
2733
field_value = getattr(value, field_name)
2834
ret[field_name] = encode(field_value, include_hash_tree_roots)
2935
if include_hash_tree_roots:
30-
ret[field_name + "_hash_tree_root"] = '0x' + hash_tree_root(field_value).hex()
36+
ret[field_name + "_hash_tree_root"] = "0x" + hash_tree_root(field_value).hex()
3137
if include_hash_tree_roots:
32-
ret["hash_tree_root"] = '0x' + hash_tree_root(value).hex()
38+
ret["hash_tree_root"] = "0x" + hash_tree_root(value).hex()
3339
return ret
3440
elif isinstance(value, Union):
3541
inner_value = value.value()
3642
return {
37-
'selector': int(value.selector()),
38-
'value': None if inner_value is None else encode(inner_value, include_hash_tree_roots)
43+
"selector": int(value.selector()),
44+
"value": None if inner_value is None else encode(inner_value, include_hash_tree_roots),
3945
}
4046
else:
4147
raise Exception(f"Type not recognized: value={value}, typ={type(value)}")

tests/core/pyspec/eth2spec/debug/random_value.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
from typing import Type
55

66
from eth2spec.utils.ssz.ssz_typing import (
7-
View, BasicView, uint, Container, List, boolean,
8-
Vector, ByteVector, ByteList, Bitlist, Bitvector, Union
7+
View,
8+
BasicView,
9+
uint,
10+
Container,
11+
List,
12+
boolean,
13+
Vector,
14+
ByteVector,
15+
ByteList,
16+
Bitlist,
17+
Bitvector,
18+
Union,
919
)
1020

1121
# in bytes
@@ -35,12 +45,14 @@ def is_changing(self):
3545
return self.value in [0, 4, 5]
3646

3747

38-
def get_random_ssz_object(rng: Random,
39-
typ: Type[View],
40-
max_bytes_length: int,
41-
max_list_length: int,
42-
mode: RandomizationMode,
43-
chaos: bool) -> View:
48+
def get_random_ssz_object(
49+
rng: Random,
50+
typ: Type[View],
51+
max_bytes_length: int,
52+
max_list_length: int,
53+
mode: RandomizationMode,
54+
chaos: bool,
55+
) -> View:
4456
"""
4557
Create an object for a given type, filled with random data.
4658
:param rng: The random number generator to use.
@@ -56,24 +68,26 @@ def get_random_ssz_object(rng: Random,
5668
if issubclass(typ, ByteList):
5769
# ByteList array
5870
if mode == RandomizationMode.mode_nil_count:
59-
return typ(b'')
71+
return typ(b"")
6072
elif mode == RandomizationMode.mode_max_count:
6173
return typ(get_random_bytes_list(rng, min(max_bytes_length, typ.limit())))
6274
elif mode == RandomizationMode.mode_one_count:
6375
return typ(get_random_bytes_list(rng, min(1, typ.limit())))
6476
elif mode == RandomizationMode.mode_zero:
65-
return typ(b'\x00' * min(1, typ.limit()))
77+
return typ(b"\x00" * min(1, typ.limit()))
6678
elif mode == RandomizationMode.mode_max:
67-
return typ(b'\xff' * min(1, typ.limit()))
79+
return typ(b"\xff" * min(1, typ.limit()))
6880
else:
69-
return typ(get_random_bytes_list(rng, rng.randint(0, min(max_bytes_length, typ.limit()))))
81+
return typ(
82+
get_random_bytes_list(rng, rng.randint(0, min(max_bytes_length, typ.limit())))
83+
)
7084
if issubclass(typ, ByteVector):
7185
# Random byte vectors can be bigger than max bytes size, e.g. custody chunk data.
7286
# No max-bytes-length limitation here.
7387
if mode == RandomizationMode.mode_zero:
74-
return typ(b'\x00' * typ.type_byte_length())
88+
return typ(b"\x00" * typ.type_byte_length())
7589
elif mode == RandomizationMode.mode_max:
76-
return typ(b'\xff' * typ.type_byte_length())
90+
return typ(b"\xff" * typ.type_byte_length())
7791
else:
7892
return typ(get_random_bytes_list(rng, typ.type_byte_length()))
7993
elif issubclass(typ, (boolean, uint)):
@@ -99,7 +113,9 @@ def get_random_ssz_object(rng: Random,
99113
elif mode == RandomizationMode.mode_nil_count:
100114
length = 0
101115

102-
if typ.limit() < length: # SSZ imposes a hard limit on lists, we can't put in more than that
116+
if (
117+
typ.limit() < length
118+
): # SSZ imposes a hard limit on lists, we can't put in more than that
103119
length = typ.limit()
104120

105121
elem_type = typ.element_cls() if issubclass(typ, List) else boolean
@@ -110,11 +126,14 @@ def get_random_ssz_object(rng: Random,
110126
elif issubclass(typ, Container):
111127
fields = typ.fields()
112128
# Container
113-
return typ(**{
114-
field_name:
115-
get_random_ssz_object(rng, field_type, max_bytes_length, max_list_length, mode, chaos)
116-
for field_name, field_type in fields.items()
117-
})
129+
return typ(
130+
**{
131+
field_name: get_random_ssz_object(
132+
rng, field_type, max_bytes_length, max_list_length, mode, chaos
133+
)
134+
for field_name, field_type in fields.items()
135+
}
136+
)
118137
elif issubclass(typ, Union):
119138
options = typ.options()
120139
selector: int
@@ -129,7 +148,9 @@ def get_random_ssz_object(rng: Random,
129148
if elem_type is None:
130149
elem = None
131150
else:
132-
elem = get_random_ssz_object(rng, elem_type, max_bytes_length, max_list_length, mode, chaos)
151+
elem = get_random_ssz_object(
152+
rng, elem_type, max_bytes_length, max_list_length, mode, chaos
153+
)
133154
return typ(selector=selector, value=elem)
134155
else:
135156
raise Exception(f"Type not recognized: typ={typ}")

0 commit comments

Comments
 (0)