test+ci: add regression tests and GitHub Actions workflow

This commit is contained in:
jackwener
2026-03-05 16:14:05 +08:00
parent 4c08d09304
commit 6f322ff2d6
7 changed files with 225 additions and 0 deletions

31
tests/test_filter.py Normal file
View File

@@ -0,0 +1,31 @@
from __future__ import annotations
from twitter_cli.filter import filter_tweets
def test_filter_tweets_does_not_mutate_input(tweet_factory) -> None:
tweet = tweet_factory("1", score=0.0)
output = filter_tweets([tweet], {"mode": "all", "weights": {}})
assert tweet.score == 0.0
assert output[0].score > 0.0
assert output[0] is not tweet
def test_filter_tweets_applies_language_and_retweet_filters(tweet_factory) -> None:
tweets = [
tweet_factory("1", lang="en", is_retweet=False),
tweet_factory("2", lang="zh", is_retweet=False),
tweet_factory("3", lang="en", is_retweet=True),
]
output = filter_tweets(
tweets,
{
"mode": "all",
"lang": ["en"],
"excludeRetweets": True,
"weights": {},
},
)
assert [tweet.id for tweet in output] == ["1"]