This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 603
/
test.py
54 lines (39 loc) · 1.52 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
from twitter_scraper import get_tweets, get_trends
class TestFamilyUnderscore(unittest.TestCase):
def test_father(self):
user = "_"
tweets = list(get_tweets(query=user, pages=1))
self.assertTrue(tweets[0]["text"].__contains__("Want to feel old?"))
def test_mother(self):
user = "__"
tweets = list(get_tweets(query=user, pages=1))
self.assertTrue(
tweets[3]["text"].__contains__(
"It is a gift to be alive in the time of Beyoncé"
)
)
def test_child(self):
user = "___"
tweets = list(get_tweets(query=user, pages=1))
self.assertEqual(tweets[1]["text"], "“Review mirror”")
class TestPages(unittest.TestCase):
def test_25pages(self):
"""I don't know why but in some cases it only crawls 2~5 pages"""
user = "gvanrossum"
tweets = list(get_tweets(query=user, pages=25))
self.assertGreater(len(tweets), 498)
def test_languages(self):
user = "fcbarcelona_jp"
tweets = list(get_tweets(query=user, pages=1))
self.assertIn("likes", tweets[0])
self.assertIsInstance(tweets[0]["replies"], int)
self.assertGreaterEqual(tweets[1]["retweets"], 0)
class TestTrends(unittest.TestCase):
def test_returned(self):
self.assertIsInstance(get_trends(), list)
def test_returned_string(self):
for trend in get_trends():
self.assertIsInstance(trend, str)
if __name__ == "__main__":
unittest.main()