Skip to content

Commit b1fe166

Browse files
authored
Merge pull request #679 from DocNow/media-variants
Add missing variants field to media
2 parents cdb0350 + a7e5204 commit b1fe166

14 files changed

+39
-69
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
setup_requires=["pytest-runner"],
3131
tests_require=[
3232
"pytest",
33+
"black",
3334
"pytest-black",
3435
"python-dotenv",
3536
"pytz",

test_twarc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def test_follower_ids_with_user_id():
337337

338338

339339
def test_follower_ids_max_pages():
340-
341340
ids = list(T.follower_ids(813286, max_pages=1))
342341
assert 0 < len(ids) <= 5000
343342
ids = list(T.follower_ids(813286, max_pages=2))
@@ -363,7 +362,6 @@ def test_friend_ids_with_user_id():
363362

364363

365364
def test_friend_ids_max_pages():
366-
367365
ids = list(T.friend_ids(27260086, max_pages=1))
368366
assert 0 < len(ids) <= 5000
369367
ids = list(T.friend_ids(27260086, max_pages=2))
@@ -799,7 +797,6 @@ def test_csv_retweet():
799797

800798

801799
def test_csv_retweet_hashtag():
802-
803800
toplevel_hashtags = 0
804801
rt_hashtags = 0
805802

test_twarc2.py

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
)
3232

3333

34-
def atest_version():
34+
def test_version():
3535
import setup
3636

3737
assert setup.version == version
@@ -40,7 +40,7 @@ def atest_version():
4040
assert f"twarc/{version}" in user_agent
4141

4242

43-
def atest_auth_types_interaction():
43+
def test_auth_types_interaction():
4444
"""
4545
Test the various options for configuration work as expected.
4646
"""
@@ -81,7 +81,7 @@ def atest_auth_types_interaction():
8181
tw.sample()
8282

8383

84-
def atest_sample():
84+
def test_sample():
8585
# event to tell the filter stream to close
8686
event = threading.Event()
8787

@@ -101,7 +101,6 @@ def atest_sample():
101101

102102
@pytest.mark.parametrize("sort_order", ["recency", "relevancy"])
103103
def test_search_recent(sort_order):
104-
105104
found_tweets = 0
106105
pages = 0
107106

@@ -116,8 +115,7 @@ def test_search_recent(sort_order):
116115
assert 100 <= found_tweets <= 200
117116

118117

119-
def atest_counts_recent():
120-
118+
def test_counts_recent():
121119
found_counts = 0
122120

123121
for response_page in T.counts_recent("twitter is:verified", granularity="day"):
@@ -132,8 +130,7 @@ def atest_counts_recent():
132130
os.environ.get("SKIP_ACADEMIC_PRODUCT_TRACK") != None,
133131
reason="No Academic Research Product Track access",
134132
)
135-
def atest_counts_empty_page():
136-
133+
def test_counts_empty_page():
137134
found_counts = 0
138135

139136
for response_page in T.counts_all(
@@ -148,7 +145,7 @@ def atest_counts_empty_page():
148145
assert found_counts == 72
149146

150147

151-
def atest_search_times():
148+
def test_search_times():
152149
found = False
153150
now = datetime.datetime.now(tz=pytz.timezone("Australia/Melbourne"))
154151
# twitter api doesn't resolve microseconds so strip them for comparison
@@ -169,12 +166,11 @@ def atest_search_times():
169166
assert found
170167

171168

172-
def atest_user_ids_lookup():
169+
def test_user_ids_lookup():
173170
users_found = 0
174171
users_not_found = 0
175172

176173
for response in T.user_lookup(range(1, 1000)):
177-
178174
for profile in response["data"]:
179175
users_found += 1
180176

@@ -189,7 +185,7 @@ def atest_user_ids_lookup():
189185
assert users_found + users_not_found == 999
190186

191187

192-
def atest_usernames_lookup():
188+
def test_usernames_lookup():
193189
users_found = 0
194190
usernames = ["jack", "barackobama", "rihanna"]
195191
for response in T.user_lookup(usernames, usernames=True):
@@ -198,13 +194,11 @@ def atest_usernames_lookup():
198194
assert users_found == 3
199195

200196

201-
def atest_tweet_lookup():
202-
197+
def test_tweet_lookup():
203198
tweets_found = 0
204199
tweets_not_found = 0
205200

206201
for response in T.tweet_lookup(range(1000, 2000)):
207-
208202
for tweet in response["data"]:
209203
tweets_found += 1
210204

@@ -227,7 +221,7 @@ def atest_tweet_lookup():
227221
os.environ.get("GITHUB_ACTIONS") != None,
228222
reason="stream() seems to throw a 400 error under GitHub Actions?!",
229223
)
230-
def atest_stream():
224+
def test_stream():
231225
# remove any active stream rules
232226
rules = T.get_stream_rules()
233227
if "data" in rules and len(rules["data"]) > 0:
@@ -280,7 +274,7 @@ def atest_stream():
280274
assert "data" not in rules
281275

