Skip to content

Commit c007706

Browse files
author
thenamesweretakenalready
committed
🐛 Fix traceback in tests
1 parent 5e5994c commit c007706

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

tests/test_main.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,109 +21,128 @@ async def test_main():
2121
try:
2222
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")
2323
except Exception as e:
24-
errors.append({"Error in": "blank joke get", "Error": traceback.extract_tb()})
24+
_, __, exc_traceback = sys.exc_info()
25+
errors.append({"Error in": "blank joke get", "Error": traceback.extract_tb(exc_traceback)})
2526

2627
"""Testing auth tokens"""
2728
try:
2829
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")
2930
except Exception as e:
31+
_, __, exc_traceback = sys.exc_info()
3032
auth_token = None
31-
errors.append({"Error in": "auth usage", "Error": traceback.extract_tb()})
33+
errors.append({"Error in": "auth usage", "Error": traceback.extract_tb(exc_traceback)})
3234

3335
"""Testing for errors in categories"""
3436
try:
3537
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")
3638
except Exception as e:
37-
errors.append({"Error in": "category programming", "Error": traceback.extract_tb()})
39+
_, __, exc_traceback = sys.exc_info()
40+
errors.append({"Error in": "category programming", "Error": traceback.extract_tb(exc_traceback)})
3841
try:
3942
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")
4043
except Exception as e:
44+
_, __, exc_traceback = sys.exc_info()
4145
errors.append({"Error in": "category miscellaneous", "Error": traceback.extract_tb()})
4246
try:
4347
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")
4448
except Exception as e:
45-
errors.append({"Error in": "category dark", "Error": traceback.extract_tb()})
49+
_, __, exc_traceback = sys.exc_info()
50+
errors.append({"Error in": "category dark", "Error": traceback.extract_tb(exc_traceback)})
4651

4752
"""Testing for errors in blacklist"""
4853
try:
4954
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")
5055
except Exception as e:
51-
errors.append({"Error in": "blacklist nsfw", "Error": traceback.extract_tb()})
56+
_, __, exc_traceback = sys.exc_info()
57+
errors.append({"Error in": "blacklist nsfw", "Error": traceback.extract_tb(exc_traceback)})
5258

5359
try:
5460
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")
5561
except Exception as e:
56-
errors.append({"Error in": "blacklist religious", "Error": traceback.extract_tb()})
62+
_, __, exc_traceback = sys.exc_info()
63+
errors.append({"Error in": "blacklist religious", "Error": traceback.extract_tb(exc_traceback)})
5764

5865
try:
5966
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")
6067
except Exception as e:
61-
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb()})
68+
_, __, exc_traceback = sys.exc_info()
69+
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb(exc_traceback)})
6270

6371
try:
6472
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")
6573
except Exception as e:
66-
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb()})
74+
_, __, exc_traceback = sys.exc_info()
75+
errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb(exc_traceback)})
6776

6877
try:
6978
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")
7079
except Exception as e:
71-
errors.append({"Error in": "blacklist sexist", "Error": traceback.extract_tb()})
80+
_, __, exc_traceback = sys.exc_info()
81+
errors.append({"Error in": "blacklist sexist", "Error": traceback.extract_tb(exc_traceback)})
7282

7383
"""Testing for errors in response_format"""
7484
try:
7585
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")
7686
except Exception as e:
77-
errors.append({"Error in": "response_format xml", "Error": traceback.extract_tb()})
87+
_, __, exc_traceback = sys.exc_info()
88+
errors.append({"Error in": "response_format xml", "Error": traceback.extract_tb(exc_traceback)})
7889

7990
try:
8091
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")
8192
except Exception as e:
82-
errors.append({"Error in": "response_format yaml", "Error": traceback.extract_tb()})
93+
_, __, exc_traceback = sys.exc_info()
94+
errors.append({"Error in": "response_format yaml", "Error": traceback.extract_tb(exc_traceback)})
8395

8496
"""Testing for errors in type"""
8597
try:
8698
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")
8799
except Exception as e:
88-
errors.append({"Error in": "type single", "Error": traceback.extract_tb()})
100+
_, __, exc_traceback = sys.exc_info()
101+
errors.append({"Error in": "type single", "Error": traceback.extract_tb(exc_traceback)})
89102

90103
try:
91104
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")
92105
except Exception as e:
93-
errors.append({"Error in": "type double", "Error": traceback.extract_tb()})
106+
_, __, exc_traceback = sys.exc_info()
107+
errors.append({"Error in": "type double", "Error": traceback.extract_tb(exc_traceback)})
94108

95109
"""Testing for errors in search_string"""
96110
try:
97111
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")
98112
# as long as this gets a response, the api wrapper is fine;
99113
# it probably doesn't exist in a joke.
100114
except Exception as e:
101-
errors.append({"Error in": "search_string", "Error": traceback.extract_tb()})
115+
_, __, exc_traceback = sys.exc_info()
116+
errors.append({"Error in": "search_string", "Error": traceback.extract_tb(exc_traceback)})
102117

103118
"""Testing for errors in id_range"""
104119
try:
105120
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")
106121
except Exception as e:
107-
errors.append({"Error in": "id_range", "Error": traceback.extract_tb()})
122+
_, __, exc_traceback = sys.exc_info()
123+
errors.append({"Error in": "id_range", "Error": traceback.extract_tb(exc_traceback)})
108124

109125
"""Testing for errors in safe_mode"""
110126
try:
111127
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")
112128
except Exception as e:
113-
errors.append({"Error in": "safe_mode", "Error": traceback.extract_tb()})
129+
_, __, exc_traceback = sys.exc_info()
130+
errors.append({"Error in": "safe_mode", "Error": traceback.extract_tb(exc_traceback)})
114131

115132
"""Testing for errors in user agent"""
116133
try:
117134
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")
118135
except Exception as e:
119-
errors.append({"Error in": "user agent", "Error": traceback.extract_tb()})
136+
_, __, exc_traceback = sys.exc_info()
137+
errors.append({"Error in": "user agent", "Error": traceback.extract_tb(exc_traceback)})
120138

121139

122140
""" Testing jokeapi.submit_joke() """
123141
try:
124142
await j.submit_joke("Programming", ["foo", "bar"], {}, dry_run=True)
125143
except Exception as e:
126-
errors.append({"Error in": "dry_run", "Error": traceback.extract_tb()})
144+
_, __, exc_traceback = sys.exc_info()
145+
errors.append({"Error in": "dry_run", "Error": traceback.extract_tb(exc_traceback)})
127146

128147

129148
if len(errors):

0 commit comments

Comments
 (0)