MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_name_conflicts

Method test_name_conflicts

Lib/test/test_collections.py:586–648  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

namedtupleFunction · 0.90
lenFunction · 0.85
reprFunction · 0.85
_makeMethod · 0.80
TClass · 0.70
assertEqualMethod · 0.45
__getnewargs__Method · 0.45

Tested by

no test coverage detected