• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Run the python doc generator and fail if there are any broken links."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
21import os
22import textwrap
23
24import tensorflow as tf
25from tensorflow.python import debug as tf_debug
26from tensorflow.python.platform import googletest
27from tensorflow.python.platform import resource_loader
28from tensorflow.tools.docs import generate_lib
29
30
31class Flags(object):
32  resource_root = resource_loader.get_root_dir_with_all_resources()
33  src_dir = os.path.join(googletest.GetTempDir(), 'input')
34  os.mkdir(src_dir)
35  base_dir = os.path.join(resource_root, 'tensorflow/')
36  output_dir = os.path.join(googletest.GetTempDir(), 'output')
37  os.mkdir(output_dir)
38
39
40class BuildDocsTest(googletest.TestCase):
41
42  def testBuildDocs(self):
43    doc_generator = generate_lib.DocGenerator()
44
45    doc_generator.set_py_modules([('tf', tf), ('tfdbg', tf_debug)])
46
47    try:
48      status = doc_generator.build(Flags())
49    except RuntimeError as e:
50      if not e.args[0].startswith('Modules nested too deep'):
51        raise
52
53      msg = textwrap.dedent("""\
54          %s
55
56          ****************************************************************
57          If this test fails here, you have most likely introduced an
58          unsealed module. Make sure to use `remove_undocumented` or similar
59          utilities to avoid leaking symbols. See above for more information
60          on the exact point of failure.
61          ****************************************************************
62          """ % e.args[0])
63
64      raise RuntimeError(msg)
65
66    if status:
67      self.fail('Found %s Errors!' % status)
68
69
70if __name__ == '__main__':
71  googletest.main()
72