test+ci: add regression tests and GitHub Actions workflow
This commit is contained in:
22
tests/test_serialization.py
Normal file
22
tests/test_serialization.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from twitter_cli.serialization import tweet_from_dict, tweet_to_dict, tweets_from_json, tweets_to_json
|
||||
|
||||
|
||||
def test_tweet_roundtrip_dict(tweet_factory) -> None:
|
||||
tweet = tweet_factory("42")
|
||||
payload = tweet_to_dict(tweet)
|
||||
restored = tweet_from_dict(payload)
|
||||
|
||||
assert restored.id == tweet.id
|
||||
assert restored.author.screen_name == tweet.author.screen_name
|
||||
assert restored.metrics.likes == tweet.metrics.likes
|
||||
|
||||
|
||||
def test_tweets_json_roundtrip(tweet_factory) -> None:
|
||||
tweets = [tweet_factory("1"), tweet_factory("2", lang="zh")]
|
||||
raw = tweets_to_json(tweets)
|
||||
restored = tweets_from_json(raw)
|
||||
|
||||
assert [tweet.id for tweet in restored] == ["1", "2"]
|
||||
assert restored[1].lang == "zh"
|
||||
Reference in New Issue
Block a user