282276

283-
def atest_timeline():
277+
def test_timeline():
284278
"""
285279
Test the user timeline endpoints.
286280
@@ -301,7 +295,7 @@ def atest_timeline():
301295
assert found >= 200
302296

303297

304-
def atest_timeline_username():
298+
def test_timeline_username():
305299
"""
306300
Test the user timeline endpoints with username.
307301
@@ -322,12 +316,12 @@ def atest_timeline_username():
322316
assert found >= 200
323317

324318

325-
def atest_missing_timeline():
319+
def test_missing_timeline():
326320
results = T.timeline(1033441111677788160)
327321
assert len(list(results)) == 0
328322

329323

330-
def atest_follows():
324+
def test_follows():
331325
"""
332326
Test followers and and following.
333327
@@ -349,7 +343,7 @@ def atest_follows():
349343
assert found >= 1000
350344

351345

352-
def atest_follows_username():
346+
def test_follows_username():
353347
"""
354348
Test followers and and following by username.
355349
@@ -371,7 +365,7 @@ def atest_follows_username():
371365
assert found >= 1000
372366

373367

374-
def atest_flattened():
368+
def test_flattened():
375369
"""
376370
This test uses the search API to test response flattening. It will look
377371
at each tweet to find evidence that all the expansions have worked. Once it
@@ -457,7 +451,7 @@ def atest_flattened():
457451
assert found_referenced_tweets, "found referenced tweets"
458452

459453

460-
def atest_ensure_flattened():
454+
def test_ensure_flattened():
461455
resp = next(T.search_recent("twitter", max_results=20))
462456

463457
# flatten a response
@@ -510,15 +504,15 @@ def atest_ensure_flattened():
510504
twarc.expansions.ensure_flattened([[{"data": {"fake": "list_of_lists"}}]])
511505

512506

513-
def atest_ensure_flattened_errors():
507+
def test_ensure_flattened_errors():
514508
"""
515509
Test that ensure_flattened doesn't return tweets for API responses that only contain errors.
516510
"""
517511
data = {"errors": ["fake error"]}
518512
assert twarc.expansions.ensure_flattened(data) == []
519513

520514

521-
def atest_ensure_user_id():
515+
def test_ensure_user_id():
522516
"""
523517
Test _ensure_user_id's ability to discriminate correctly between IDs and
524518
screen names.
@@ -538,8 +532,7 @@ def atest_ensure_user_id():
538532
assert T._ensure_user_id(1033441111677788160) == "1033441111677788160"
539533

540534

541-
def atest_liking_users():
542-
535+
def test_liking_users():
543536
# This is one of @jack's tweets about the Twitter API
544537
likes = T.liking_users(1460417326130421765)
545538

@@ -554,8 +547,7 @@ def atest_liking_users():
554547
break
555548

556549

557-
def atest_retweeted_by():
558-
550+
def test_retweeted_by():
559551
# This is one of @jack's tweets about the Twitter API
560552
retweet_users = T.retweeted_by(1460417326130421765)
561553

@@ -570,8 +562,7 @@ def atest_retweeted_by():
570562
break
571563

572564

573-
def atest_liked_tweets():
574-
565+
def test_liked_tweets():
575566
# What has @jack liked?
576567
liked_tweets = T.liked_tweets(12)
577568

@@ -586,62 +577,61 @@ def atest_liked_tweets():
586577
break
587578

588579

589-
def atest_list_lookup():
580+
def test_list_lookup():
590581
parks_list = T.list_lookup(715919216927322112)
591582
assert "data" in parks_list
592583
assert parks_list["data"]["name"] == "National-parks"
593584

594585

595-
def atest_list_members():
586+
def test_list_members():
596587
response = list(T.list_members(715919216927322112))
597588
assert len(response) == 1
598589
members = twarc.expansions.flatten(response[0])
599590
assert len(members) == 8
600591

601592

602-
def atest_list_followers():
593+
def test_list_followers():
603594
response = list(T.list_followers(715919216927322112))
604595
assert len(response) >= 2
605596
followers = twarc.expansions.flatten(response[0])
606597
assert len(followers) > 50
607598

608599

609-
def atest_list_memberships():
600+
def test_list_memberships():
610601
response = list(T.list_memberships("64flavors"))
611602
assert len(response) == 1
612603
lists = twarc.expansions.flatten(response[0])
613604
assert len(lists) >= 9
614605

615606

616-
def atest_followed_lists():
607+
def test_followed_lists():
617608
response = list(T.followed_lists("nasa"))
618609
assert len(response) == 1
619610
lists = twarc.expansions.flatten(response[0])
620611
assert len(lists) >= 1
621612

622613

623-
def atest_owned_lists():
614+
def test_owned_lists():
624615
response = list(T.owned_lists("nasa"))
625616
assert len(response) >= 1
626617
lists = twarc.expansions.flatten(response[0])
627618
assert len(lists) >= 11
628619

629620

630-
def atest_list_tweets():
621+
def test_list_tweets():
631622
response = next(T.list_tweets(715919216927322112))
632623
assert "data" in response
633624
tweets = twarc.expansions.flatten(response)
634625
assert len(tweets) >= 90
635626

636627

637-
def atest_user_lookup_non_existent():
628+
def test_user_lookup_non_existent():
638629
with pytest.raises(ValueError):
639630
# This user does not exist, and a value error should be raised
640631
T._ensure_user("noasdfasdf")
641632

642633

643-
def atest_twarc_metadata():
644-
634+
def test_twarc_metadata():
645635
# With metadata (default)
646636
event = threading.Event()
647637
for i, response in enumerate(T.sample(event=event)):
@@ -667,7 +657,7 @@ def atest_twarc_metadata():
667657
T.metadata = True
668658

669659

670-
def atest_docs_requirements():
660+
def test_docs_requirements():
671661
"""
672662
Make sure that the mkdocs requirements has everything that is in the
673663
twarc requirements so the readthedocs build doesn't fail.
@@ -678,7 +668,7 @@ def atest_docs_requirements():
678668
assert twarc_reqs.issubset(mkdocs_reqs)
679669

680670

681-
def atest_geo():
671+
def test_geo():
682672
print(T.geo(query="Silver Spring"))
683673

684674

twarc/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def search(
139139
reached_end = False
140140

141141
while True:
142-
143142
# note: max_id changes as results are retrieved
144143
if max_id:
145144
params["max_id"] = max_id
@@ -724,7 +723,6 @@ def replies(self, tweet, recursive=False, prune=()):
724723
tweet_id = tweet["id_str"]
725724
log.info("looking for replies to: %s", tweet_id)
726725
for reply in self.search("to:%s" % screen_name, since_id=tweet_id):
727-
728726
if reply["in_reply_to_status_id_str"] != tweet_id:
729727
continue
730728

twarc/client2.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ def _search(
256256
if using_counts:
257257
while True:
258258
for response in self.get_paginated(url, params=params):
259-
260259
# Note that we're ensuring the appropriate amount of sleep is
261260
# taken before yielding every item. This ensures that we won't
262261
# exceed the rate limit even in cases where a response generator
@@ -309,7 +308,6 @@ def _search(
309308

310309
else:
311310
for response in self.get_paginated(url, params=params):
312-
313311
# Note that we're ensuring the appropriate amount of sleep is
314312
# taken before yielding every item. This ensures that we won't
315313
# exceed the rate limit even in cases where a response generator
@@ -914,7 +912,6 @@ def tweet_lookup(
914912
"""
915913

916914
def lookup_batch(tweet_id):
917-
918915
url = "https://api.twitter.com/2/tweets"
919916

920917
params = self._prepare_params(
@@ -1653,7 +1650,6 @@ def get_paginated(self, *args, **kwargs):
16531650
token_param = "next_token"
16541651

16551652
while "meta" in page and "next_token" in page["meta"]:
1656-
16571653
if "params" in kwargs:
16581654
kwargs["params"][token_param] = page["meta"]["next_token"]
16591655
else:

twarc/command.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ def stop(signal, frame):
291291
line_count = 0
292292
file_count = 0
293293
for thing in things:
294-
295294
# rotate the files if necessary
296295
if args.output and args.split and line_count % args.split == 0:
297296
file_count += 1

0 commit comments

Comments
 (0)