diff options
author | Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> | 2024-10-02 02:58:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-02 02:58:08 (GMT) |
commit | 9ce90206b7a4649600218cf0bd4826db79c9a312 (patch) | |
tree | e656b4c100f65e7733439d97bf760fa84f17a657 /Lib/test | |
parent | 120729d862f0ef9979508899f7f63a9f3d9623cb (diff) | |
download | cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.zip cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.tar.gz cpython-9ce90206b7a4649600218cf0bd4826db79c9a312.tar.bz2 |
gh-124835: `tomllib.loads`: Raise TypeError not AttributeError. Improve message (#124587)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_tomllib/test_error.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_tomllib/test_error.py b/Lib/test/test_tomllib/test_error.py index 7244626..d2ef59a 100644 --- a/Lib/test/test_tomllib/test_error.py +++ b/Lib/test/test_tomllib/test_error.py @@ -39,6 +39,15 @@ class TestError(unittest.TestCase): 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__) |