1
1
"""Helper functions/classes used to generate Ethereum tests."""
2
2
3
- from dataclasses import MISSING , dataclass , fields
4
3
from typing import List , SupportsBytes
5
4
6
5
import ethereum_rlp as eth_rlp
6
+ from pydantic import BaseModel , ConfigDict
7
7
8
8
from ethereum_test_base_types .base_types import Address , Bytes , Hash
9
9
from ethereum_test_base_types .conversions import BytesConvertible , FixedSizeBytesConvertible
@@ -92,8 +92,7 @@ def add_kzg_version(
92
92
return kzg_versioned_hashes
93
93
94
94
95
- @dataclass (kw_only = True , frozen = True , repr = False )
96
- class TestParameterGroup :
95
+ class TestParameterGroup (BaseModel ):
97
96
"""
98
97
Base class for grouping test parameters in a dataclass. Provides a generic
99
98
__repr__ method to generate clean test ids, including only non-default
@@ -102,18 +101,18 @@ class TestParameterGroup:
102
101
103
102
__test__ = False # explicitly prevent pytest collecting this class
104
103
104
+ model_config = ConfigDict (frozen = True , repr = False , validate_default = True )
105
+
105
106
def __repr__ (self ):
106
107
"""
107
108
Generate repr string, intended to be used as a test id, based on the class
108
109
name and the values of the non-default optional fields.
109
110
"""
110
111
class_name = self .__class__ .__name__
111
- field_strings = []
112
-
113
- for field in fields (self ):
114
- value = getattr (self , field .name )
112
+ field_strings = [
113
+ f"{ field } _{ value } "
115
114
# Include the field only if it is not optional or not set to its default value
116
- if field . default is MISSING or field . default != value :
117
- field_strings . append ( f" { field . name } _ { value } " )
115
+ for field , value in self . model_dump ( exclude_defaults = True , exclude_unset = True ). items ()
116
+ ]
118
117
119
118
return f"{ class_name } _{ '-' .join (field_strings )} "
0 commit comments