Skip to content

Commit a806bc5

Browse files
committed
refactor(consume): split base functionality out to the base plugin
These are fixtures that can also be shared by multi-client architecture simulators.
1 parent a57e50b commit a806bc5

File tree

3 files changed

+1
-80
lines changed

3 files changed

+1
-80
lines changed

src/pytest_plugins/consume/simulators/engine/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from ethereum_test_rpc import EngineRPC
1616

1717
pytest_plugins = (
18-
"pytest_plugins.pytest_hive.pytest_hive",
1918
"pytest_plugins.consume.simulators.base",
2019
"pytest_plugins.consume.simulators.single_test_client",
2120
"pytest_plugins.consume.simulators.test_case_description",

src/pytest_plugins/consume/simulators/rlp/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
TestCase = TestCaseIndexFile | TestCaseStream
1313

1414
pytest_plugins = (
15-
"pytest_plugins.pytest_hive.pytest_hive",
1615
"pytest_plugins.consume.simulators.base",
1716
"pytest_plugins.consume.simulators.single_test_client",
1817
"pytest_plugins.consume.simulators.test_case_description",

src/pytest_plugins/consume/simulators/single_test_client.py

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33
import io
44
import json
55
import logging
6-
from pathlib import Path
7-
from typing import Dict, Generator, Literal, cast
6+
from typing import Generator, Literal, cast
87

98
import pytest
109
from hive.client import Client, ClientType
1110
from hive.testing import HiveTest
1211

1312
from ethereum_test_base_types import Number, to_json
1413
from ethereum_test_fixtures import (
15-
BaseFixture,
1614
BlockchainFixtureCommon,
1715
)
18-
from ethereum_test_fixtures.consume import TestCaseIndexFile, TestCaseStream
19-
from ethereum_test_fixtures.file import Fixtures
20-
from ethereum_test_rpc import EthRPC
21-
from pytest_plugins.consume.consume import FixturesSource
2216
from pytest_plugins.consume.simulators.helpers.ruleset import (
2317
ruleset, # TODO: generate dynamically
2418
)
@@ -28,12 +22,6 @@
2822
logger = logging.getLogger(__name__)
2923

3024

31-
@pytest.fixture(scope="function")
32-
def eth_rpc(client: Client) -> EthRPC:
33-
"""Initialize ethereum RPC client for the execution client under test."""
34-
return EthRPC(f"http://{client.ip}:8545")
35-
36-
3725
@pytest.fixture(scope="function")
3826
def client_genesis(fixture: BlockchainFixtureCommon) -> dict:
3927
"""Convert the fixture genesis block header and pre-state to a client genesis state."""
@@ -44,18 +32,6 @@ def client_genesis(fixture: BlockchainFixtureCommon) -> dict:
4432
return genesis
4533

4634

47-
@pytest.fixture(scope="function")
48-
def check_live_port(test_suite_name: str) -> Literal[8545, 8551]:
49-
"""Port used by hive to check for liveness of the client."""
50-
if test_suite_name == "eest/consume-rlp":
51-
return 8545
52-
elif test_suite_name == "eest/consume-engine":
53-
return 8551
54-
raise ValueError(
55-
f"Unexpected test suite name '{test_suite_name}' while setting HIVE_CHECK_LIVE_PORT."
56-
)
57-
58-
5935
@pytest.fixture(scope="function")
6036
def environment(
6137
fixture: BlockchainFixtureCommon,
@@ -105,56 +81,3 @@ def client(
10581
with total_timing_data.time("Stop client"):
10682
client.stop()
10783
logger.info(f"Client ({client_type.name}) stopped!")
108-
109-
110-
class FixturesDict(Dict[Path, Fixtures]):
111-
"""
112-
A dictionary caches loaded fixture files to avoid reloading the same file
113-
multiple times.
114-
"""
115-
116-
def __init__(self) -> None:
117-
"""Initialize the dictionary that caches loaded fixture files."""
118-
self._fixtures: Dict[Path, Fixtures] = {}
119-
120-
def __getitem__(self, key: Path) -> Fixtures:
121-
"""Return the fixtures from the index file, if not found, load from disk."""
122-
assert key.is_file(), f"Expected a file path, got '{key}'"
123-
if key not in self._fixtures:
124-
self._fixtures[key] = Fixtures.model_validate_json(key.read_text())
125-
return self._fixtures[key]
126-
127-
128-
@pytest.fixture(scope="session")
129-
def fixture_file_loader() -> Dict[Path, Fixtures]:
130-
"""Return a singleton dictionary that caches loaded fixture files used in all tests."""
131-
return FixturesDict()
132-
133-
134-
@pytest.fixture(scope="function")
135-
def fixture(
136-
fixtures_source: FixturesSource,
137-
fixture_file_loader: Dict[Path, Fixtures],
138-
test_case: TestCaseIndexFile | TestCaseStream,
139-
) -> BaseFixture:
140-
"""
141-
Load the fixture from a file or from stream in any of the supported
142-
fixture formats.
143-
144-
The fixture is either already available within the test case (if consume
145-
is taking input on stdin) or loaded from the fixture json file if taking
146-
input from disk (fixture directory with index file).
147-
"""
148-
fixture: BaseFixture
149-
if fixtures_source.is_stdin:
150-
assert isinstance(test_case, TestCaseStream), "Expected a stream test case"
151-
fixture = test_case.fixture
152-
else:
153-
assert isinstance(test_case, TestCaseIndexFile), "Expected an index file test case"
154-
fixtures_file_path = fixtures_source.path / test_case.json_path
155-
fixtures: Fixtures = fixture_file_loader[fixtures_file_path]
156-
fixture = fixtures[test_case.id]
157-
assert isinstance(fixture, test_case.format), (
158-
f"Expected a {test_case.format.format_name} test fixture"
159-
)
160-
return fixture

0 commit comments

Comments
 (0)