31
31
)
32
32
33
33
34
- def atest_version ():
34
+ def test_version ():
35
35
import setup
36
36
37
37
assert setup .version == version
@@ -40,7 +40,7 @@ def atest_version():
40
40
assert f"twarc/{ version } " in user_agent
41
41
42
42
43
- def atest_auth_types_interaction ():
43
+ def test_auth_types_interaction ():
44
44
"""
45
45
Test the various options for configuration work as expected.
46
46
"""
@@ -81,7 +81,7 @@ def atest_auth_types_interaction():
81
81
tw .sample ()
82
82
83
83
84
- def atest_sample ():
84
+ def test_sample ():
85
85
# event to tell the filter stream to close
86
86
event = threading .Event ()
87
87
@@ -101,7 +101,6 @@ def atest_sample():
101
101
102
102
@pytest .mark .parametrize ("sort_order" , ["recency" , "relevancy" ])
103
103
def test_search_recent (sort_order ):
104
-
105
104
found_tweets = 0
106
105
pages = 0
107
106
@@ -116,8 +115,7 @@ def test_search_recent(sort_order):
116
115
assert 100 <= found_tweets <= 200
117
116
118
117
119
- def atest_counts_recent ():
120
-
118
+ def test_counts_recent ():
121
119
found_counts = 0
122
120
123
121
for response_page in T .counts_recent ("twitter is:verified" , granularity = "day" ):
@@ -132,8 +130,7 @@ def atest_counts_recent():
132
130
os .environ .get ("SKIP_ACADEMIC_PRODUCT_TRACK" ) != None ,
133
131
reason = "No Academic Research Product Track access" ,
134
132
)
135
- def atest_counts_empty_page ():
136
-
133
+ def test_counts_empty_page ():
137
134
found_counts = 0
138
135
139
136
for response_page in T .counts_all (
@@ -148,7 +145,7 @@ def atest_counts_empty_page():
148
145
assert found_counts == 72
149
146
150
147
151
- def atest_search_times ():
148
+ def test_search_times ():
152
149
found = False
153
150
now = datetime .datetime .now (tz = pytz .timezone ("Australia/Melbourne" ))
154
151
# twitter api doesn't resolve microseconds so strip them for comparison
@@ -169,12 +166,11 @@ def atest_search_times():
169
166
assert found
170
167
171
168
172
- def atest_user_ids_lookup ():
169
+ def test_user_ids_lookup ():
173
170
users_found = 0
174
171
users_not_found = 0
175
172
176
173
for response in T .user_lookup (range (1 , 1000 )):
177
-
178
174
for profile in response ["data" ]:
179
175
users_found += 1
180
176
@@ -189,7 +185,7 @@ def atest_user_ids_lookup():
189
185
assert users_found + users_not_found == 999
190
186
191
187
192
- def atest_usernames_lookup ():
188
+ def test_usernames_lookup ():
193
189
users_found = 0
194
190
usernames = ["jack" , "barackobama" , "rihanna" ]
195
191
for response in T .user_lookup (usernames , usernames = True ):
@@ -198,13 +194,11 @@ def atest_usernames_lookup():
198
194
assert users_found == 3
199
195
200
196
201
- def atest_tweet_lookup ():
202
-
197
+ def test_tweet_lookup ():
203
198
tweets_found = 0
204
199
tweets_not_found = 0
205
200
206
201
for response in T .tweet_lookup (range (1000 , 2000 )):
207
-
208
202
for tweet in response ["data" ]:
209
203
tweets_found += 1
210
204
@@ -227,7 +221,7 @@ def atest_tweet_lookup():
227
221
os .environ .get ("GITHUB_ACTIONS" ) != None ,
228
222
reason = "stream() seems to throw a 400 error under GitHub Actions?!" ,
229
223
)
230
- def atest_stream ():
224
+ def test_stream ():
231
225
# remove any active stream rules
232
226
rules = T .get_stream_rules ()
233
227
if "data" in rules and len (rules ["data" ]) > 0 :
@@ -280,7 +274,7 @@ def atest_stream():
280
274
assert "data" not in rules
281
275
282
276
283
- def atest_timeline ():
277
+ def test_timeline ():
284
278
"""
285
279
Test the user timeline endpoints.
286
280
@@ -301,7 +295,7 @@ def atest_timeline():
301
295
assert found >= 200
302
296
303
297
304
- def atest_timeline_username ():
298
+ def test_timeline_username ():
305
299
"""
306
300
Test the user timeline endpoints with username.
307
301
@@ -322,12 +316,12 @@ def atest_timeline_username():
322
316
assert found >= 200
323
317
324
318
325
- def atest_missing_timeline ():
319
+ def test_missing_timeline ():
326
320
results = T .timeline (1033441111677788160 )
327
321
assert len (list (results )) == 0
328
322
329
323
330
- def atest_follows ():
324
+ def test_follows ():
331
325
"""
332
326
Test followers and and following.
333
327
@@ -349,7 +343,7 @@ def atest_follows():
349
343
assert found >= 1000
350
344
351
345
352
- def atest_follows_username ():
346
+ def test_follows_username ():
353
347
"""
354
348
Test followers and and following by username.
355
349
@@ -371,7 +365,7 @@ def atest_follows_username():
371
365
assert found >= 1000
372
366
373
367
374
- def atest_flattened ():
368
+ def test_flattened ():
375
369
"""
376
370
This test uses the search API to test response flattening. It will look
377
371
at each tweet to find evidence that all the expansions have worked. Once it
@@ -457,7 +451,7 @@ def atest_flattened():
457
451
assert found_referenced_tweets , "found referenced tweets"
458
452
459
453
460
- def atest_ensure_flattened ():
454
+ def test_ensure_flattened ():
461
455
resp = next (T .search_recent ("twitter" , max_results = 20 ))
462
456
463
457
# flatten a response
@@ -510,15 +504,15 @@ def atest_ensure_flattened():
510
504
twarc .expansions .ensure_flattened ([[{"data" : {"fake" : "list_of_lists" }}]])
511
505
512
506
513
- def atest_ensure_flattened_errors ():
507
+ def test_ensure_flattened_errors ():
514
508
"""
515
509
Test that ensure_flattened doesn't return tweets for API responses that only contain errors.
516
510
"""
517
511
data = {"errors" : ["fake error" ]}
518
512
assert twarc .expansions .ensure_flattened (data ) == []
519
513
520
514
521
- def atest_ensure_user_id ():
515
+ def test_ensure_user_id ():
522
516
"""
523
517
Test _ensure_user_id's ability to discriminate correctly between IDs and
524
518
screen names.
@@ -538,8 +532,7 @@ def atest_ensure_user_id():
538
532
assert T ._ensure_user_id (1033441111677788160 ) == "1033441111677788160"
539
533
540
534
541
- def atest_liking_users ():
542
-
535
+ def test_liking_users ():
543
536
# This is one of @jack's tweets about the Twitter API
544
537
likes = T .liking_users (1460417326130421765 )
545
538
@@ -554,8 +547,7 @@ def atest_liking_users():
554
547
break
555
548
556
549
557
- def atest_retweeted_by ():
558
-
550
+ def test_retweeted_by ():
559
551
# This is one of @jack's tweets about the Twitter API
560
552
retweet_users = T .retweeted_by (1460417326130421765 )
561
553
@@ -570,8 +562,7 @@ def atest_retweeted_by():
570
562
break
571
563
572
564
573
- def atest_liked_tweets ():
574
-
565
+ def test_liked_tweets ():
575
566
# What has @jack liked?
576
567
liked_tweets = T .liked_tweets (12 )
577
568
@@ -586,62 +577,61 @@ def atest_liked_tweets():
586
577
break
587
578
588
579
589
- def atest_list_lookup ():
580
+ def test_list_lookup ():
590
581
parks_list = T .list_lookup (715919216927322112 )
591
582
assert "data" in parks_list
592
583
assert parks_list ["data" ]["name" ] == "National-parks"
593
584
594
585
595
- def atest_list_members ():
586
+ def test_list_members ():
596
587
response = list (T .list_members (715919216927322112 ))
597
588
assert len (response ) == 1
598
589
members = twarc .expansions .flatten (response [0 ])
599
590
assert len (members ) == 8
600
591
601
592
602
- def atest_list_followers ():
593
+ def test_list_followers ():
603
594
response = list (T .list_followers (715919216927322112 ))
604
595
assert len (response ) >= 2
605
596
followers = twarc .expansions .flatten (response [0 ])
606
597
assert len (followers ) > 50
607
598
608
599
609
- def atest_list_memberships ():
600
+ def test_list_memberships ():
610
601
response = list (T .list_memberships ("64flavors" ))
611
602
assert len (response ) == 1
612
603
lists = twarc .expansions .flatten (response [0 ])
613
604
assert len (lists ) >= 9
614
605
615
606
616
- def atest_followed_lists ():
607
+ def test_followed_lists ():
617
608
response = list (T .followed_lists ("nasa" ))
618
609
assert len (response ) == 1
619
610
lists = twarc .expansions .flatten (response [0 ])
620
611
assert len (lists ) >= 1
621
612
622
613
623
- def atest_owned_lists ():
614
+ def test_owned_lists ():
624
615
response = list (T .owned_lists ("nasa" ))
625
616
assert len (response ) >= 1
626
617
lists = twarc .expansions .flatten (response [0 ])
627
618
assert len (lists ) >= 11
628
619
629
620
630
- def atest_list_tweets ():
621
+ def test_list_tweets ():
631
622
response = next (T .list_tweets (715919216927322112 ))
632
623
assert "data" in response
633
624
tweets = twarc .expansions .flatten (response )
634
625
assert len (tweets ) >= 90
635
626
636
627
637
- def atest_user_lookup_non_existent ():
628
+ def test_user_lookup_non_existent ():
638
629
with pytest .raises (ValueError ):
639
630
# This user does not exist, and a value error should be raised
640
631
T ._ensure_user ("noasdfasdf" )
641
632
642
633
643
- def atest_twarc_metadata ():
644
-
634
+ def test_twarc_metadata ():
645
635
# With metadata (default)
646
636
event = threading .Event ()
647
637
for i , response in enumerate (T .sample (event = event )):
@@ -667,7 +657,7 @@ def atest_twarc_metadata():
667
657
T .metadata = True
668
658
669
659
670
- def atest_docs_requirements ():
660
+ def test_docs_requirements ():
671
661
"""
672
662
Make sure that the mkdocs requirements has everything that is in the
673
663
twarc requirements so the readthedocs build doesn't fail.
@@ -678,7 +668,7 @@ def atest_docs_requirements():
678
668
assert twarc_reqs .issubset (mkdocs_reqs )
679
669
680
670
681
- def atest_geo ():
671
+ def test_geo ():
682
672
print (T .geo (query = "Silver Spring" ))
683
673
684
674
0 commit comments