def test_write(self):
    _, parser_config = self.get_test_objects()

    output_dir = googletest.GetTempDir()

    generate_lib.write_docs(output_dir, parser_config, yaml_toc=True)

    # Make sure that the right files are written to disk.
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
    self.assertTrue(
        os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
    self.assertFalse(
        os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir,
                         'tf/TestModule/TestClass/ChildClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(
                output_dir,
                'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
    # Make sure that duplicates are not written
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/test_function.md')))
Beispiel #2
0
    def test_write(self):
        _, parser_config = self.get_test_objects()

        output_dir = googletest.GetTempDir()

        generate_lib.write_docs(output_dir, parser_config, yaml_toc=True)

        # Make sure that the right files are written to disk.
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
        self.assertTrue(
            os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
        self.assertFalse(
            os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir,
                             'tf/TestModule/TestClass/ChildClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    output_dir,
                    'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
        # Make sure that duplicates are not written
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/test_function.md')))
  def test_write(self):
    module = sys.modules[__name__]

    index = {
        'tf': sys,  # Can be any module, this test doesn't care about content.
        'tf.TestModule': module,
        'tf.test_function': test_function,
        'tf.TestModule.test_function': test_function,
        'tf.TestModule.TestClass': TestClass,
        'tf.TestModule.TestClass.ChildClass': TestClass.ChildClass,
        'tf.TestModule.TestClass.ChildClass.GrandChildClass':
        TestClass.ChildClass.GrandChildClass,
    }

    tree = {
        'tf': ['TestModule', 'test_function'],
        'tf.TestModule': ['test_function', 'TestClass'],
        'tf.TestModule.TestClass': ['ChildClass'],
        'tf.TestModule.TestClass.ChildClass': ['GrandChildClass'],
        'tf.TestModule.TestClass.ChildClass.GrandChildClass': []
    }

    duplicate_of = {
        'tf.TestModule.test_function': 'tf.test_function'
    }

    duplicates = {
        'tf.test_function': ['tf.test_function', 'tf.TestModule.test_function']
    }

    output_dir = tempfile.mkdtemp()
    base_dir = os.path.dirname(__file__)

    reference_resolver = parser.ReferenceResolver(
        duplicate_of=duplicate_of,
        doc_index={}, index=index, py_module_names=['tf'])
    parser_config = parser.ParserConfig(
        reference_resolver=reference_resolver, duplicates=duplicates, tree=tree,
        reverse_index={}, guide_index={}, base_dir=base_dir)
    generate_lib.write_docs(output_dir, parser_config, duplicate_of, index,
                            yaml_toc=True)

    # Make sure that the right files are written to disk.
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
    self.assertTrue(os.path.exists(os.path.join(
        output_dir, 'tf/TestModule.md')))
    self.assertTrue(os.path.exists(os.path.join(
        output_dir, 'tf/test_function.md')))
    self.assertTrue(os.path.exists(os.path.join(
        output_dir, 'tf/TestModule/TestClass.md')))
    self.assertTrue(os.path.exists(os.path.join(
        output_dir, 'tf/TestModule/TestClass/ChildClass.md')))
    self.assertTrue(os.path.exists(os.path.join(
        output_dir, 'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
    # Make sure that duplicates are not written
    self.assertFalse(os.path.exists(os.path.join(
        output_dir, 'tf/TestModule/test_function.md')))
Beispiel #4
0
  def test_write(self):
    _, parser_config = self.get_test_objects()

    output_dir = googletest.GetTempDir()

    generate_lib.write_docs(output_dir, parser_config, yaml_toc=True,
                            site_api_path='api_docs/python')

    # Check redirects
    redirects_file = os.path.join(output_dir, '_redirects.yaml')
    self.assertTrue(os.path.exists(redirects_file))
    with open(redirects_file) as f:
      redirects = f.read()
    self.assertEqual(redirects.split(), [
        'redirects:', '-', 'from:', '/api_docs/python/tf/test_function', 'to:',
        '/api_docs/python/tf/TestModule/test_function'
    ])

    # Make sure that the right files are written to disk.
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
    self.assertTrue(
        os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
    self.assertFalse(
        os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir,
                         'tf/TestModule/TestClass/ChildClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(
                output_dir,
                'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
    # Make sure that duplicates are not written
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/test_function.md')))
Beispiel #5
0
    def test_write(self):
        module = sys.modules[__name__]

        index = {
            'tf':
            sys,  # Can be any module, this test doesn't care about content.
            'tf.TestModule':
            module,
            'tf.test_function':
            test_function,
            'tf.TestModule.test_function':
            test_function,
            'tf.TestModule.TestClass':
            TestClass,
            'tf.TestModule.TestClass.ChildClass':
            TestClass.ChildClass,
            'tf.TestModule.TestClass.ChildClass.GrandChildClass':
            TestClass.ChildClass.GrandChildClass,
        }

        tree = {
            'tf': ['TestModule', 'test_function'],
            'tf.TestModule': ['test_function', 'TestClass'],
            'tf.TestModule.TestClass': ['ChildClass'],
            'tf.TestModule.TestClass.ChildClass': ['GrandChildClass'],
            'tf.TestModule.TestClass.ChildClass.GrandChildClass': []
        }

        duplicate_of = {'tf.TestModule.test_function': 'tf.test_function'}

        duplicates = {
            'tf.test_function':
            ['tf.test_function', 'tf.TestModule.test_function']
        }

        output_dir = tempfile.mkdtemp()
        base_dir = os.path.dirname(__file__)

        reference_resolver = parser.ReferenceResolver(
            duplicate_of=duplicate_of,
            doc_index={},
            index=index,
            py_module_names=['tf'])
        parser_config = parser.ParserConfig(
            reference_resolver=reference_resolver,
            duplicates=duplicates,
            tree=tree,
            reverse_index={},
            guide_index={},
            base_dir=base_dir)
        generate_lib.write_docs(output_dir,
                                parser_config,
                                duplicate_of,
                                index,
                                yaml_toc=True)

        # Make sure that the right files are written to disk.
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
        self.assertTrue(
            os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
        self.assertTrue(
            os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir,
                             'tf/TestModule/TestClass/ChildClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    output_dir,
                    'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
        # Make sure that duplicates are not written
        self.assertFalse(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/test_function.md')))
  def test_write(self):
    if sys.version_info >= (3, 0):
      self.skipTest('Warning: Doc generation is not supported from python3.')

    module = sys.modules[__name__]

    index = {
        'tf': sys,  # Can be any module, this test doesn't care about content.
        'tf.TestModule': module,
        'tf.test_function': test_function,
        'tf.TestModule.test_function': test_function,
        'tf.TestModule.TestClass': TestClass,
        'tf.TestModule.TestClass.ChildClass': TestClass.ChildClass,
        'tf.TestModule.TestClass.ChildClass.GrandChildClass':
        TestClass.ChildClass.GrandChildClass,
    }

    tree = {
        'tf': ['TestModule', 'test_function'],
        'tf.TestModule': ['test_function', 'TestClass'],
        'tf.TestModule.TestClass': ['ChildClass'],
        'tf.TestModule.TestClass.ChildClass': ['GrandChildClass'],
        'tf.TestModule.TestClass.ChildClass.GrandChildClass': []
    }

    duplicate_of = {'tf.test_function': 'tf.TestModule.test_function'}

    duplicates = {
        'tf.TestModule.test_function': [
            'tf.test_function', 'tf.TestModule.test_function'
        ]
    }

    base_dir = os.path.dirname(__file__)

    visitor = DummyVisitor(index, duplicate_of)

    reference_resolver = parser.ReferenceResolver.from_visitor(
        visitor=visitor, doc_index={}, py_module_names=['tf'])

    parser_config = parser.ParserConfig(
        reference_resolver=reference_resolver,
        duplicates=duplicates,
        duplicate_of=duplicate_of,
        tree=tree,
        index=index,
        reverse_index={},
        guide_index={},
        base_dir=base_dir)

    output_dir = googletest.GetTempDir()

    generate_lib.write_docs(output_dir, parser_config, yaml_toc=True)

    # Make sure that the right files are written to disk.
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
    self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
    self.assertTrue(
        os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
    self.assertFalse(
        os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir,
                         'tf/TestModule/TestClass/ChildClass.md')))
    self.assertTrue(
        os.path.exists(
            os.path.join(
                output_dir,
                'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
    # Make sure that duplicates are not written
    self.assertTrue(
        os.path.exists(
            os.path.join(output_dir, 'tf/TestModule/test_function.md')))
    def test_write(self):
        if sys.version_info >= (3, 0):
            self.skipTest(
                'Warning: Doc generation is not supported from python3.')

        module = sys.modules[__name__]

        index = {
            'tf':
            sys,  # Can be any module, this test doesn't care about content.
            'tf.TestModule':
            module,
            'tf.test_function':
            test_function,
            'tf.TestModule.test_function':
            test_function,
            'tf.TestModule.TestClass':
            TestClass,
            'tf.TestModule.TestClass.ChildClass':
            TestClass.ChildClass,
            'tf.TestModule.TestClass.ChildClass.GrandChildClass':
            TestClass.ChildClass.GrandChildClass,
        }

        tree = {
            'tf': ['TestModule', 'test_function'],
            'tf.TestModule': ['test_function', 'TestClass'],
            'tf.TestModule.TestClass': ['ChildClass'],
            'tf.TestModule.TestClass.ChildClass': ['GrandChildClass'],
            'tf.TestModule.TestClass.ChildClass.GrandChildClass': []
        }

        duplicate_of = {'tf.test_function': 'tf.TestModule.test_function'}

        duplicates = {
            'tf.TestModule.test_function':
            ['tf.test_function', 'tf.TestModule.test_function']
        }

        base_dir = os.path.dirname(__file__)

        visitor = DummyVisitor(index, duplicate_of)

        reference_resolver = parser.ReferenceResolver.from_visitor(
            visitor=visitor, doc_index={}, py_module_names=['tf'])

        parser_config = parser.ParserConfig(
            reference_resolver=reference_resolver,
            duplicates=duplicates,
            duplicate_of=duplicate_of,
            tree=tree,
            index=index,
            reverse_index={},
            guide_index={},
            base_dir=base_dir)

        output_dir = googletest.GetTempDir()

        generate_lib.write_docs(output_dir, parser_config, yaml_toc=True)

        # Make sure that the right files are written to disk.
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'index.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, 'tf.md')))
        self.assertTrue(os.path.exists(os.path.join(output_dir, '_toc.yaml')))
        self.assertTrue(
            os.path.exists(os.path.join(output_dir, 'tf/TestModule.md')))
        self.assertFalse(
            os.path.exists(os.path.join(output_dir, 'tf/test_function.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/TestClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir,
                             'tf/TestModule/TestClass/ChildClass.md')))
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    output_dir,
                    'tf/TestModule/TestClass/ChildClass/GrandChildClass.md')))
        # Make sure that duplicates are not written
        self.assertTrue(
            os.path.exists(
                os.path.join(output_dir, 'tf/TestModule/test_function.md')))