Skip to content

Commit b13ece6

Browse files
wphillipmoorewphillipmoore-claude
andauthored
feat(sync): add SyncConfig construction validation (#425)
Co-authored-by: wphillipmoore-claude <255925739+wphillipmoore-claude@users.noreply.github.com>
1 parent 855d259 commit b13ece6

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/pymqrest/sync.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

3140
class SyncOperation(enum.Enum):
3241
"""Operation performed by a synchronous wrapper.

tests/pymqrest/test_sync.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)