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

Method test_empty_namedtuple

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

Source from the content-addressed store, hash-verified

8345 self.assertEqual(a, (1, [2]))
8346
8347 def test_empty_namedtuple(self):
8348 with self.assertRaisesRegex(TypeError, "missing.*required.*argument"):
8349 BAD = NamedTuple('BAD')
8350
8351 NT1 = NamedTuple('NT1', {})
8352 NT2 = NamedTuple('NT2', ())
8353 NT3 = NamedTuple('NT3', [])
8354
8355 class CNT(NamedTuple):
8356 pass # empty body
8357
8358 for struct in NT1, NT2, NT3, CNT:
8359 with self.subTest(struct=struct):
8360 self.assertEqual(struct._fields, ())
8361 self.assertEqual(struct._field_defaults, {})
8362 self.assertEqual(struct.__annotations__, {})
8363 self.assertIsInstance(struct(), struct)
8364
8365 def test_namedtuple_errors(self):
8366 with self.assertRaises(TypeError):

Callers

nothing calls this directly

Calls 5

NamedTupleFunction · 0.90
assertRaisesRegexMethod · 0.80
assertIsInstanceMethod · 0.80
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected