summaryrefslogtreecommitdiffstats
path: root/tests/test_error.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:21:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:21:29 +0000
commit683f1f3ddde13390781318b9fe4a6841ea35d145 (patch)
treec21fddf99f2e5233bb3f22bbafd0d711fe7c5d95 /tests/test_error.py
parentInitial commit. (diff)
downloadpython-tomli-683f1f3ddde13390781318b9fe4a6841ea35d145.tar.xz
python-tomli-683f1f3ddde13390781318b9fe4a6841ea35d145.zip
Adding upstream version 2.0.1.upstream/2.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_error.py')
-rw-r--r--tests/test_error.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_error.py b/tests/test_error.py
new file mode 100644
index 0000000..7244626
--- /dev/null
+++ b/tests/test_error.py
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2021 Taneli Hukkinen
+# Licensed to PSF under a Contributor Agreement.
+
+import unittest
+
+from . import tomllib
+
+
+class TestError(unittest.TestCase):
+ def test_line_and_col(self):
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads("val=.")
+ self.assertEqual(str(exc_info.exception), "Invalid value (at line 1, column 5)")
+
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads(".")
+ self.assertEqual(
+ str(exc_info.exception), "Invalid statement (at line 1, column 1)"
+ )
+
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads("\n\nval=.")
+ self.assertEqual(str(exc_info.exception), "Invalid value (at line 3, column 5)")
+
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads("\n\n.")
+ self.assertEqual(
+ str(exc_info.exception), "Invalid statement (at line 3, column 1)"
+ )
+
+ def test_missing_value(self):
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads("\n\nfwfw=")
+ self.assertEqual(str(exc_info.exception), "Invalid value (at end of document)")
+
+ def test_invalid_char_quotes(self):
+ with self.assertRaises(tomllib.TOMLDecodeError) as exc_info:
+ tomllib.loads("v = '\n'")
+ self.assertTrue(" '\\n' " in str(exc_info.exception))
+
+ def test_module_name(self):
+ self.assertEqual(tomllib.TOMLDecodeError().__module__, tomllib.__name__)
+
+ def test_invalid_parse_float(self):
+ def dict_returner(s: str) -> dict:
+ return {}
+
+ def list_returner(s: str) -> list:
+ return []
+
+ for invalid_parse_float in (dict_returner, list_returner):
+ with self.assertRaises(ValueError) as exc_info:
+ tomllib.loads("f=0.1", parse_float=invalid_parse_float)
+ self.assertEqual(
+ str(exc_info.exception), "parse_float must not return dicts or lists"
+ )