Skip to content

Commit b50f12c

Browse files
committed
test: precise exception types + scheduler dirty config coverage
- Replace pytest.raises(Exception) with pytest.raises(ValueError) in test_settings and test_backend for Pydantic validation tests - Add scheduler interval validation tests: zero/negative clamping and non-numeric graceful failure
1 parent 6456b95 commit b50f12c

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

tests/test_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ def test_defaults(self):
252252
assert jr.conflict_points == []
253253

254254
def test_trust_bounds(self):
255-
with pytest.raises(Exception):
255+
with pytest.raises(ValueError):
256256
JudgeResult(trust=11)
257-
with pytest.raises(Exception):
257+
with pytest.raises(ValueError):
258258
JudgeResult(trust=-1)
259259

260260
def test_freshness_validation(self):
261261
jr = JudgeResult(freshness="current")
262262
assert jr.freshness == "current"
263-
with pytest.raises(Exception):
263+
with pytest.raises(ValueError):
264264
JudgeResult(freshness="invalid")
265265

266266
def test_to_pipeline_dict(self):

tests/test_scheduler.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,38 @@ def test_status_when_running(self, monkeypatch):
314314
assert len(status["jobs"]) == 1
315315
assert status["jobs"][0]["id"] == "freshness_scan"
316316
assert "2026-01-01" in status["jobs"][0]["next_run"]
317+
318+
319+
class TestSchedulerIntervalValidation:
320+
"""Verify scheduler interval clamping for edge-case values."""
321+
322+
def test_zero_interval_clamped_to_one(self, monkeypatch):
323+
"""CURATOR_FRESHNESS_INTERVAL_HOURS=0 should be clamped to 1h, not crash."""
324+
monkeypatch.setattr(sched, "_scheduler", None)
325+
monkeypatch.setenv("CURATOR_SCHEDULER_ENABLED", "1")
326+
monkeypatch.setenv("CURATOR_FRESHNESS_INTERVAL_HOURS", "0")
327+
monkeypatch.setenv("CURATOR_STRENGTHEN_INTERVAL_HOURS", "-5")
328+
329+
mock_sched = MagicMock()
330+
with patch("apscheduler.schedulers.background.BackgroundScheduler", return_value=mock_sched):
331+
result = sched.start_scheduler()
332+
333+
assert result is True
334+
# Both add_job calls should use clamped hours (>= 1.0)
335+
for call in mock_sched.add_job.call_args_list:
336+
assert call.kwargs.get("hours", call[1].get("hours", 1)) >= 1.0
337+
sched.stop_scheduler()
338+
339+
def test_non_numeric_interval_raises(self, monkeypatch):
340+
"""Non-numeric interval should cause start_scheduler to return False (caught)."""
341+
monkeypatch.setattr(sched, "_scheduler", None)
342+
monkeypatch.setenv("CURATOR_SCHEDULER_ENABLED", "1")
343+
monkeypatch.setenv("CURATOR_FRESHNESS_INTERVAL_HOURS", "not-a-number")
344+
345+
mock_sched = MagicMock()
346+
with patch("apscheduler.schedulers.background.BackgroundScheduler", return_value=mock_sched):
347+
result = sched.start_scheduler()
348+
349+
# Should fail gracefully (ValueError caught in the try block)
350+
assert result is False
351+
sched.stop_scheduler()

tests/test_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ class TestCuratorSettingsValidation:
6767
def test_threshold_rejects_out_of_range(self):
6868
from curator.settings import CuratorSettings
6969

70-
with pytest.raises(Exception):
70+
with pytest.raises(ValueError):
7171
CuratorSettings(threshold_cov_sufficient=1.5)
7272

7373
def test_threshold_rejects_negative(self):
7474
from curator.settings import CuratorSettings
7575

76-
with pytest.raises(Exception):
76+
with pytest.raises(ValueError):
7777
CuratorSettings(feedback_weight=-0.1)
7878

7979
def test_cb_threshold_rejects_zero(self):
8080
from curator.settings import CuratorSettings
8181

82-
with pytest.raises(Exception):
82+
with pytest.raises(ValueError):
8383
CuratorSettings(cb_threshold=0)
8484

8585
def test_provider_timeout_clamped(self):

0 commit comments

Comments
 (0)