|
1 |
#!/usr/bin/python
|
|
2 |
#
|
|
3 |
|
|
4 |
# Copyright (C) 2009 Google Inc.
|
|
5 |
#
|
|
6 |
# This program is free software; you can redistribute it and/or modify
|
|
7 |
# it under the terms of the GNU General Public License as published by
|
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
|
9 |
# (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful, but
|
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 |
# General Public License for more details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
19 |
# 02110-1301, USA.
|
|
20 |
|
|
21 |
|
|
22 |
"""Script for unittesting documentation"""
|
|
23 |
|
|
24 |
import unittest
|
|
25 |
import re
|
|
26 |
|
|
27 |
from ganeti import utils
|
|
28 |
from ganeti import cmdlib
|
|
29 |
|
|
30 |
import testutils
|
|
31 |
|
|
32 |
|
|
33 |
class TestDocs(unittest.TestCase):
|
|
34 |
"""Documentation tests"""
|
|
35 |
|
|
36 |
@staticmethod
|
|
37 |
def _ReadDocFile(filename):
|
|
38 |
return utils.ReadFile("%s/doc/%s" %
|
|
39 |
(testutils.GetSourceDir(), filename))
|
|
40 |
|
|
41 |
def testHookDocs(self):
|
|
42 |
"""Check whether all hooks are documented.
|
|
43 |
|
|
44 |
"""
|
|
45 |
hooksdoc = self._ReadDocFile("hooks.rst")
|
|
46 |
|
|
47 |
for name in dir(cmdlib):
|
|
48 |
obj = getattr(cmdlib, name)
|
|
49 |
|
|
50 |
if (isinstance(obj, type) and
|
|
51 |
issubclass(obj, cmdlib.LogicalUnit) and
|
|
52 |
hasattr(obj, "HPATH")):
|
|
53 |
self._CheckHook(name, obj, hooksdoc)
|
|
54 |
|
|
55 |
def _CheckHook(self, name, lucls, hooksdoc):
|
|
56 |
if lucls.HTYPE is None:
|
|
57 |
return
|
|
58 |
|
|
59 |
# TODO: Improve this test (e.g. find hooks documented but no longer
|
|
60 |
# existing)
|
|
61 |
|
|
62 |
pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
|
|
63 |
|
|
64 |
self.assert_(re.findall(pattern, hooksdoc, re.M),
|
|
65 |
msg=("Missing documentation for hook %s/%s" %
|
|
66 |
(lucls.HTYPE, lucls.HPATH)))
|
|
67 |
|
|
68 |
|
|
69 |
if __name__ == "__main__":
|
|
70 |
unittest.main()
|