Revision 3f991867

b/Makefile.am
264 264
	test/ganeti.serializer_unittest.py \
265 265
	test/ganeti.ssh_unittest.py \
266 266
	test/ganeti.utils_unittest.py \
267
	test/ganeti.workerpool_unittest.py
267
	test/ganeti.workerpool_unittest.py \
268
	test/docs_unittest.py
268 269

  
269 270
nodist_TESTS =
270 271

  
b/test/docs_unittest.py
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()
b/test/testutils.py
29 29
from ganeti import utils
30 30

  
31 31

  
32
def GetSourceDir():
33
  return os.environ.get("TOP_SRCDIR", ".")
34

  
35

  
32 36
class GanetiTestCase(unittest.TestCase):
33 37
  """Helper class for unittesting.
34 38

  
......
83 87
        be used in 'make distcheck' rules
84 88

  
85 89
    """
86
    prefix = os.environ.get("TOP_SRCDIR", ".")
87
    return "%s/test/data/%s" % (prefix, name)
90
    return "%s/test/data/%s" % (GetSourceDir(), name)
88 91

  
89 92
  @classmethod
90 93
  def _ReadTestData(cls, name):

Also available in: Unified diff