Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_pyjson(self):
'json.encoder')

class TestCTest(CTest):
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_cjson(self):
self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')
self.assertEqual(self.json.decoder.scanstring.__module__, '_json')
Expand Down
8 changes: 3 additions & 5 deletions Lib/test/test_json/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from test.test_json import PyTest, CTest
from test import support

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class TestDecode:
Expand All @@ -18,7 +18,7 @@ def test_float(self):
self.assertIsInstance(rval, float)
self.assertEqual(rval, 1.0)

@unittest.skip('TODO: RUSTPYTHON; called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }')
@unittest.skip("TODO: RUSTPYTHON; called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }")
def test_nonascii_digits_rejected(self):
# JSON specifies only ascii digits, see gh-125687
for num in ["1\uff10", "0.\uff10", "0e\uff10"]:
Expand Down Expand Up @@ -135,9 +135,7 @@ def test_limit_int(self):


class TestPyDecode(TestDecode, PyTest): pass

class TestCDecode(TestDecode, CTest):
# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_limit_int(self):
return super().test_limit_int()
6 changes: 3 additions & 3 deletions Lib/test/test_json/test_default.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import collections
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
from test.test_json import PyTest, CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class TestDefault:
def test_default(self):
self.assertEqual(
self.dumps(type, default=repr),
self.dumps(repr(type)))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bad_default(self):
def default(obj):
if obj is NotImplemented:
Expand Down
8 changes: 3 additions & 5 deletions Lib/test/test_json/test_fail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests

from test.test_json import PyTest, CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests

# 2007-10-05
JSONDOCS = [
# https://json.org/JSON_checker/test/fail1.json
Expand Down Expand Up @@ -239,9 +239,7 @@ def test_linecol(self):
(line, col, idx))

class TestPyFail(TestFail, PyTest): pass

class TestCFail(TestFail, CTest):
# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_failures(self):
return super().test_failures()
27 changes: 13 additions & 14 deletions Lib/test/test_json/test_recursion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from test import support
from test.test_json import PyTest, CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class JSONTestObject:
Expand Down Expand Up @@ -70,13 +70,12 @@ def default(self, o):
self.fail("didn't raise ValueError on default recursion")


# TODO: RUSTPYTHON
@unittest.skip('TODO: RUSTPYTHON; crashes')
# TODO: RUSTPYHTON; needs to upgrade test.support to 3.14 above
# @support.skip_emscripten_stack_overflow()
# @support.skip_wasi_stack_overflow()
@unittest.skip("TODO: RUSTPYTHON; crashes")
@support.skip_if_unlimited_stack_size
@support.skip_emscripten_stack_overflow()
@support.skip_wasi_stack_overflow()
def test_highly_nested_objects_decoding(self):
very_deep = 200000
very_deep = 500_000
# test that loading highly-nested objects doesn't segfault when C
# accelerations are used. See #12017
with self.assertRaises(RecursionError):
Expand All @@ -89,14 +88,14 @@ def test_highly_nested_objects_decoding(self):
with support.infinite_recursion():
self.loads('[' * very_deep + '1' + ']' * very_deep)

# TODO: RUSTPYHTON; needs to upgrade test.support to 3.14 above
# @support.skip_wasi_stack_overflow()
# @support.skip_emscripten_stack_overflow()
@support.skip_if_unlimited_stack_size
@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 = [], {}
for x in range(200_000):
for x in range(500_000):
l, d = [l], {'k':d}
with self.assertRaises(RecursionError):
with support.infinite_recursion(5000):
Expand All @@ -105,9 +104,9 @@ def test_highly_nested_objects_encoding(self):
with support.infinite_recursion(5000):
self.dumps(d)

