MCPcopy Index your code
hub / github.com/python/cpython / test_keywords

Method test_keywords

Lib/test/test_descr.py:3194–3219  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3192 ## os_helper.unlink(os_helper.TESTFN)
3193
3194 def test_keywords(self):
3195 # Testing keyword args to basic type constructors ...
3196 with self.assertRaisesRegex(TypeError, 'keyword argument'):
3197 int(x=1)
3198 with self.assertRaisesRegex(TypeError, 'keyword argument'):
3199 float(x=2)
3200 with self.assertRaisesRegex(TypeError, 'keyword argument'):
3201 bool(x=2)
3202 self.assertEqual(complex(imag=42, real=666), complex(666, 42))
3203 self.assertEqual(str(object=500), '500')
3204 self.assertEqual(str(object=b'abc', errors='strict'), 'abc')
3205 with self.assertRaisesRegex(TypeError, 'keyword argument'):
3206 tuple(sequence=range(3))
3207 with self.assertRaisesRegex(TypeError, 'keyword argument'):
3208 list(sequence=(0, 1, 2))
3209 # note: as of Python 2.3, dict() no longer has an "items" keyword arg
3210
3211 for constructor in (int, float, int, complex, str, str,
3212 tuple, list):
3213 try:
3214 constructor(bogus_keyword_arg=1)
3215 except TypeError:
3216 pass
3217 else:
3218 self.fail("expected TypeError from bogus keyword argument to %r"
3219 % constructor)
3220
3221 def test_str_subclass_as_dict_key(self):
3222 # Testing a str subclass used as dict key ..

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
listClass · 0.85
constructorFunction · 0.85
assertRaisesRegexMethod · 0.80
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected