Exemplo n.º 1
0
 def test_transform_children(self):
     eq = self.assertEqual
     # Parameter matches tree module.
     tcl = list(browser.transform_children(mock_pyclbr_tree, 'test'))
     eq(tcl[0], f0)
     eq(tcl[1], C0)
     eq(tcl[1].name, 'C0(base)')
     # Check that second call does not add second '(base)' suffix.
     tcl = list(browser.transform_children(mock_pyclbr_tree, 'test'))
     eq(tcl[1].name, 'C0(base)')
     # Nothing to traverse if parameter name isn't same as tree module.
     tn = browser.transform_children(mock_pyclbr_tree, 'different name')
     self.assertEqual(list(tn), [])
     # No name parameter.
     tn = browser.transform_children({'f1': f1, 'c1': c1})
     self.assertEqual(list(tn), [f1, c1])
Exemplo n.º 2
0
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
mb = pyclbr
module, fname = 'test', 'test.py'
C0 = mb.Class(module, 'C0', ['base'], fname, 1)
F1 = mb._nest_function(C0, 'F1', 3)
C1 = mb._nest_class(C0, 'C1', 6, [''])
C2 = mb._nest_class(C1, 'C2', 7)
F3 = mb._nest_function(C2, 'F3', 9)
f0 = mb.Function(module, 'f0', fname, 11)
f1 = mb._nest_function(f0, 'f1', 12)
f2 = mb._nest_function(f1, 'f2', 13)
c1 = mb._nest_class(f0, 'c1', 15)
mock_pyclbr_tree = {'C0': C0, 'f0': f0}

# Adjust C0.name, C1.name so tests do not depend on order.
browser.transform_children(mock_pyclbr_tree, 'test')  # C0(base)
browser.transform_children(C0.children)  # C1()

# The class below checks that the calls above are correct
# and that duplicate calls have no effect.


class TransformChildrenTest(unittest.TestCase):
    def test_transform_module_children(self):
        eq = self.assertEqual
        transform = browser.transform_children
        # Parameter matches tree module.
        tcl = list(transform(mock_pyclbr_tree, 'test'))
        eq(tcl, [C0, f0])
        eq(tcl[0].name, 'C0(base)')
        eq(tcl[1].name, 'f0')
Exemplo n.º 3
0
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
mb = pyclbr
module, fname = 'test', 'test.py'
f0 = mb.Function(module, 'f0', fname, 1)
f1 = mb._nest_function(f0, 'f1', 2)
f2 = mb._nest_function(f1, 'f2', 3)
c1 = mb._nest_class(f0, 'c1', 5)
C0 = mb.Class(module, 'C0', ['base'], fname, 6)
F1 = mb._nest_function(C0, 'F1', 8)
C1 = mb._nest_class(C0, 'C1', 11, [''])
C2 = mb._nest_class(C1, 'C2', 12)
F3 = mb._nest_function(C2, 'F3', 14)
mock_pyclbr_tree = {'f0': f0, 'C0': C0}

# Adjust C0.name, C1.name so tests do not depend on order.
browser.transform_children(mock_pyclbr_tree, 'test')  # C0(base)
browser.transform_children(C0.children)  # C1()

# The class below checks that the calls above are correct
# and that duplicate calls have no effect.


class TransformChildrenTest(unittest.TestCase):

    def test_transform_module_children(self):
        eq = self.assertEqual
        transform = browser.transform_children
        # Parameter matches tree module.
        tcl = list(transform(mock_pyclbr_tree, 'test'))
        eq(tcl, [f0, C0])
        eq(tcl[0].name, 'f0')