aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_json
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_dump.py8
-rw-r--r--Lib/test/test_json/test_fail.py2
-rw-r--r--Lib/test/test_json/test_recursion.py3
-rw-r--r--Lib/test/test_json/test_tool.py4
4 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/test_json/test_dump.py b/Lib/test/test_json/test_dump.py
index 13b40020781..39470754003 100644
--- a/Lib/test/test_json/test_dump.py
+++ b/Lib/test/test_json/test_dump.py
@@ -22,6 +22,14 @@ class TestDump:
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
+ def test_dump_skipkeys_indent_empty(self):
+ v = {b'invalid_key': False}
+ self.assertEqual(self.json.dumps(v, skipkeys=True, indent=4), '{}')
+
+ def test_skipkeys_indent(self):
+ v = {b'invalid_key': False, 'valid_key': True}
+ self.assertEqual(self.json.dumps(v, skipkeys=True, indent=4), '{\n "valid_key": true\n}')
+
def test_encode_truefalse(self):
self.assertEqual(self.dumps(
{True: False, False: True}, sort_keys=True),
diff --git a/Lib/test/test_json/test_fail.py b/Lib/test/test_json/test_fail.py
index 7c1696cc66d..79c44af2fbf 100644
--- a/Lib/test/test_json/test_fail.py
+++ b/Lib/test/test_json/test_fail.py
@@ -102,7 +102,7 @@ class TestFail:
with self.assertRaisesRegex(TypeError,
'Object of type module is not JSON serializable') as cm:
self.dumps(sys)
- self.assertFalse(hasattr(cm.exception, '__notes__'))
+ self.assertNotHasAttr(cm.exception, '__notes__')
with self.assertRaises(TypeError) as cm:
self.dumps([1, [2, 3, sys]])
diff --git a/Lib/test/test_json/test_recursion.py b/Lib/test/test_json/test_recursion.py
index d82093f3895..5d7b56ff9ad 100644
--- a/Lib/test/test_json/test_recursion.py
+++ b/Lib/test/test_json/test_recursion.py
@@ -69,6 +69,7 @@ class TestRecursion:
@support.skip_emscripten_stack_overflow()
+ @support.skip_wasi_stack_overflow()
def test_highly_nested_objects_decoding(self):
very_deep = 200000
# test that loading highly-nested objects doesn't segfault when C
@@ -85,6 +86,7 @@ class TestRecursion:
@support.skip_wasi_stack_overflow()
@support.skip_emscripten_stack_overflow()
+ @support.requires_resource('cpu')
def test_highly_nested_objects_encoding(self):
# See #12051
l, d = [], {}
@@ -98,6 +100,7 @@ class TestRecursion:
self.dumps(d)
@support.skip_emscripten_stack_overflow()
+ @support.skip_wasi_stack_overflow()
def test_endless_recursion(self):
# See #12051
class EndlessJSONEncoder(self.json.JSONEncoder):
diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py
index 72cde3f0d6c..30f9bb33316 100644
--- a/Lib/test/test_json/test_tool.py
+++ b/Lib/test/test_json/test_tool.py
@@ -160,7 +160,7 @@ class TestMain(unittest.TestCase):
rc, out, err = assert_python_ok('-m', self.module, '-h',
PYTHON_COLORS='0')
self.assertEqual(rc, 0)
- self.assertTrue(out.startswith(b'usage: '))
+ self.assertStartsWith(out, b'usage: ')
self.assertEqual(err, b'')
def test_sort_keys_flag(self):
@@ -270,7 +270,7 @@ class TestMain(unittest.TestCase):
(r'" \"foo\" "', f'{t.string}" \\"foo\\" "{t.reset}'),
('"α"', f'{t.string}"\\u03b1"{t.reset}'),
('123', f'{t.number}123{t.reset}'),
- ('-1.2345e+23', f'{t.number}-1.2345e+23{t.reset}'),
+ ('-1.25e+23', f'{t.number}-1.25e+23{t.reset}'),
(r'{"\\": ""}',
f'''\
{ob}