# TODO: RUSTPYHTON; needs to upgrade test.support to 3.14 above
# @support.skip_emscripten_stack_overflow()
# @support.skip_wasi_stack_overflow()
@support.skip_if_unlimited_stack_size
@support.skip_emscripten_stack_overflow()
@support.skip_wasi_stack_overflow()
def test_endless_recursion(self):
# See #12051
class EndlessJSONEncoder(self.json.JSONEncoder):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_json/test_scanstring.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from test.test_json import PyTest, CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class TestScanstring:
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_bad_escapes(self):
with self.assertRaises(self.JSONDecodeError, msg=s):
scanstring(s, 1, True)

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_overflow(self):
with self.assertRaises(OverflowError):
self.json.decoder.scanstring("xxx", sys.maxsize+1)
Expand Down
40 changes: 36 additions & 4 deletions Lib/test/test_json/test_speedups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from test.test_json import CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class BadBool:
Expand Down Expand Up @@ -40,7 +40,7 @@ def test_make_encoder(self):
b"\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
None)

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'NoneType' object is not callable
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'NoneType' object is not callable
def test_bad_str_encoder(self):
# Issue #31505: There shouldn't be an assertion failure in case
# c_make_encoder() receives a bad encoder() argument.
Expand All @@ -62,7 +62,7 @@ def bad_encoder2(*args):
with self.assertRaises(ZeroDivisionError):
enc('spam', 4)

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bad_markers_argument_to_encoder(self):
# https://bugs.python.org/issue45269
with self.assertRaisesRegex(
Expand All @@ -72,7 +72,7 @@ def test_bad_markers_argument_to_encoder(self):
self.json.encoder.c_make_encoder(1, None, None, None, ': ', ', ',
False, False, False)

@unittest.expectedFailure # TODO: RUSTPYTHON; ZeroDivisionError not raised by test
@unittest.expectedFailure # TODO: RUSTPYTHON; ZeroDivisionError not raised by test
def test_bad_bool_args(self):
def test(name):
self.json.encoder.JSONEncoder(**{name: BadBool()}).encode({'a': 1})
Expand All @@ -85,3 +85,35 @@ def test(name):
def test_unsortable_keys(self):
with self.assertRaises(TypeError):
self.json.encoder.JSONEncoder(sort_keys=True).encode({'a': 1, 1: 'a'})

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'NoneType' object is not callable
def test_current_indent_level(self):
enc = self.json.encoder.c_make_encoder(
markers=None,
default=str,
encoder=self.json.encoder.c_encode_basestring,
indent='\t',
key_separator=': ',
item_separator=', ',
sort_keys=False,
skipkeys=False,
allow_nan=False)
expected = (
'[\n'
'\t"spam", \n'
'\t{\n'
'\t\t"ham": "eggs"\n'
'\t}\n'
']')
self.assertEqual(enc(['spam', {'ham': 'eggs'}], 0)[0], expected)
self.assertEqual(enc(['spam', {'ham': 'eggs'}], -3)[0], expected)
expected2 = (
'[\n'
'\t\t\t\t"spam", \n'
'\t\t\t\t{\n'
'\t\t\t\t\t"ham": "eggs"\n'
'\t\t\t\t}\n'
'\t\t\t]')
self.assertEqual(enc(['spam', {'ham': 'eggs'}], 3)[0], expected2)
self.assertRaises(TypeError, enc, ['spam', {'ham': 'eggs'}], 3.0)
self.assertRaises(TypeError, enc, ['spam', {'ham': 'eggs'}])
13 changes: 3 additions & 10 deletions Lib/test/test_json/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@
import subprocess

from test import support
from test.support import force_not_colorized, os_helper
from test.support import force_colorized, force_not_colorized, os_helper
from test.support.script_helper import assert_python_ok

from _colorize import get_theme

# XXX: RUSTPYTHON; force_colorized not available in test.support
def force_colorized(func):
"""Placeholder decorator for RustPython - force_colorized not available."""
import functools
@functools.wraps(func)
def wrapper(*args, **kwargs):
raise unittest.SkipTest("TODO: RUSTPYTHON; force_colorized not available")
return wrapper


@support.requires_subprocess()
@support.skip_if_pgo_task
class TestMain(unittest.TestCase):
data = """

Expand Down Expand Up @@ -328,6 +320,7 @@ def test_colors(self):


@support.requires_subprocess()
@support.skip_if_pgo_task
class TestTool(TestMain):
module = 'json.tool'

Expand Down
8 changes: 2 additions & 6 deletions Lib/test/test_json/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import OrderedDict
from test.test_json import PyTest, CTest

import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests


class TestUnicode:
Expand Down Expand Up @@ -137,19 +137,15 @@ def test_object_pairs_hook_with_unicode(self):


class TestPyUnicode(TestUnicode, PyTest): pass

class TestCUnicode(TestUnicode, CTest):
# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_ascii_non_printable_encode(self):
return super().test_ascii_non_printable_encode()

# TODO: RUSTPYTHON
@unittest.skip("TODO: RUSTPYTHON; panics with 'str has surrogates'")
def test_single_surrogate_decode(self):
return super().test_single_surrogate_decode()

# TODO: RUSTPYTHON
@unittest.skip("TODO: RUSTPYTHON; panics with 'str has surrogates'")
def test_single_surrogate_encode(self):
return super().test_single_surrogate_encode()
Loading