Skip to content

Commit

Permalink
fix(fw): pydantic fixture format
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Sep 24, 2024
1 parent f9eb3e1 commit e1fb88a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/gen_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def generate_fixtures_index(
json_path=relative_file_path,
fixture_hash=fixture.info.get("hash", None),
fork=fixture.get_fork(),
format=fixture.fixture_format_name,
format=fixture.__class__,
)
)

Expand Down
11 changes: 8 additions & 3 deletions src/ethereum_test_fixtures/consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import datetime
import json
from pathlib import Path
from typing import List, TextIO
from typing import Annotated, List, TextIO

from pydantic import BaseModel, RootModel
from pydantic import BaseModel, PlainSerializer, PlainValidator, RootModel

from ethereum_test_base_types import HexNumber
from ethereum_test_fixtures import FIXTURE_FORMATS, FixtureFormat

from .blockchain import EngineFixture as BlockchainEngineFixture
from .blockchain import Fixture as BlockchainFixture
Expand All @@ -25,7 +26,11 @@ class TestCaseBase(BaseModel):
id: str
fixture_hash: HexNumber | None
fork: str | None
format: str
format: Annotated[
FixtureFormat,
PlainSerializer(lambda f: f.fixture_format_name),
PlainValidator(lambda f: FIXTURE_FORMATS[f] if f in FIXTURE_FORMATS else f),
]
__test__ = False # stop pytest from collecting this class as a test


Expand Down
6 changes: 3 additions & 3 deletions src/pytest_plugins/consume/direct/test_via_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest

from ethereum_test_fixtures import FIXTURE_FORMATS, BlockchainFixture, StateFixture
from ethereum_test_fixtures import BlockchainFixture, StateFixture
from ethereum_test_fixtures.consume import TestCaseIndexFile, TestCaseStream
from evm_transition_tool import TransitionTool

Expand All @@ -30,7 +30,7 @@ def test_blocktest( # noqa: D103
if evm_run_single_test:
fixture_name = re.escape(test_case.id)
evm.verify_fixture(
FIXTURE_FORMATS[test_case.format],
test_case.format,
fixture_path,
fixture_name=fixture_name,
debug_output_path=test_dump_dir,
Expand All @@ -51,7 +51,7 @@ def run_statetest(
# TODO: Can we group the tests appropriately so that this works more efficiently with xdist?
if fixture_path not in statetest_results:
json_result = evm.verify_fixture(
FIXTURE_FORMATS[test_case.format],
test_case.format,
fixture_path,
fixture_name=None,
debug_output_path=test_dump_dir,
Expand Down

0 comments on commit e1fb88a

Please sign in to comment.