-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Previously, our JSON encoder monkey patch was to an unbound method. This resulted in throwing a misleading `TypeError` when trying to encode something non-encodable.
- Loading branch information
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# --------------------------------------------------------------------------- # | ||
# test_monkey.py # | ||
# # | ||
# Copyright © 2015-2021, original authors. # | ||
# All rights reserved. # | ||
# --------------------------------------------------------------------------- # | ||
|
||
|
||
import json | ||
|
||
from tests.base import TestCase | ||
|
||
|
||
class MonkeyPatchTests(TestCase): | ||
def test_json_encoder(self): | ||
try: | ||
json.dumps(object()) | ||
except TypeError as error: | ||
assert str(error) in { | ||
"Object of type 'object' is not JSON serializable", # Python 3.6 | ||
'Object of type object is not JSON serializable', # Python 3.7+ | ||
} |