| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import pytest
- from twhatter.parser import *
- class TestTweetList:
- def test_len(self, raw_html_user_initial_page):
- t_list = TweetList(raw_html_user_initial_page)
- assert len(t_list) == 20
- def test_iter(self, raw_html_user_initial_page):
- t_list = TweetList(raw_html_user_initial_page)
- for t in t_list:
- assert isinstance(t, TweetBase)
- class TestTweet:
- all_types = [
- "plain",
- "reaction_tweet",
- "with_link",
- "retweet",
- "hashtags",
- "mentions",
- "stats",
- ]
- @pytest.mark.parametrize("tweet_type", all_types)
- def test_tweet(self, tweet_test_data_factory, tweet_type):
- t, tweet_info = tweet_test_data_factory(tweet_type)
- for field, value in tweet_info._asdict().items():
- # It would be rather complicated to keep some test fixtures values
- # accurate (e.g. number of likes, retweets, ...) so for most
- # of them, the expected values are not set on purpose and therefore
- # not tested
- if value is not None:
- assert getattr(t, field) == value
- @pytest.mark.parametrize("tweet_type,expected_class", [
- ('plain', TweetTextOnly),
- ('reaction_tweet', TweetReaction),
- ('with_link', TweetLink),
- ('retweet', TweetRetweet)
- ])
- def test_tweet_type(self, tweet_test_data_factory, tweet_type, expected_class):
- t, tweet_info = tweet_test_data_factory(tweet_type)
- assert isinstance(t, expected_class)
|