summaryrefslogtreecommitdiffstats
path: root/testsuite/Testtools
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 09:58:06 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 09:58:06 -0400
commit5ac4217ee9c4f84dbc47d4eee1ca643960325ecb (patch)
treecf9022cd0c2635223094e9e65f74ec513ec3ba66 /testsuite/Testtools
parentd9d4391b211c0a13cbfeadc9fa63e5bdeba9d2f6 (diff)
downloadbcfg2-5ac4217ee9c4f84dbc47d4eee1ca643960325ecb.tar.gz
bcfg2-5ac4217ee9c4f84dbc47d4eee1ca643960325ecb.tar.bz2
bcfg2-5ac4217ee9c4f84dbc47d4eee1ca643960325ecb.zip
fixed up tools documentation, added tests for tools doco
Diffstat (limited to 'testsuite/Testtools')
-rw-r--r--testsuite/Testtools/__init__.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/testsuite/Testtools/__init__.py b/testsuite/Testtools/__init__.py
new file mode 100644
index 000000000..73687eb5f
--- /dev/null
+++ b/testsuite/Testtools/__init__.py
@@ -0,0 +1,98 @@
+import os
+import re
+import sys
+
+# add all parent testsuite directories to sys.path to allow (most)
+# relative imports in python 2.4
+path = os.path.dirname(__file__)
+while path != "/":
+ if os.path.basename(path).lower().startswith("test"):
+ sys.path.append(path)
+ if os.path.basename(path) == "testsuite":
+ break
+ path = os.path.dirname(path)
+from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \
+ skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \
+ patchIf, datastore
+
+TOOLSDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
+ "..", "..", "tools"))
+
+class TestToolsDocs(Bcfg2TestCase):
+ blankline = re.compile(r'^\s*$')
+
+ @skipUnless(os.path.exists(TOOLSDIR),
+ "%s does not exist, skipping tools/ tests" % TOOLSDIR)
+ def tools_in_README(self, toolsdir=None):
+ if toolsdir is None:
+ toolsdir = TOOLSDIR
+ script = None
+ desc = None
+ started = False
+ rv = dict()
+ for line in open(os.path.join(toolsdir, "README")).readlines():
+ if not started:
+ # skip up to the first blank line
+ if self.blankline.match(line):
+ started = True
+ elif not self.blankline.match(line):
+ match = re.match(r'^(\S+)', line)
+ if match:
+ script = match.group(1)
+ desc = ''
+ else:
+ match = re.match(r'^\s+(?:-\s+)?(.*)$', line)
+ if match:
+ desc += match.group(1)
+ else:
+ # blank line
+ if script and desc:
+ rv[script] = desc
+ if script and desc:
+ rv[script] = desc
+ return rv
+
+ @skipUnless(os.path.exists(TOOLSDIR),
+ "%s does not exist, skipping tools/ tests" % TOOLSDIR)
+ def test_all_scripts_in_README(self, prefix=''):
+ toolsdir = os.path.join(TOOLSDIR, prefix)
+ tools = self.tools_in_README(toolsdir=toolsdir)
+ for fname in os.listdir(toolsdir):
+ if fname == 'README':
+ continue
+ dname = os.path.join(prefix, fname) # display name
+ fpath = os.path.join(toolsdir, fname)
+ if os.path.isfile(fpath):
+ self.assertIn(fname, tools,
+ msg="%s has no entry in README" % dname)
+ self.assertNotRegexpMatches(tools[fname], r'^(\s|\?)*$',
+ msg="%s has an empty entry in README" %
+ dname)
+
+ @skipUnless(os.path.exists(TOOLSDIR),
+ "%s does not exist, skipping tools/ tests" % TOOLSDIR)
+ def test_no_extras_in_README(self, prefix=''):
+ toolsdir = os.path.join(TOOLSDIR, prefix)
+ tools = self.tools_in_README(toolsdir=toolsdir)
+ for fname in tools.keys():
+ dname = os.path.join(prefix, fname) # display name
+ fpath = os.path.join(toolsdir, fname)
+ self.assertTrue(os.path.exists(fpath),
+ msg="%s is listed in README but does not exist" %
+ dname)
+
+ @skipUnless(os.path.exists(TOOLSDIR),
+ "%s does not exist, skipping tools/ tests" % TOOLSDIR)
+ def test_upgrade_scripts_documented(self):
+ upgrade = os.path.join(TOOLSDIR, "upgrade")
+ for udir in os.listdir(upgrade):
+ upath = os.path.join(upgrade, udir)
+ dname = os.path.join("upgrade", udir) # display name
+ self.assertTrue(os.path.isdir(upath),
+ msg="Unexpected script %s found in %s" % (udir,
+ dname))
+ self.assertTrue(os.path.exists(os.path.join(upath, 'README')),
+ msg="%s has no README" % dname)
+ self.test_all_scripts_in_README(dname)
+
+