[Python-checkins] gh-99124: use concrete exception types in `test_builtin` (GH-99125)

miss-islington webhook-mailer at python.org
Mon Nov 7 21:12:55 EST 2022


https://github.com/python/cpython/commit/42fb233c52f438b42666d3d09937ea8130f93d6c
commit: 42fb233c52f438b42666d3d09937ea8130f93d6c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-11-07T18:12:48-08:00
summary:

gh-99124: use concrete exception types in `test_builtin` (GH-99125)

(cherry picked from commit c32bc1bffd9d63ede0d0505abab983247a3ad0c6)

Co-authored-by: Nikita Sobolev <mail at sobolevn.me>

files:
M Lib/test/test_builtin.py

diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 4cc9315eba44..6cd72eda774c 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -159,7 +159,7 @@ def test_import(self):
         __import__('string')
         __import__(name='sys')
         __import__(name='time', level=0)
-        self.assertRaises(ImportError, __import__, 'spamspam')
+        self.assertRaises(ModuleNotFoundError, __import__, 'spamspam')
         self.assertRaises(TypeError, __import__, 1, 2, 3, 4)
         self.assertRaises(ValueError, __import__, '')
         self.assertRaises(TypeError, __import__, 'sys', name='sys')
@@ -2376,7 +2376,7 @@ def test_type_name(self):
                 self.assertEqual(A.__module__, __name__)
         with self.assertRaises(ValueError):
             type('A\x00B', (), {})
-        with self.assertRaises(ValueError):
+        with self.assertRaises(UnicodeEncodeError):
             type('A\udcdcB', (), {})
         with self.assertRaises(TypeError):
             type(b'A', (), {})
@@ -2393,7 +2393,7 @@ def test_type_name(self):
         with self.assertRaises(ValueError):
             A.__name__ = 'A\x00B'
         self.assertEqual(A.__name__, 'C')
-        with self.assertRaises(ValueError):
+        with self.assertRaises(UnicodeEncodeError):
             A.__name__ = 'A\udcdcB'
         self.assertEqual(A.__name__, 'C')
         with self.assertRaises(TypeError):



More information about the Python-checkins mailing list