]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] Add test for explicit `cls` argument bypassing default JSON decoder (GH-154094...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 19 Jul 2026 12:27:04 +0000 (14:27 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 12:27:04 +0000 (12:27 +0000)
Add test for explicit `cls` argument bypassing default JSON decoder (GH-154094)

* Add test for skipped `cls=None` case

* Fix lint

* Add new line between classes
(cherry picked from commit 5380589615515fa9e2c48820073a3fd8e32a930d)

Co-authored-by: Dominic H <dom@dominic.sk>
Lib/test/test_json/test_decode.py

index 2250af964c022bf4fc3d95ee2238502e7fe0b51b..e46f19712953546e9dabe36be10984596278d161 100644 (file)
@@ -1,4 +1,5 @@
 import decimal
+import unittest.mock
 from io import StringIO
 from collections import OrderedDict
 from test.test_json import PyTest, CTest
@@ -130,6 +131,15 @@ class TestDecode:
             with self.assertRaises(ValueError):
                 self.loads('1' * (maxdigits + 1))
 
+    def test_explicit_cls_skips_json_decoder_default(self):
+        class CustomDecoder:
+            pass
+
+        with unittest.mock.patch.object(
+                CustomDecoder, 'decode', create=True) as mock_decode:
+            self.loads('{}', cls=CustomDecoder)
+        mock_decode.assert_called_once()
+
 
 class TestPyDecode(TestDecode, PyTest): pass
 class TestCDecode(TestDecode, CTest): pass