Exemple #1
0
    def test_write(self):
        _, parser_config = self.get_test_objects()

        output_dir = self.workdir

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

        # 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'
        ])

        toc_file = os.path.join(output_dir, '_toc.yaml')
        self.assertTrue(os.path.exists(toc_file))
        with open(toc_file) as f:
            toc = f.read()
        toc_list = toc.split()

        # Number of sections in the toc should be 2.
        self.assertEqual(toc_list.count('section:'), 2)

        # TOC should always begin with `toc:`
        self.assertEqual(toc_list[0], 'toc:')

        # The last path in the TOC must be the ground truth below.
        # This will check if the symbols are being sorted in case-insensitive
        # alphabetical order too, spanning across submodules and children.
        self.assertEqual(toc_list[-1],
                         '/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')))
Exemple #2
0
    def test_write(self):
        _, parser_config = self.get_test_objects()

        output_dir = pathlib.Path(self.workdir)

        generate_lib.write_docs(output_dir=output_dir,
                                parser_config=parser_config,
                                root_module_name='tf',
                                yaml_toc=True)

        # Check redirects
        redirects_file = output_dir / 'tf/_redirects.yaml'
        self.assertTrue(redirects_file.exists())
        redirects = yaml.safe_load(redirects_file.read_text())
        self.assertEqual(
            redirects, {
                'redirects':
                [{
                    'from': '/api_docs/python/tf/test_function',
                    'to': '/api_docs/python/tf/TestModule/test_function'
                }, {
                    'from': '/api_docs/python/tf_overview',
                    'to': '/api_docs/python/tf'
                }]
            })

        toc_file = output_dir / 'tf/_toc.yaml'
        self.assertTrue(toc_file.exists())
        toc_list = yaml.safe_load(toc_file.read_text())['toc']

        # Number of sections in the toc should be 2.
        self.assertLen([item for item in toc_list if 'section' in item], 2)

        # The last path in the TOC must be the ground truth below.
        # This will check if the symbols are being sorted in case-insensitive
        # alphabetical order too, spanning across submodules and children.
        test_function_toc = toc_list[1]['section'][-1]
        self.assertEqual(test_function_toc['path'],
                         '/api_docs/python/tf/TestModule/test_function')
        self.assertEqual(test_function_toc['status'], 'deprecated')

        # Make sure that the right files are written to disk.
        self.assertTrue((output_dir / 'tf/all_symbols.md').exists())
        self.assertTrue((output_dir / 'tf.md').exists())
        self.assertTrue((output_dir / 'tf/TestModule.md').exists())
        self.assertFalse((output_dir / 'tf/test_function.md').exists())
        self.assertTrue((output_dir / 'tf/TestModule/TestClass.md').exists())
        self.assertTrue(
            (output_dir / 'tf/TestModule/TestClass/ChildClass.md').exists())
        self.assertTrue(
            (output_dir /
             'tf/TestModule/TestClass/ChildClass/GrandChildClass.md').exists())
        # Make sure that duplicates are not written
        self.assertTrue(
            (output_dir / 'tf/TestModule/test_function.md').exists())
Exemple #3
0
    def test_write(self):
        _, parser_config = self.get_test_objects()

        output_dir = self.workdir

        generate_lib.write_docs(output_dir,
                                parser_config,
                                yaml_toc=True,
                                site_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')))
Exemple #4
0
  def test_write(self):
    _, parser_config = self.get_test_objects()

    output_dir = self.workdir

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

    # 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')))