Ejemplo n.º 1
0
 def test_private_child_removal(self):
     visitor = self.TestVisitor()
     children = [('name1', 'thing1'), ('_name2', 'thing2')]
     public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
     # Make sure the private symbols are removed before the visitor is called.
     self.assertEqual([('name1', 'thing1')], visitor.last_children)
     self.assertEqual([('name1', 'thing1')], children)
Ejemplo n.º 2
0
 def test_call_forward(self):
     visitor = self.TestVisitor()
     children = [('name1', 'thing1'), ('name2', 'thing2')]
     public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
     self.assertEqual(set(['test']), visitor.symbols)
     self.assertEqual('dummy', visitor.last_parent)
     self.assertEqual([('name1', 'thing1'), ('name2', 'thing2')],
                      visitor.last_children)
Ejemplo n.º 3
0
 def test_no_descent_child_removal(self):
     visitor = self.TestVisitor()
     children = [('name1', 'thing1'), ('mock', 'thing2')]
     public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
     # Make sure not-to-be-descended-into symbols are removed after the visitor
     # is called.
     self.assertEqual([('name1', 'thing1'), ('mock', 'thing2')],
                      visitor.last_children)
     self.assertEqual([('name1', 'thing1')], children)
Ejemplo n.º 4
0
    def test_no_descent_child_removal(self):
        visitor = self.TestVisitor()
        children = [('name1', 'thing1'), ('name2', 'thing2')]

        api_visitor = public_api.PublicAPIVisitor(
            visitor, base_dir='/', do_not_descend_map={'tf.test': ['mock']})

        api_visitor(('tf', 'test', 'mock'), 'dummy', children)

        # Make sure not-to-be-descended-into symbols's children are removed.
        self.assertEqual([], visitor.last_children)
        self.assertEqual([], children)
Ejemplo n.º 5
0
    def test_private_map_child_removal(self):
        visitor = self.TestVisitor()
        children = [('name1', 'thing1'), ('mock', 'thing2')]

        api_visitor = public_api.PublicAPIVisitor(
            visitor, base_dir='/', private_map={'tf.test': ['mock']})

        api_visitor((
            'tf',
            'test',
        ), 'dummy', children)
        # Make sure private aliases are removed.
        self.assertEqual([('name1', 'thing1')], visitor.last_children)
        self.assertEqual([('name1', 'thing1')], children)
Ejemplo n.º 6
0
def extract(py_modules,
            base_dir,
            private_map,
            do_not_descend_map,
            visitor_cls=doc_generator_visitor.DocGeneratorVisitor):
    """Extract docs from tf namespace and write them to disk."""
    # Traverse the first module.
    if len(py_modules) != 1:
        raise ValueError("only pass one [('name',module)] pair in py_modules")
    short_name, py_module = py_modules[0]
    visitor = visitor_cls()
    api_visitor = public_api.PublicAPIVisitor(visitor, base_dir, private_map,
                                              do_not_descend_map)

    traverse.traverse(py_module, api_visitor, short_name)

    return visitor
Ejemplo n.º 7
0
    def test_call_forward(self):
        visitor = self.TestVisitor()
        children = [('name1', 'thing1'), ('name2', 'thing2')]

        api_visitor = public_api.PublicAPIVisitor(visitor, base_dir='/')
        api_visitor((
            'tf',
            'test',
        ), 'dummy', children)

        self.assertEqual(set([(
            'tf',
            'test',
        )]), visitor.symbols)
        self.assertEqual('dummy', visitor.last_parent)
        self.assertEqual([('name1', 'thing1'), ('name2', 'thing2')],
                         visitor.last_children)