Switch man pages from SGML to RST
[ganeti-local] / test / docs_unittest.py
index 6e66748..5be823b 100755 (executable)
@@ -92,11 +92,16 @@ class TestDocs(unittest.TestCase):
 
       prevline = line
 
+    prefix_exception = frozenset(["/", "/version", "/2"])
+
     undocumented = []
 
     for key, handler in resources.iteritems():
       # Regex objects
       if hasattr(key, "match"):
+        self.assert_(key.pattern.startswith("^/2/"),
+                     msg="Pattern %r does not start with '^/2/'" % key.pattern)
+
         found = False
         for title in titles:
           if (title.startswith("``") and
@@ -107,14 +112,18 @@ class TestDocs(unittest.TestCase):
 
         if not found:
           # TODO: Find better way of identifying resource
-          undocumented.append(str(handler))
+          undocumented.append(key.pattern)
+
+      else:
+        self.assert_(key.startswith("/2/") or key in prefix_exception,
+                     msg="Path %r does not start with '/2/'" % key)
 
-      elif ("``%s``" % key) not in titles:
-        undocumented.append(key)
+        if ("``%s``" % key) not in titles:
+          undocumented.append(key)
 
     self.failIf(undocumented,
                 msg=("Missing RAPI resource documentation for %s" %
-                     " ,".join(undocumented)))
+                     utils.CommaJoin(undocumented)))
 
 
 class TestManpages(unittest.TestCase):
@@ -122,7 +131,7 @@ class TestManpages(unittest.TestCase):
 
   @staticmethod
   def _ReadManFile(name):
-    return utils.ReadFile("%s/man/%s.sgml" %
+    return utils.ReadFile("%s/man/%s.rst" %
                           (testutils.GetSourceDir(), name))
 
   @staticmethod
@@ -139,14 +148,14 @@ class TestManpages(unittest.TestCase):
     missing = []
 
     for cmd in commands:
-      pattern = "<cmdsynopsis>\s*<command>%s</command>" % re.escape(cmd)
-      if not re.findall(pattern, mantext, re.S):
+      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, " ,".join(missing))))
+                     (script, utils.CommaJoin(missing))))
 
 
 if __name__ == "__main__":
-  unittest.main()
+  testutils.GanetiTestProgram()