File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,15 @@ class SyncConfig:
2727 timeout_seconds : float = 30.0
2828 poll_interval_seconds : float = 1.0
2929
30+ def __post_init__ (self ) -> None :
31+ """Validate that both fields are positive."""
32+ if self .timeout_seconds <= 0 :
33+ msg = f"timeout_seconds must be positive, got { self .timeout_seconds } "
34+ raise ValueError (msg )
35+ if self .poll_interval_seconds <= 0 :
36+ msg = f"poll_interval_seconds must be positive, got { self .poll_interval_seconds } "
37+ raise ValueError (msg )
38+
3039
3140class SyncOperation (enum .Enum ):
3241 """Operation performed by a synchronous wrapper.
Original file line number Diff line number Diff line change @@ -134,6 +134,22 @@ def test_frozen(self) -> None:
134134 with pytest .raises (AttributeError ):
135135 sync_config .timeout_seconds = 99.0 # type: ignore[misc]
136136
137+ def test_zero_timeout_raises (self ) -> None :
138+ with pytest .raises (ValueError , match = "timeout_seconds must be positive" ):
139+ SyncConfig (timeout_seconds = 0.0 )
140+
141+ def test_negative_timeout_raises (self ) -> None :
142+ with pytest .raises (ValueError , match = "timeout_seconds must be positive" ):
143+ SyncConfig (timeout_seconds = - 1.0 )
144+
145+ def test_zero_poll_interval_raises (self ) -> None :
146+ with pytest .raises (ValueError , match = "poll_interval_seconds must be positive" ):
147+ SyncConfig (poll_interval_seconds = 0.0 )
148+
149+ def test_negative_poll_interval_raises (self ) -> None :
150+ with pytest .raises (ValueError , match = "poll_interval_seconds must be positive" ):
151+ SyncConfig (poll_interval_seconds = - 1.0 )
152+
137153
138154# ---------------------------------------------------------------------------
139155# SyncOperation enum
You can’t perform that action at this time.
0 commit comments