(self)
| 319 | class TestNamedTuple(unittest.TestCase): |
| 320 | |
| 321 | def test_factory(self): |
| 322 | Point = namedtuple('Point', 'x y') |
| 323 | self.assertEqual(Point.__name__, 'Point') |
| 324 | self.assertEqual(Point.__slots__, ()) |
| 325 | self.assertEqual(Point.__module__, __name__) |
| 326 | self.assertEqual(Point.__getitem__, tuple.__getitem__) |
| 327 | self.assertEqual(Point._fields, ('x', 'y')) |
| 328 | |
| 329 | self.assertRaises(ValueError, namedtuple, 'abc%', 'efg ghi') # type has non-alpha char |
| 330 | self.assertRaises(ValueError, namedtuple, 'class', 'efg ghi') # type has keyword |
| 331 | self.assertRaises(ValueError, namedtuple, '9abc', 'efg ghi') # type starts with digit |
| 332 | |
| 333 | self.assertRaises(ValueError, namedtuple, 'abc', 'efg g%hi') # field with non-alpha char |
| 334 | self.assertRaises(ValueError, namedtuple, 'abc', 'abc class') # field has keyword |
| 335 | self.assertRaises(ValueError, namedtuple, 'abc', '8efg 9ghi') # field starts with digit |
| 336 | self.assertRaises(ValueError, namedtuple, 'abc', '_efg ghi') # field with leading underscore |
| 337 | self.assertRaises(ValueError, namedtuple, 'abc', 'efg efg ghi') # duplicate field |
| 338 | |
| 339 | namedtuple('Point0', 'x1 y2') # Verify that numbers are allowed in names |
| 340 | namedtuple('_', 'a b c') # Test leading underscores in a typename |
| 341 | |
| 342 | nt = namedtuple('nt', 'the quick brown fox') # check unicode input |
| 343 | self.assertNotIn("u'", repr(nt._fields)) |
| 344 | nt = namedtuple('nt', ('the', 'quick')) # check unicode input |
| 345 | self.assertNotIn("u'", repr(nt._fields)) |
| 346 | |
| 347 | self.assertRaises(TypeError, Point._make, [11]) # catch too few args |
| 348 | self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args |
| 349 | |
| 350 | def test_defaults(self): |
| 351 | Point = namedtuple('Point', 'x y', defaults=(10, 20)) # 2 defaults |
nothing calls this directly
no test coverage detected