refactor: match upstream unittest convention

Convert all new tests from bare pytest style to unittest.TestCase
with sys.path.insert, matching the convention used by all existing
tests. Remove pyproject.toml and conftest.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
P
2026-03-09 16:43:04 -04:00
parent 0979f506db
commit 4756c20ec0
6 changed files with 175 additions and 152 deletions
+44 -33
View File
@@ -1,20 +1,27 @@
"""Tests for schema.py — data class serialization roundtrips."""
import sys
import unittest
from pathlib import Path
# Add lib to path
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
from lib import schema
class TestEngagement:
class TestEngagement(unittest.TestCase):
"""Tests for Engagement.to_dict()."""
def test_sparse_fields(self):
eng = schema.Engagement(score=100, num_comments=50)
d = eng.to_dict()
assert d == {"score": 100, "num_comments": 50}
assert "likes" not in d
self.assertEqual(d, {"score": 100, "num_comments": 50})
self.assertNotIn("likes", d)
def test_all_none_returns_none(self):
eng = schema.Engagement()
assert eng.to_dict() is None
self.assertIsNone(eng.to_dict())
def test_all_fields(self):
eng = schema.Engagement(
@@ -23,19 +30,19 @@ class TestEngagement:
views=7, shares=8, volume=9.0, liquidity=10.0,
)
d = eng.to_dict()
assert len(d) == 11
self.assertEqual(len(d), 11)
class TestComment:
class TestComment(unittest.TestCase):
def test_basic(self):
c = schema.Comment(score=50, date="2026-03-01", author="user", excerpt="text", url="http://x")
d = c.to_dict()
assert d["score"] == 50
assert d["author"] == "user"
assert len(d) == 5
self.assertEqual(d["score"], 50)
self.assertEqual(d["author"], "user")
self.assertEqual(len(d), 5)
class TestRedditItem:
class TestRedditItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.RedditItem(
id="R1", title="Test", url="http://reddit.com/r/test",
@@ -43,10 +50,10 @@ class TestRedditItem:
engagement=schema.Engagement(score=100),
)
d = item.to_dict()
assert d["id"] == "R1"
assert d["subreddit"] == "test"
assert d["engagement"] == {"score": 100}
assert "cross_refs" not in d
self.assertEqual(d["id"], "R1")
self.assertEqual(d["subreddit"], "test")
self.assertEqual(d["engagement"], {"score": 100})
self.assertNotIn("cross_refs", d)
def test_cross_refs_included_when_present(self):
item = schema.RedditItem(
@@ -54,78 +61,82 @@ class TestRedditItem:
cross_refs=["X1", "HN2"],
)
d = item.to_dict()
assert d["cross_refs"] == ["X1", "HN2"]
self.assertEqual(d["cross_refs"], ["X1", "HN2"])
class TestXItem:
class TestXItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.XItem(
id="X1", text="tweet", url="http://x.com/1",
author_handle="user", date="2026-03-01",
)
d = item.to_dict()
assert d["id"] == "X1"
assert d["author_handle"] == "user"
assert "cross_refs" not in d
self.assertEqual(d["id"], "X1")
self.assertEqual(d["author_handle"], "user")
self.assertNotIn("cross_refs", d)
class TestYouTubeItem:
class TestYouTubeItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.YouTubeItem(
id="YT1", title="Video", url="http://youtube.com/1",
channel_name="chan",
)
d = item.to_dict()
assert d["channel_name"] == "chan"
assert d["date_confidence"] == "high"
self.assertEqual(d["channel_name"], "chan")
self.assertEqual(d["date_confidence"], "high")
class TestTikTokItem:
class TestTikTokItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.TikTokItem(
id="TK1", text="caption", url="http://tiktok.com/1",
author_name="creator", hashtags=["ai", "code"],
)
d = item.to_dict()
assert d["hashtags"] == ["ai", "code"]
assert d["author_name"] == "creator"
self.assertEqual(d["hashtags"], ["ai", "code"])
self.assertEqual(d["author_name"], "creator")
class TestInstagramItem:
class TestInstagramItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.InstagramItem(
id="IG1", text="caption", url="http://instagram.com/reel/1",
author_name="creator",
)
d = item.to_dict()
assert d["id"] == "IG1"
self.assertEqual(d["id"], "IG1")
class TestWebSearchItem:
class TestWebSearchItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.WebSearchItem(
id="W1", title="Article", url="http://example.com",
source_domain="example.com", snippet="text",
)
d = item.to_dict()
assert d["source_domain"] == "example.com"
self.assertEqual(d["source_domain"], "example.com")
class TestHackerNewsItem:
class TestHackerNewsItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.HackerNewsItem(
id="HN1", title="Show HN", url="http://example.com",
hn_url="http://news.ycombinator.com/item?id=1", author="pg",
)
d = item.to_dict()
assert d["hn_url"].startswith("http://news.ycombinator.com")
self.assertTrue(d["hn_url"].startswith("http://news.ycombinator.com"))
class TestPolymarketItem:
class TestPolymarketItem(unittest.TestCase):
def test_roundtrip(self):
item = schema.PolymarketItem(
id="PM1", title="Election", question="Who wins?",
url="http://polymarket.com/1",
)
d = item.to_dict()
assert d["question"] == "Who wins?"
self.assertEqual(d["question"], "Who wins?")
if __name__ == "__main__":
unittest.main()