diff options
author | Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> | 2024-11-13 12:52:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-13 12:52:16 (GMT) |
commit | 29b5323c4567dc7772e1d30a7ba1cbad52fe10a9 (patch) | |
tree | e0adef119b01d1726f2adf442f6d47c6caf48c30 /Lib/test/test_tomllib | |
parent | a12690ef49e8fc8a3af4c5f1757eb3caffb35e03 (diff) | |
download | cpython-29b5323c4567dc7772e1d30a7ba1cbad52fe10a9.zip cpython-29b5323c4567dc7772e1d30a7ba1cbad52fe10a9.tar.gz cpython-29b5323c4567dc7772e1d30a7ba1cbad52fe10a9.tar.bz2 |
gh-126175: Add attributes to TOMLDecodeError. Deprecate free-form `__init__` args (GH-126428)
Diffstat (limited to 'Lib/test/test_tomllib')
-rw-r--r-- | Lib/test/test_tomllib/test_error.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Lib/test/test_tomllib/test_error.py b/Lib/test/test_tomllib/test_error.py index d2ef59a..3a85874 100644 --- a/Lib/test/test_tomllib/test_error.py +++ b/Lib/test/test_tomllib/test_error.py @@ -49,7 +49,9 @@ class TestError(unittest.TestCase): 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: @@ -64,3 +66,33 @@ class TestError(unittest.TestCase): 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) |