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
20 changes: 20 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,26 @@ def skip_if_pgo_task(test):
return test if ok else unittest.skip(msg)(test)


# XXX: RUSTPYTHON; Taken from 3.14.3
def skip_if_unlimited_stack_size(test):
"""Skip decorator for tests not run when an unlimited stack size is configured.
Tests using support.infinite_recursion([...]) may otherwise run into
an infinite loop, running until the memory on the system is filled and
crashing due to OOM.
See https://github.com/python/cpython/issues/143460.
"""
if is_emscripten or is_wasi or os.name == "nt":
return test

import resource
curlim, maxlim = resource.getrlimit(resource.RLIMIT_STACK)
unlimited_stack_size_cond = curlim == maxlim and curlim in (-1, 0xFFFF_FFFF_FFFF_FFFF)
reason = "Not run due to unlimited stack size"
return unittest.skipIf(unlimited_stack_size_cond, reason)(test)


def detect_api_mismatch(ref_api, other_api, *, ignore=()):
"""Returns the set of items in ref_api not in other_api, except for a
defined list of items to be ignored in this check.
Expand Down
43 changes: 42 additions & 1 deletion Lib/test/test_tomllib/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ def test_invalid_char_quotes(self):
tomllib.loads("v = '\n'")
self.assertTrue(" '\\n' " in str(exc_info.exception))

def test_type_error(self):
with self.assertRaises(TypeError) as exc_info:
tomllib.loads(b"v = 1") # type: ignore[arg-type]
self.assertEqual(str(exc_info.exception), "Expected str object, not 'bytes'")

with self.assertRaises(TypeError) as exc_info:
tomllib.loads(False) # type: ignore[arg-type]
self.assertEqual(str(exc_info.exception), "Expected str object, not 'bool'")

def test_module_name(self):
self.assertEqual(tomllib.TOMLDecodeError().__module__, tomllib.__name__)
self.assertEqual(
tomllib.TOMLDecodeError("", "", 0).__module__, tomllib.__name__
)

def test_invalid_parse_float(self):
def dict_returner(s: str) -> dict:
Expand All @@ -55,3 +66,33 @@ def list_returner(s: str) -> list:
self.assertEqual(
str(exc_info.exception), "parse_float must not return dicts or lists"
)

def test_deprecated_tomldecodeerror(self):
for args in [
(),
("err msg",),
(None,),
(None, "doc"),
("err msg", None),
(None, "doc", None),
("err msg", "doc", None),
("one", "two", "three", "four"),
("one", "two", 3, "four", "five"),
]:
with self.assertWarns(DeprecationWarning):
e = tomllib.TOMLDecodeError(*args) # type: ignore[arg-type]
self.assertEqual(e.args, args)

def test_tomldecodeerror(self):
msg = "error parsing"
doc = "v=1\n[table]\nv='val'"
pos = 13
formatted_msg = "error parsing (at line 3, column 2)"
e = tomllib.TOMLDecodeError(msg, doc, pos)
self.assertEqual(e.args, (formatted_msg,))
self.assertEqual(str(e), formatted_msg)
self.assertEqual(e.msg, msg)
self.assertEqual(e.doc, doc)
self.assertEqual(e.pos, pos)
self.assertEqual(e.lineno, 3)
self.assertEqual(e.colno, 2)
11 changes: 11 additions & 0 deletions Lib/test/test_tomllib/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import datetime
from decimal import Decimal as D
import importlib
from pathlib import Path
import sys
import tempfile
Expand Down Expand Up @@ -92,6 +93,7 @@ def test_deepcopy(self):
}
self.assertEqual(obj_copy, expected_obj)

@support.skip_if_unlimited_stack_size
def test_inline_array_recursion_limit(self):
with support.infinite_recursion(max_depth=100):
available = support.get_recursion_available()
Expand All @@ -103,6 +105,7 @@ def test_inline_array_recursion_limit(self):
recursive_array_toml = "arr = " + nest_count * "[" + nest_count * "]"
tomllib.loads(recursive_array_toml)

@support.skip_if_unlimited_stack_size
def test_inline_table_recursion_limit(self):
with support.infinite_recursion(max_depth=100):
available = support.get_recursion_available()
Expand All @@ -113,3 +116,11 @@ def test_inline_table_recursion_limit(self):
nest_count=nest_count):
recursive_table_toml = nest_count * "key = {" + nest_count * "}"
tomllib.loads(recursive_table_toml)

def test_types_import(self):
"""Test that `_types` module runs.
The module is for type annotations only, so it is otherwise
never imported by tests.
"""
importlib.import_module(f"{tomllib.__name__}._types")
Loading
Loading