test: add smoke tests and edge case coverage

Add end-to-end smoke tests and expand coverage for score and render modules:

- test_smoke.py (new): subprocess tests for --diagnose, --help, --mock,
  and missing topic. Validates exit codes, JSON structure, and source
  detection (HN/Polymarket always available).
- test_score.py: add TestCommentQualityWeight (top_comment_score boost),
  TestInstagramEngagement (basic scoring, views vs likes weighting)
- test_render.py: add TestEnsureOutputDir, TestXrefTag, TestRenderEmptyReport

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
P
2026-03-09 16:41:58 -04:00
parent 627947fc2c
commit 8a9f734d14
3 changed files with 175 additions and 0 deletions
+28
View File
@@ -164,5 +164,33 @@ class TestSortItems(unittest.TestCase):
self.assertEqual(len(result), 2)
class TestCommentQualityWeight(unittest.TestCase):
"""Test that top comment score boosts Reddit engagement."""
def test_comment_boosts_score(self):
eng = schema.Engagement(score=100, num_comments=50, upvote_ratio=0.9)
without_comment = score.compute_reddit_engagement_raw(eng, top_comment_score=None)
with_comment = score.compute_reddit_engagement_raw(eng, top_comment_score=500)
self.assertGreater(with_comment, without_comment)
class TestInstagramEngagement(unittest.TestCase):
"""Tests for compute_instagram_engagement_raw()."""
def test_basic(self):
eng = schema.Engagement(views=10000, likes=500, num_comments=50)
raw = score.compute_instagram_engagement_raw(eng)
self.assertIsNotNone(raw)
self.assertGreater(raw, 0)
def test_views_dominate(self):
views_only = schema.Engagement(views=10000)
likes_only = schema.Engagement(likes=10000)
self.assertGreater(
score.compute_instagram_engagement_raw(views_only),
score.compute_instagram_engagement_raw(likes_only),
)
if __name__ == "__main__":
unittest.main()