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

Method test_visitor

Lib/test/test_asdl_parser.py:102–127  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

100 self.assertTrue(f2.seq)
101
102 def test_visitor(self):
103 class CustomVisitor(self.asdl.VisitorBase):
104 def __init__(self):
105 super().__init__()
106 self.names_with_seq = []
107
108 def visitModule(self, mod):
109 for dfn in mod.dfns:
110 self.visit(dfn)
111
112 def visitType(self, type):
113 self.visit(type.value)
114
115 def visitSum(self, sum):
116 for t in sum.types:
117 self.visit(t)
118
119 def visitConstructor(self, cons):
120 for f in cons.fields:
121 if f.seq:
122 self.names_with_seq.append(cons.name)
123
124 v = CustomVisitor()
125 v.visit(self.types['mod'])
126 self.assertEqual(v.names_with_seq,
127 ['Module', 'Module', 'Interactive', 'FunctionType'])
128
129
130if __name__ == '__main__':

Callers

nothing calls this directly

Calls 3

CustomVisitorClass · 0.85
visitMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected