mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-11 18:58:59 +03:00
black the generated protocol messages code (#11786)
* black the generated protocol messages code * Update tests/util/build_network_protocol_files.py Co-authored-by: Arvid Norberg <arvid@libtorrent.org> * more focused noqa Co-authored-by: Arvid Norberg <arvid@libtorrent.org>
This commit is contained in:
parent
61fa0edc02
commit
a87e8e34ac
5
.flake8
5
.flake8
@ -2,3 +2,8 @@
|
||||
max-line-length = 120
|
||||
exclude = ./typings/**/*
|
||||
ignore = E203,W503
|
||||
per-file-ignores =
|
||||
tests/util/build_network_protocol_files.py:F405
|
||||
tests/util/test_network_protocol_files.py:F405
|
||||
tests/util/test_network_protocol_json.py:F405
|
||||
tests/util/protocol_messages_json.py:E501
|
||||
|
@ -49,7 +49,6 @@ repos:
|
||||
rev: 21.12b0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: "tests/util/(protocol_messages_json|test_network_protocol_json).py"
|
||||
additional_dependencies: ['click<8.1']
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.9.2
|
||||
|
@ -15,4 +15,4 @@ include = '''
|
||||
| (benchmarks|build_scripts|chia|tests|tools)/.*\.pyi?
|
||||
)$
|
||||
'''
|
||||
exclude = 'tests/util/(protocol_messages_json|test_network_protocol_json).py'
|
||||
exclude = ''
|
||||
|
@ -1,17 +1,18 @@
|
||||
# flake8: noqa
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sysconfig
|
||||
from typing import Callable, Any
|
||||
from pathlib import Path
|
||||
from chia.util.streamable import Streamable, streamable
|
||||
from tests.util.network_protocol_data import *
|
||||
from tests.util.network_protocol_data import * # noqa: F403
|
||||
from chia.util.ints import uint32
|
||||
|
||||
version = "1.0"
|
||||
|
||||
|
||||
tests_dir = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def get_network_protocol_filename() -> Path:
|
||||
tests_dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
return tests_dir / Path("protocol_messages_bytes-v" + version)
|
||||
|
||||
|
||||
@ -159,11 +160,10 @@ def build_protocol_test() -> str:
|
||||
|
||||
result = """# this file is generated by build_network_protocol_files.py
|
||||
|
||||
# flake8: noqa
|
||||
from typing import Tuple
|
||||
from pathlib import Path
|
||||
from tests.util.network_protocol_data import *
|
||||
from tests.util.protocol_messages_json import *
|
||||
from tests.util.network_protocol_data import * # noqa: F403
|
||||
from tests.util.protocol_messages_json import * # noqa: F403
|
||||
from tests.util.build_network_protocol_files import get_network_protocol_filename
|
||||
|
||||
|
||||
@ -203,7 +203,6 @@ def test_protocol_bytes() -> None:
|
||||
def get_protocol_json() -> str:
|
||||
|
||||
result = """# this file is generated by build_network_protocol_files.py
|
||||
# flake8: noqa
|
||||
from typing import Any, Dict
|
||||
"""
|
||||
counter = 0
|
||||
@ -223,9 +222,8 @@ def build_json_test() -> str:
|
||||
|
||||
result = """# this file is generated by build_network_protocol_files.py
|
||||
|
||||
# flake8: noqa
|
||||
from tests.util.network_protocol_data import *
|
||||
from tests.util.protocol_messages_json import *
|
||||
from tests.util.network_protocol_data import * # noqa: F403
|
||||
from tests.util.protocol_messages_json import * # noqa: F403
|
||||
|
||||
|
||||
def test_protocol_json() -> None:
|
||||
@ -245,15 +243,22 @@ def test_protocol_json() -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
tests_dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
with open(get_network_protocol_filename(), "wb") as f:
|
||||
f.write(get_protocol_bytes())
|
||||
get_network_protocol_filename().write_bytes(get_protocol_bytes())
|
||||
|
||||
with open(tests_dir / Path("test_network_protocol_files.py"), "w") as f2:
|
||||
f2.write(build_protocol_test())
|
||||
name_to_function = {
|
||||
"test_network_protocol_files.py": build_protocol_test,
|
||||
"protocol_messages_json.py": get_protocol_json,
|
||||
"test_network_protocol_json.py": build_json_test,
|
||||
}
|
||||
|
||||
with open(tests_dir / Path("protocol_messages_json.py"), "w") as f2:
|
||||
f2.write(get_protocol_json())
|
||||
scripts_path = Path(sysconfig.get_path("scripts"))
|
||||
|
||||
with open(tests_dir / Path("test_network_protocol_json.py"), "w") as f2:
|
||||
f2.write(build_json_test())
|
||||
for name, function in name_to_function.items():
|
||||
path = tests_dir.joinpath(name)
|
||||
path.write_text(function())
|
||||
# black seems to have trouble when run as a module so not using `python -m black`
|
||||
subprocess.run(
|
||||
[scripts_path.joinpath("black"), os.fspath(path.relative_to(tests_dir))],
|
||||
check=True,
|
||||
cwd=tests_dir,
|
||||
)
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,10 +1,9 @@
|
||||
# this file is generated by build_network_protocol_files.py
|
||||
|
||||
# flake8: noqa
|
||||
from typing import Tuple
|
||||
from pathlib import Path
|
||||
from tests.util.network_protocol_data import *
|
||||
from tests.util.protocol_messages_json import *
|
||||
from tests.util.network_protocol_data import * # noqa: F403
|
||||
from tests.util.protocol_messages_json import * # noqa: F403
|
||||
from tests.util.build_network_protocol_files import get_network_protocol_filename
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
# this file is generated by build_network_protocol_files.py
|
||||
|
||||
# flake8: noqa
|
||||
from tests.util.network_protocol_data import *
|
||||
from tests.util.protocol_messages_json import *
|
||||
from tests.util.network_protocol_data import * # noqa: F403
|
||||
from tests.util.protocol_messages_json import * # noqa: F403
|
||||
|
||||
|
||||
def test_protocol_json() -> None:
|
||||
@ -47,15 +46,26 @@ def test_protocol_json() -> None:
|
||||
assert str(respond_unfinished_block_json) == str(respond_unfinished_block.to_json_dict())
|
||||
assert type(respond_unfinished_block).from_json_dict(respond_unfinished_block_json) == respond_unfinished_block
|
||||
assert str(new_signage_point_or_end_of_subslot_json) == str(new_signage_point_or_end_of_subslot.to_json_dict())
|
||||
assert type(new_signage_point_or_end_of_subslot).from_json_dict(new_signage_point_or_end_of_subslot_json) == new_signage_point_or_end_of_subslot
|
||||
assert str(request_signage_point_or_end_of_subslot_json) == str(request_signage_point_or_end_of_subslot.to_json_dict())
|
||||
assert type(request_signage_point_or_end_of_subslot).from_json_dict(request_signage_point_or_end_of_subslot_json) == request_signage_point_or_end_of_subslot
|
||||
assert (
|
||||
type(new_signage_point_or_end_of_subslot).from_json_dict(new_signage_point_or_end_of_subslot_json)
|
||||
== new_signage_point_or_end_of_subslot
|
||||
)
|
||||
assert str(request_signage_point_or_end_of_subslot_json) == str(
|
||||
request_signage_point_or_end_of_subslot.to_json_dict()
|
||||
)
|
||||
assert (
|
||||
type(request_signage_point_or_end_of_subslot).from_json_dict(request_signage_point_or_end_of_subslot_json)
|
||||
== request_signage_point_or_end_of_subslot
|
||||
)
|
||||
assert str(respond_signage_point_json) == str(respond_signage_point.to_json_dict())
|
||||
assert type(respond_signage_point).from_json_dict(respond_signage_point_json) == respond_signage_point
|
||||
assert str(respond_end_of_subslot_json) == str(respond_end_of_subslot.to_json_dict())
|
||||
assert type(respond_end_of_subslot).from_json_dict(respond_end_of_subslot_json) == respond_end_of_subslot
|
||||
assert str(request_mempool_transaction_json) == str(request_mempool_transaction.to_json_dict())
|
||||
assert type(request_mempool_transaction).from_json_dict(request_mempool_transaction_json) == request_mempool_transaction
|
||||
assert (
|
||||
type(request_mempool_transaction).from_json_dict(request_mempool_transaction_json)
|
||||
== request_mempool_transaction
|
||||
)
|
||||
assert str(new_compact_vdf_json) == str(new_compact_vdf.to_json_dict())
|
||||
assert type(new_compact_vdf).from_json_dict(new_compact_vdf_json) == new_compact_vdf
|
||||
assert str(request_compact_vdf_json) == str(request_compact_vdf.to_json_dict())
|
||||
@ -129,7 +139,10 @@ def test_protocol_json() -> None:
|
||||
assert str(harvester_handhsake_json) == str(harvester_handhsake.to_json_dict())
|
||||
assert type(harvester_handhsake).from_json_dict(harvester_handhsake_json) == harvester_handhsake
|
||||
assert str(new_signage_point_harvester_json) == str(new_signage_point_harvester.to_json_dict())
|
||||
assert type(new_signage_point_harvester).from_json_dict(new_signage_point_harvester_json) == new_signage_point_harvester
|
||||
assert (
|
||||
type(new_signage_point_harvester).from_json_dict(new_signage_point_harvester_json)
|
||||
== new_signage_point_harvester
|
||||
)
|
||||
assert str(new_proof_of_space_json) == str(new_proof_of_space.to_json_dict())
|
||||
assert type(new_proof_of_space).from_json_dict(new_proof_of_space_json) == new_proof_of_space
|
||||
assert str(request_signatures_json) == str(request_signatures.to_json_dict())
|
||||
@ -175,14 +188,25 @@ def test_protocol_json() -> None:
|
||||
assert str(new_peak_timelord_json) == str(new_peak_timelord.to_json_dict())
|
||||
assert type(new_peak_timelord).from_json_dict(new_peak_timelord_json) == new_peak_timelord
|
||||
assert str(new_unfinished_block_timelord_json) == str(new_unfinished_block_timelord.to_json_dict())
|
||||
assert type(new_unfinished_block_timelord).from_json_dict(new_unfinished_block_timelord_json) == new_unfinished_block_timelord
|
||||
assert (
|
||||
type(new_unfinished_block_timelord).from_json_dict(new_unfinished_block_timelord_json)
|
||||
== new_unfinished_block_timelord
|
||||
)
|
||||
assert str(new_infusion_point_vdf_json) == str(new_infusion_point_vdf.to_json_dict())
|
||||
assert type(new_infusion_point_vdf).from_json_dict(new_infusion_point_vdf_json) == new_infusion_point_vdf
|
||||
assert str(new_signage_point_vdf_json) == str(new_signage_point_vdf.to_json_dict())
|
||||
assert type(new_signage_point_vdf).from_json_dict(new_signage_point_vdf_json) == new_signage_point_vdf
|
||||
assert str(new_end_of_sub_slot_bundle_json) == str(new_end_of_sub_slot_bundle.to_json_dict())
|
||||
assert type(new_end_of_sub_slot_bundle).from_json_dict(new_end_of_sub_slot_bundle_json) == new_end_of_sub_slot_bundle
|
||||
assert (
|
||||
type(new_end_of_sub_slot_bundle).from_json_dict(new_end_of_sub_slot_bundle_json) == new_end_of_sub_slot_bundle
|
||||
)
|
||||
assert str(request_compact_proof_of_time_json) == str(request_compact_proof_of_time.to_json_dict())
|
||||
assert type(request_compact_proof_of_time).from_json_dict(request_compact_proof_of_time_json) == request_compact_proof_of_time
|
||||
assert (
|
||||
type(request_compact_proof_of_time).from_json_dict(request_compact_proof_of_time_json)
|
||||
== request_compact_proof_of_time
|
||||
)
|
||||
assert str(respond_compact_proof_of_time_json) == str(respond_compact_proof_of_time.to_json_dict())
|
||||
assert type(respond_compact_proof_of_time).from_json_dict(respond_compact_proof_of_time_json) == respond_compact_proof_of_time
|
||||
assert (
|
||||
type(respond_compact_proof_of_time).from_json_dict(respond_compact_proof_of_time_json)
|
||||
== respond_compact_proof_of_time
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user