test_parser.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import pytest
  2. from twhatter.parser import TweetList, Tweet
  3. class TestTweetList:
  4. def test_len(self, raw_html_user_initial_page):
  5. t_list = TweetList(raw_html_user_initial_page)
  6. assert len(t_list) == 20
  7. def test_iter(self, raw_html_user_initial_page):
  8. t_list = TweetList(raw_html_user_initial_page)
  9. for t in t_list:
  10. assert isinstance(t, Tweet)
  11. class TestTweet:
  12. @pytest.mark.parametrize("tweet_type", [
  13. "plain",
  14. "reaction_tweet",
  15. "with_link",
  16. "retweet",
  17. "stats",
  18. ])
  19. def test_plain_tweet(self, raw_tweet_factory, tweet_collection, tweet_type):
  20. tweet_info = tweet_collection[tweet_type]
  21. raw = raw_tweet_factory(tweet_info)
  22. t = Tweet.extract(raw)
  23. assert t
  24. for field, value in tweet_info._asdict().items():
  25. # It would be rather complicated to keep some test fixtures values
  26. # accurate (e.g. number of likes, retweets, ...) so for most
  27. # of them, the expected values are not set on purpose and therefore
  28. # not tested
  29. if value is not None:
  30. assert getattr(t, field) == value