(self)
| 585 | self.assertEqual(p._fields, q._fields) |
| 586 | |
| 587 | def test_name_conflicts(self): |
| 588 | # Some names like "self", "cls", "tuple", "itemgetter", and "property" |
| 589 | # failed when used as field names. Test to make sure these now work. |
| 590 | T = namedtuple('T', 'itemgetter property self cls tuple') |
| 591 | t = T(1, 2, 3, 4, 5) |
| 592 | self.assertEqual(t, (1,2,3,4,5)) |
| 593 | newt = t._replace(itemgetter=10, property=20, self=30, cls=40, tuple=50) |
| 594 | self.assertEqual(newt, (10,20,30,40,50)) |
| 595 | |
| 596 | # Broader test of all interesting names taken from the code, old |
| 597 | # template, and an example |
| 598 | words = {'Alias', 'At', 'AttributeError', 'Build', 'Bypass', 'Create', |
| 599 | 'Encountered', 'Expected', 'Field', 'For', 'Got', 'Helper', |
| 600 | 'IronPython', 'Jython', 'KeyError', 'Make', 'Modify', 'Note', |
| 601 | 'OrderedDict', 'Point', 'Return', 'Returns', 'Type', 'TypeError', |
| 602 | 'Used', 'Validate', 'ValueError', 'Variables', 'a', 'accessible', 'add', |
| 603 | 'added', 'all', 'also', 'an', 'arg_list', 'args', 'arguments', |
| 604 | 'automatically', 'be', 'build', 'builtins', 'but', 'by', 'cannot', |
| 605 | 'class_namespace', 'classmethod', 'cls', 'collections', 'convert', |
| 606 | 'copy', 'created', 'creation', 'd', 'debugging', 'defined', 'dict', |
| 607 | 'dictionary', 'doc', 'docstring', 'docstrings', 'duplicate', 'effect', |
| 608 | 'either', 'enumerate', 'environments', 'error', 'example', 'exec', 'f', |
| 609 | 'f_globals', 'field', 'field_names', 'fields', 'formatted', 'frame', |
| 610 | 'function', 'functions', 'generate', 'get', 'getter', 'got', 'greater', |
| 611 | 'has', 'help', 'identifiers', 'index', 'indexable', 'instance', |
| 612 | 'instantiate', 'interning', 'introspection', 'isidentifier', |
| 613 | 'isinstance', 'itemgetter', 'iterable', 'join', 'keyword', 'keywords', |
| 614 | 'kwds', 'len', 'like', 'list', 'map', 'maps', 'message', 'metadata', |
| 615 | 'method', 'methods', 'module', 'module_name', 'must', 'name', 'named', |
| 616 | 'namedtuple', 'namedtuple_', 'names', 'namespace', 'needs', 'new', |
| 617 | 'nicely', 'num_fields', 'number', 'object', 'of', 'operator', 'option', |
| 618 | 'p', 'particular', 'pickle', 'pickling', 'plain', 'pop', 'positional', |
| 619 | 'property', 'r', 'regular', 'rename', 'replace', 'replacing', 'repr', |
| 620 | 'repr_fmt', 'representation', 'result', 'reuse_itemgetter', 's', 'seen', |
| 621 | 'self', 'sequence', 'set', 'side', 'specified', 'split', 'start', |
| 622 | 'startswith', 'step', 'str', 'string', 'strings', 'subclass', 'sys', |
| 623 | 'targets', 'than', 'the', 'their', 'this', 'to', 'tuple', 'tuple_new', |
| 624 | 'type', 'typename', 'underscore', 'unexpected', 'unpack', 'up', 'use', |
| 625 | 'used', 'user', 'valid', 'values', 'variable', 'verbose', 'where', |
| 626 | 'which', 'work', 'x', 'y', 'z', 'zip'} |
| 627 | T = namedtuple('T', words) |
| 628 | # test __new__ |
| 629 | values = tuple(range(len(words))) |
| 630 | t = T(*values) |
| 631 | self.assertEqual(t, values) |
| 632 | t = T(**dict(zip(T._fields, values))) |
| 633 | self.assertEqual(t, values) |
| 634 | # test _make |
| 635 | t = T._make(values) |
| 636 | self.assertEqual(t, values) |
| 637 | # exercise __repr__ |
| 638 | repr(t) |
| 639 | # test _asdict |
| 640 | self.assertEqual(t._asdict(), dict(zip(T._fields, values))) |
| 641 | # test _replace |
| 642 | t = T._make(values) |
| 643 | newvalues = tuple(v*10 for v in values) |
| 644 | newt = t._replace(**dict(zip(T._fields, newvalues))) |
nothing calls this directly
no test coverage detected