Commit 3f991867 authored by Michael Hanselmann's avatar Michael Hanselmann

Add simple unittest for hooks documentation

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarLuca Bigliardi <shammash@google.com>
parent 6c6b7f8a
......@@ -264,7 +264,8 @@ dist_TESTS = \
test/ganeti.serializer_unittest.py \
test/ganeti.ssh_unittest.py \
test/ganeti.utils_unittest.py \
test/ganeti.workerpool_unittest.py
test/ganeti.workerpool_unittest.py \
test/docs_unittest.py
nodist_TESTS =
......
#!/usr/bin/python
#
# Copyright (C) 2009 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Script for unittesting documentation"""
import unittest
import re
from ganeti import utils
from ganeti import cmdlib
import testutils
class TestDocs(unittest.TestCase):
"""Documentation tests"""
@staticmethod
def _ReadDocFile(filename):
return utils.ReadFile("%s/doc/%s" %
(testutils.GetSourceDir(), filename))
def testHookDocs(self):
"""Check whether all hooks are documented.
"""
hooksdoc = self._ReadDocFile("hooks.rst")
for name in dir(cmdlib):
obj = getattr(cmdlib, name)
if (isinstance(obj, type) and
issubclass(obj, cmdlib.LogicalUnit) and
hasattr(obj, "HPATH")):
self._CheckHook(name, obj, hooksdoc)
def _CheckHook(self, name, lucls, hooksdoc):
if lucls.HTYPE is None:
return
# TODO: Improve this test (e.g. find hooks documented but no longer
# existing)
pattern = r"^:directory:\s*%s\s*$" % re.escape(lucls.HPATH)
self.assert_(re.findall(pattern, hooksdoc, re.M),
msg=("Missing documentation for hook %s/%s" %
(lucls.HTYPE, lucls.HPATH)))
if __name__ == "__main__":
unittest.main()
......@@ -29,6 +29,10 @@ import unittest
from ganeti import utils
def GetSourceDir():
return os.environ.get("TOP_SRCDIR", ".")
class GanetiTestCase(unittest.TestCase):
"""Helper class for unittesting.
......@@ -83,8 +87,7 @@ class GanetiTestCase(unittest.TestCase):
be used in 'make distcheck' rules
"""
prefix = os.environ.get("TOP_SRCDIR", ".")
return "%s/test/data/%s" % (prefix, name)
return "%s/test/data/%s" % (GetSourceDir(), name)
@classmethod
def _ReadTestData(cls, name):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment