summaryrefslogtreecommitdiff
path: root/test/test_farm.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-03-14 19:17:17 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-03-14 19:17:17 -0400
commitdad7ff8429e1c785840687d93dc17bfd43ba8a21 (patch)
treec5767330e9a4709722f72e579751c64f192d05ea /test/test_farm.py
parent3048c7084e1dd8479359d4183f712db1ebd3fc53 (diff)
downloadpython-coveragepy-git-dad7ff8429e1c785840687d93dc17bfd43ba8a21.tar.gz
A farm of directories holding test cases.
--HG-- rename : test/white.py,cover => test/farm/000/gold/white.py,cover rename : test/white.py => test/farm/000/src/white.py
Diffstat (limited to 'test/test_farm.py')
-rw-r--r--test/test_farm.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/test_farm.py b/test/test_farm.py
new file mode 100644
index 00000000..50f4fdef
--- /dev/null
+++ b/test/test_farm.py
@@ -0,0 +1,65 @@
+"""Run tests in the farm subdirectory. Requires nose."""
+
+import filecmp, fnmatch, glob, os, shutil, sys
+from coverage.files import FileLocator
+
+
+def test_farm():
+ """A test-generating function for nose to find and run."""
+ for fname in glob.glob("test/farm/*/*.py"):
+ case = FarmTestCase(fname)
+ yield (case.execute,)
+
+
+class FarmTestCase(object):
+ def __init__(self, runpy):
+ self.dir, self.runpy = os.path.split(runpy)
+
+ def cd(self, newdir):
+ cwd = os.getcwd()
+ os.chdir(newdir)
+ return cwd
+
+ def execute(self):
+ print "Running", self.runpy, "in", self.dir
+ cwd = self.cd(self.dir)
+
+ glo = dict([(a, getattr(self, a)) for a in "run compare clean".split()])
+ execfile(self.runpy, glo)
+
+ self.cd(cwd)
+
+ def fnmatch_list(self, files, filepattern):
+ """Filter the list of `files` to only those that match `filepattern`."""
+
+ return [f for f in files if fnmatch.fnmatch(f, filepattern)]
+
+ # Functions usable inside farm run.py files
+
+ def run(self, cmds, rundir="src"):
+ """Run a list of commands.
+
+ `cmds` is a string, commands separated by newlines.
+ `rundir` is the directory in which to run the commands.
+
+ """
+ cwd = self.cd(rundir)
+ for cmd in cmds.split("\n"):
+ stdin, stdouterr = os.popen4(cmd)
+ output = stdouterr.read()
+ print output,
+ self.cd(cwd)
+
+ def compare(self, dir1, dir2, filepattern=None):
+ dc = filecmp.dircmp(dir1, dir2)
+
+ pass
+
+ def clean(self, cleandir):
+ shutil.rmtree(cleandir)
+
+
+# So that we can run just one farm run.py at a time.
+if __name__ == '__main__':
+ case = FarmTestCase(sys.argv[1])
+ case.execute()