Skip to content

Commit 12ce6ca

Browse files
committed
Add unit tests for TypeError messages
1 parent 33a38b3 commit 12ce6ca

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Lib/test/test_call.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,36 @@ def test_oldargs1_2_kw(self):
169169
msg = r"count\(\) takes no keyword arguments"
170170
self.assertRaisesRegex(TypeError, msg, [].count, x=2, y=2)
171171

172+
def test_argtype0(self):
173+
msg = r"^attribute name must be string, not 'int'$"
174+
self.assertRaisesRegex(TypeError, msg, getattr, 'foo', 123)
175+
176+
def test_argtype1(self):
177+
msg = r"^attribute name must be string, not 'int'$"
178+
self.assertRaisesRegex(TypeError, msg, hasattr, 'foo', 123)
179+
180+
def test_argtype2(self):
181+
msg = r"^attribute name must be string, not 'int'$"
182+
self.assertRaisesRegex(TypeError, msg, setattr, 'foo', 123, 'bar')
183+
184+
def test_argtype3(self):
185+
msg = r"^attribute name must be string, not 'int'$"
186+
self.assertRaisesRegex(TypeError, msg, delattr, 'foo', 123)
187+
188+
def test_argtype4(self):
189+
msg = r"^attribute name must be string, not 'int'$"
190+
with self.assertRaisesRegex(TypeError, msg):
191+
object.__getattribute__('foo', 123)
192+
193+
def test_argtype5(self):
194+
msg = r"^attribute name must be string, not 'int'$"
195+
with self.assertRaisesRegex(TypeError, msg):
196+
object.__setattr__('foo', 123, 'bar')
197+
198+
def test_argtype6(self):
199+
msg = r"^attribute name must be string, not 'int'$"
200+
with self.assertRaisesRegex(TypeError, msg):
201+
object.__delattr__('foo', 123)
172202

173203

174204
class TestCallingConventions(unittest.TestCase):

0 commit comments

Comments
 (0)