+ uri_dups = utils.FindDuplicates(used_uris)
+ self.failIf(uri_dups,
+ msg=("URIs matched by more than one resource: %s" %
+ utils.CommaJoin(uri_dups)))
+
+ self._FindRapiMissing(resources.values())
+ self._CheckTagHandlers(resources.values())
+
+ def _FindRapiMissing(self, handlers):
+ used = frozenset(itertools.chain(*map(baserlib.GetResourceOpcodes,
+ handlers)))
+
+ unexpected = used & RAPI_OPCODE_EXCLUDE
+ self.assertFalse(unexpected,
+ msg=("Found RAPI resources for excluded opcodes: %s" %
+ utils.CommaJoin(_GetOpIds(unexpected))))
+
+ missing = (frozenset(opcodes.OP_MAPPING.values()) - used -
+ RAPI_OPCODE_EXCLUDE)
+ self.assertFalse(missing,
+ msg=("Missing RAPI resources for opcodes: %s" %
+ utils.CommaJoin(_GetOpIds(missing))))
+
+ def _CheckTagHandlers(self, handlers):
+ tag_handlers = filter(lambda x: issubclass(x, rlib2._R_Tags), handlers)
+ self.assertEqual(frozenset(map(operator.attrgetter("TAG_LEVEL"),
+ tag_handlers)),
+ constants.VALID_TAG_TYPES)
+
+
+def _GetOpIds(ops):
+ """Returns C{OP_ID} for all opcodes in passed sequence.
+
+ """
+ return sorted(opcls.OP_ID for opcls in ops)
+
+
+class TestManpages(unittest.TestCase):
+ """Manpage tests"""
+
+ @staticmethod
+ def _ReadManFile(name):
+ return utils.ReadFile("%s/man/%s.rst" %
+ (testutils.GetSourceDir(), name))
+
+ @staticmethod
+ def _LoadScript(name):
+ return build.LoadModule("scripts/%s" % name)
+
+ def test(self):
+ for script in _autoconf.GNT_SCRIPTS:
+ self._CheckManpage(script,
+ self._ReadManFile(script),
+ self._LoadScript(script).commands.keys())
+
+ def _CheckManpage(self, script, mantext, commands):
+ missing = []
+
+ for cmd in commands:
+ pattern = r"^(\| )?\*\*%s\*\*" % re.escape(cmd)
+ if not re.findall(pattern, mantext, re.DOTALL | re.MULTILINE):
+ missing.append(cmd)
+
+ self.failIf(missing,
+ msg=("Manpage for '%s' missing documentation for %s" %
+ (script, utils.CommaJoin(missing))))
+