import goodnews.feeds as feeds RSS = b""" Volunteers restore creek and rescue stranded wildlife A hopeful recovery effort http://example.com/1 Sat, 30 May 2026 10:00:00 GMT Quarterly tax filing deadline reminder routine notice http://example.com/2 Sat, 30 May 2026 09:00:00 GMT """ def test_preview_feed_scores_sample_without_network(monkeypatch): monkeypatch.setattr(feeds, "fetch_feed", lambda url, **kw: RSS) p = feeds.preview_feed("http://example.com/feed") assert p["sampled"] == 2 assert p["classified"] is False assert 0.0 <= p["acceptance_rate"] <= 1.0 assert p["accepted"] >= 1 # the restore/rescue story should pass the heuristic assert p["newest_published"] is not None assert isinstance(p["topic_mix"], dict) and p["topic_mix"] == {} # empty without a model assert all("reason" in ex and "title" in ex for ex in p["examples_rejected"]) def test_preview_feed_respects_sample_cap(monkeypatch): monkeypatch.setattr(feeds, "fetch_feed", lambda url, **kw: RSS) p = feeds.preview_feed("http://example.com/feed", sample=1) assert p["sampled"] == 1