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

Method test_symbol_repr

Lib/test/test_symtable.py:492–529  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

490 self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
491
492 def test_symbol_repr(self):
493 self.assertEqual(repr(self.spam.lookup("glob")),
494 "<symbol 'glob': GLOBAL_IMPLICIT, USE>")
495 self.assertEqual(repr(self.spam.lookup("bar")),
496 "<symbol 'bar': GLOBAL_EXPLICIT, DEF_GLOBAL|DEF_LOCAL>")
497 self.assertEqual(repr(self.spam.lookup("a")),
498 "<symbol 'a': LOCAL, DEF_PARAM>")
499 self.assertEqual(repr(self.spam.lookup("internal")),
500 "<symbol 'internal': LOCAL, USE|DEF_LOCAL>")
501 self.assertEqual(repr(self.spam.lookup("other_internal")),
502 "<symbol 'other_internal': LOCAL, DEF_LOCAL>")
503 self.assertEqual(repr(self.internal.lookup("x")),
504 "<symbol 'x': FREE, USE>")
505 self.assertEqual(repr(self.other_internal.lookup("some_var")),
506 "<symbol 'some_var': FREE, USE|DEF_NONLOCAL|DEF_LOCAL>")
507 self.assertEqual(repr(self.GenericMine.lookup("T")),
508 "<symbol 'T': LOCAL, DEF_LOCAL|DEF_TYPE_PARAM>")
509
510 st1 = symtable.symtable("[x for x in [1]]", "?", "exec")
511 self.assertEqual(repr(st1.lookup("x")),
512 "<symbol 'x': LOCAL, USE|DEF_LOCAL|DEF_COMP_ITER>")
513
514 st2 = symtable.symtable("[(lambda: x) for x in [1]]", "?", "exec")
515 self.assertEqual(repr(st2.lookup("x")),
516 "<symbol 'x': CELL, DEF_LOCAL|DEF_COMP_ITER|DEF_COMP_CELL>")
517
518 st3 = symtable.symtable("def f():\n"
519 " x = 1\n"
520 " class A:\n"
521 " x = 2\n"
522 " def method():\n"
523 " return x\n",
524 "?", "exec")
525 # child 0 is for __annotate__
526 func_f = st3.get_children()[1]
527 class_A = func_f.get_children()[0]
528 self.assertEqual(repr(class_A.lookup('x')),
529 "<symbol 'x': LOCAL, DEF_LOCAL|DEF_FREE_CLASS>")
530
531 def test_symtable_entry_repr(self):
532 expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.45
lookupMethod · 0.45
get_childrenMethod · 0.45

Tested by

no test coverage detected