Skip to content

Commit 23a8966

Browse files
authored
Update tomllib from 3.14.3 (#7048)
1 parent c8b4d63 commit 23a8966

5 files changed

Lines changed: 204 additions & 64 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,26 @@ def skip_if_pgo_task(test):
17391739
return test if ok else unittest.skip(msg)(test)
17401740

17411741

1742+
# XXX: RUSTPYTHON; Taken from 3.14.3
1743+
def skip_if_unlimited_stack_size(test):
1744+
"""Skip decorator for tests not run when an unlimited stack size is configured.
1745+
1746+
Tests using support.infinite_recursion([...]) may otherwise run into
1747+
an infinite loop, running until the memory on the system is filled and
1748+
crashing due to OOM.
1749+
1750+
See https://github.com/python/cpython/issues/143460.
1751+
"""
1752+
if is_emscripten or is_wasi or os.name == "nt":
1753+
return test
1754+
1755+
import resource
1756+
curlim, maxlim = resource.getrlimit(resource.RLIMIT_STACK)
1757+
unlimited_stack_size_cond = curlim == maxlim and curlim in (-1, 0xFFFF_FFFF_FFFF_FFFF)
1758+
reason = "Not run due to unlimited stack size"
1759+
return unittest.skipIf(unlimited_stack_size_cond, reason)(test)
1760+
1761+
17421762
def detect_api_mismatch(ref_api, other_api, *, ignore=()):
17431763
"""Returns the set of items in ref_api not in other_api, except for a
17441764
defined list of items to be ignored in this check.

Lib/test/test_tomllib/test_error.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,19 @@ def test_invalid_char_quotes(self):
3939
tomllib.loads("v = '\n'")
4040
self.assertTrue(" '\\n' " in str(exc_info.exception))
4141

42+
def test_type_error(self):
43+
with self.assertRaises(TypeError) as exc_info:
44+
tomllib.loads(b"v = 1") # type: ignore[arg-type]
45+
self.assertEqual(str(exc_info.exception), "Expected str object, not 'bytes'")
46+
47+
with self.assertRaises(TypeError) as exc_info:
48+
tomllib.loads(False) # type: ignore[arg-type]
49+
self.assertEqual(str(exc_info.exception), "Expected str object, not 'bool'")
50+
4251
def test_module_name(self):
43-
self.assertEqual(tomllib.TOMLDecodeError().__module__, tomllib.__name__)
52+
self.assertEqual(
53+
tomllib.TOMLDecodeError("", "", 0).__module__, tomllib.__name__
54+
)
4455

4556
def test_invalid_parse_float(self):
4657
def dict_returner(s: str) -> dict:
@@ -55,3 +66,33 @@ def list_returner(s: str) -> list:
5566
self.assertEqual(
5667
str(exc_info.exception), "parse_float must not return dicts or lists"
5768
)
69+
70+
def test_deprecated_tomldecodeerror(self):
71+
for args in [
72+
(),
73+
("err msg",),
74+
(None,),
75+
(None, "doc"),
76+
("err msg", None),
77+
(None, "doc", None),
78+
("err msg", "doc", None),
79+
("one", "two", "three", "four"),
80+
("one", "two", 3, "four", "five"),
81+
]:
82+
with self.assertWarns(DeprecationWarning):
83+
e = tomllib.TOMLDecodeError(*args) # type: ignore[arg-type]
84+
self.assertEqual(e.args, args)
85+
86+
def test_tomldecodeerror(self):
87+
msg = "error parsing"
88+
doc = "v=1\n[table]\nv='val'"
89+
pos = 13
90+
formatted_msg = "error parsing (at line 3, column 2)"
91+
e = tomllib.TOMLDecodeError(msg, doc, pos)
92+
self.assertEqual(e.args, (formatted_msg,))
93+
self.assertEqual(str(e), formatted_msg)
94+
self.assertEqual(e.msg, msg)
95+
self.assertEqual(e.doc, doc)
96+
self.assertEqual(e.pos, pos)
97+
self.assertEqual(e.lineno, 3)
98+
self.assertEqual(e.colno, 2)

Lib/test/test_tomllib/test_misc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
import datetime
77
from decimal import Decimal as D
8+
import importlib
89
from pathlib import Path
910
import sys
1011
import tempfile
@@ -92,6 +93,7 @@ def test_deepcopy(self):
9293
}
9394
self.assertEqual(obj_copy, expected_obj)
9495

96+
@support.skip_if_unlimited_stack_size
9597
def test_inline_array_recursion_limit(self):
9698
with support.infinite_recursion(max_depth=100):
9799
available = support.get_recursion_available()
@@ -103,6 +105,7 @@ def test_inline_array_recursion_limit(self):
103105
recursive_array_toml = "arr = " + nest_count * "[" + nest_count * "]"
104106
tomllib.loads(recursive_array_toml)
105107

108+
@support.skip_if_unlimited_stack_size
106109
def test_inline_table_recursion_limit(self):
107110
with support.infinite_recursion(max_depth=100):
108111
available = support.get_recursion_available()
@@ -113,3 +116,11 @@ def test_inline_table_recursion_limit(self):
113116
nest_count=nest_count):
114117
recursive_table_toml = nest_count * "key = {" + nest_count * "}"
115118
tomllib.loads(recursive_table_toml)
119+
120+
def test_types_import(self):
121+
"""Test that `_types` module runs.
122+
123+
The module is for type annotations only, so it is otherwise
124+
never imported by tests.
125+
"""
126+
importlib.import_module(f"{tomllib.__name__}._types")

0 commit comments

Comments
 (0)