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

Method test_namedtuple_errors

Lib/test/test_typing.py:8365–8405  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

8363 self.assertIsInstance(struct(), struct)
8364
8365 def test_namedtuple_errors(self):
8366 with self.assertRaises(TypeError):
8367 NamedTuple.__new__()
8368 with self.assertRaisesRegex(TypeError, "object is not iterable"):
8369 NamedTuple('Name', None)
8370
8371 with self.assertRaisesRegex(
8372 TypeError,
8373 "missing 2 required positional arguments"
8374 ):
8375 NamedTuple()
8376
8377 with self.assertRaisesRegex(
8378 TypeError,
8379 "takes 2 positional arguments but 3 were given"
8380 ):
8381 NamedTuple('Emp', [('name', str)], None)
8382
8383 with self.assertRaisesRegex(
8384 ValueError,
8385 "Field names cannot start with an underscore"
8386 ):
8387 NamedTuple('Emp', [('_name', str)])
8388
8389 with self.assertRaisesRegex(
8390 TypeError,
8391 "got some positional-only arguments passed as keyword arguments"
8392 ):
8393 NamedTuple(typename='Emp', name=str, id=int)
8394
8395 with self.assertRaisesRegex(
8396 TypeError,
8397 "got an unexpected keyword argument"
8398 ):
8399 NamedTuple('Name', [('x', int)], y=str)
8400
8401 with self.assertRaisesRegex(
8402 TypeError,
8403 "got an unexpected keyword argument"
8404 ):
8405 NamedTuple('Name', [], y=str)
8406
8407 def test_copy_and_pickle(self):
8408 global Emp # pickle wants to reference the class by name

Callers

nothing calls this directly

Calls 4

NamedTupleFunction · 0.90
assertRaisesRegexMethod · 0.80
assertRaisesMethod · 0.45
__new__Method · 0.45

Tested by

no test coverage detected