Skip to content

Commit 5e5994c

Browse files
author
thenamesweretakenalready
committed
💚 Have tests provide full traceback
1 parent db8bc1b commit 5e5994c

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

tests/test_main.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import asyncio
55
import pytest
66
import pytest_asyncio.plugin
7+
import traceback
78

89
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, "src"))
910
from jokeapi import Jokes
@@ -20,109 +21,109 @@ async def test_main():
2021
try:
2122
await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
2223
except Exception as e:
23-
errors.append({"Error in": "blank joke get", "Error": e})
24+
errors.append({"Error in": "blank joke get", "Error": traceback.extract_tb()})
2425

2526
"""Testing auth tokens"""
2627
try:
2728
await j.get_joke(auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
2829
except Exception as e:
2930
auth_token = None
30-
errors.append({"Error in": "auth usage", "Error": e})
31+
errors.append({"Error in": "auth usage", "Error": traceback.extract_tb()})
3132

3233
"""Testing for errors in categories"""
3334
try:
3435
await j.get_joke(category=["programming"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
3536
except Exception as e:
36-
errors.append({"Error in": "category programming", "Error": e})
37+
errors.append({"Error in": "category programming", "Error": traceback.extract_tb()})
3738
try:
3839
await j.get_joke(category=["misc"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
3940
except Exception as e:
40-
errors.append({"Error in": "category miscellaneous", "Error": e})
41+
errors.append({"Error in": "category miscellaneous", "Error": traceback.extract_tb()})
4142
try:
4243
await j.get_joke(category=["dark"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
4344
except Exception as e:
44-
errors.append({"Error in": "category dark", "Error": e})
45+
errors.append({"Error in": "category dark", "Error": traceback.extract_tb()})
4546

4647
"""Testing for errors in blacklist"""
4748
try:
4849
await j.get_joke(blacklist=["nsfw"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
4950
except Exception as e:
50-
errors.append({"Error in": "blacklist nsfw", "Error": e})
51+
errors.append({"Error in": "blacklist nsfw", "Error": traceback.extract_tb()})
5152

5253
try:
5354
await j.get_joke(blacklist=["religious"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
5455
except Exception as e:
55-
errors.append({"Error in": "blacklist religious", "Error": e})
56+
errors.append({"Error in": "blacklist religious", "Error": traceback.extract_tb()})
5657

5758
try:
5859
await j.get_joke(blacklist=["political"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
5960
except Exception as e:
60-
errors.append({"Error in": "blacklist political", "Error": e})
61+
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb()})
6162

6263
try:
6364
await j.get_joke(blacklist=["racist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
6465
except Exception as e:
65-
errors.append({"Error in": "blacklist political", "Error": e})
66+
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb()})
6667

6768
try:
6869
await j.get_joke(blacklist=["sexist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
6970
except Exception as e:
70-
errors.append({"Error in": "blacklist sexist", "Error": e})
71+
errors.append({"Error in": "blacklist sexist", "Error": traceback.extract_tb()})
7172

7273
"""Testing for errors in response_format"""
7374
try:
7475
await j.get_joke(response_format="xml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
7576
except Exception as e:
76-
errors.append({"Error in": "response_format xml", "Error": e})
77+
errors.append({"Error in": "response_format xml", "Error": traceback.extract_tb()})
7778

7879
try:
7980
await j.get_joke(response_format="yaml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
8081
except Exception as e:
81-
errors.append({"Error in": "response_format yaml", "Error": e})
82+
errors.append({"Error in": "response_format yaml", "Error": traceback.extract_tb()})
8283

8384
"""Testing for errors in type"""
8485
try:
8586
await j.get_joke(joke_type="single", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
8687
except Exception as e:
87-
errors.append({"Error in": "type single", "Error": e})
88+
errors.append({"Error in": "type single", "Error": traceback.extract_tb()})
8889

8990
try:
9091
await j.get_joke(joke_type="twopart", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
9192
except Exception as e:
92-
errors.append({"Error in": "type double", "Error": e})
93+
errors.append({"Error in": "type double", "Error": traceback.extract_tb()})
9394

9495
"""Testing for errors in search_string"""
9596
try:
9697
await j.get_joke(search_string="search", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
9798
# as long as this gets a response, the api wrapper is fine;
9899
# it probably doesn't exist in a joke.
99100
except Exception as e:
100-
errors.append({"Error in": "search_string", "Error": e})
101+
errors.append({"Error in": "search_string", "Error": traceback.extract_tb()})
101102

102103
"""Testing for errors in id_range"""
103104
try:
104105
await j.get_joke(id_range=[30, 151], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
105106
except Exception as e:
106-
errors.append({"Error in": "id_range", "Error": e})
107+
errors.append({"Error in": "id_range", "Error": traceback.extract_tb()})
107108

108109
"""Testing for errors in safe_mode"""
109110
try:
110111
await j.get_joke(safe_mode=True, auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
111112
except Exception as e:
112-
errors.append({"Error in": "safe_mode", "Error": e})
113+
errors.append({"Error in": "safe_mode", "Error": traceback.extract_tb()})
113114

114115
"""Testing for errors in user agent"""
115116
try:
116117
await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36")
117118
except Exception as e:
118-
errors.append({"Error in": "user agent", "Error": e})
119+
errors.append({"Error in": "user agent", "Error": traceback.extract_tb()})
119120

120121

121122
""" Testing jokeapi.submit_joke() """
122123
try:
123124
await j.submit_joke("Programming", ["foo", "bar"], {}, dry_run=True)
124125
except Exception as e:
125-
errors.append({"Error in": "dry_run", "Error": e})
126+
errors.append({"Error in": "dry_run", "Error": traceback.extract_tb()})
126127

127128

128129
if len(errors):

0 commit comments

Comments
 (0)