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

Method test_nested

Lib/test/test_pyclbr.py:181–240  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

179 self.checkModule('test.pyclbr_input', ignore=['om', 'f'])
180
181 def test_nested(self):
182 mb = pyclbr
183 # Set arguments for descriptor creation and _creat_tree call.
184 m, p, f, t, i = 'test', '', 'test.py', {}, None
185 source = dedent("""\
186 def f0():
187 def f1(a,b,c):
188 def f2(a=1, b=2, c=3): pass
189 return f1(a,b,d)
190 class c1: pass
191 class C0:
192 "Test class."
193 def F1():
194 "Method."
195 return 'return'
196 class C1():
197 class C2:
198 "Class nested within nested class."
199 def F3(): return 1+1
200
201 """)
202 actual = mb._create_tree(m, p, f, source, t, i)
203
204 # Create descriptors, linked together, and expected dict.
205 f0 = mb.Function(m, 'f0', f, 1, end_lineno=5)
206 f1 = mb._nest_function(f0, 'f1', 2, 4)
207 f2 = mb._nest_function(f1, 'f2', 3, 3)
208 c1 = mb._nest_class(f0, 'c1', 5, 5)
209 C0 = mb.Class(m, 'C0', None, f, 6, end_lineno=14)
210 F1 = mb._nest_function(C0, 'F1', 8, 10)
211 C1 = mb._nest_class(C0, 'C1', 11, 14)
212 C2 = mb._nest_class(C1, 'C2', 12, 14)
213 F3 = mb._nest_function(C2, 'F3', 14, 14)
214 expected = {'f0':f0, 'C0':C0}
215
216 def compare(parent1, children1, parent2, children2):
217 """Return equality of tree pairs.
218
219 Each parent,children pair define a tree. The parents are
220 assumed equal. Comparing the children dictionaries as such
221 does not work due to comparison by identity and double
222 linkage. We separate comparing string and number attributes
223 from comparing the children of input children.
224 """
225 self.assertEqual(children1.keys(), children2.keys())
226 for ob in children1.values():
227 self.assertIs(ob.parent, parent1)
228 for ob in children2.values():
229 self.assertIs(ob.parent, parent2)
230 for key in children1.keys():
231 o1, o2 = children1[key], children2[key]
232 t1 = type(o1), o1.name, o1.file, o1.module, o1.lineno, o1.end_lineno
233 t2 = type(o2), o2.name, o2.file, o2.module, o2.lineno, o2.end_lineno
234 self.assertEqual(t1, t2)
235 if type(o1) is mb.Class:
236 self.assertEqual(o1.methods, o2.methods)
237 # Skip superclasses for now as not part of example
238 compare(o1, o1.children, o2, o2.children)

Callers

nothing calls this directly

Calls 2

dedentFunction · 0.90
compareFunction · 0.85

Tested by

no test coverage detected