summaryrefslogtreecommitdiff
path: root/test_files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-03-05 21:21:43 -0500
committerNed Batchelder <ned@nedbatchelder.com>2009-03-05 21:21:43 -0500
commit0cc8fd18714cb214327a0a58b704401a9efdf8dc (patch)
tree0a6ac59eaf1b7acaf26053a5f3c69304b9ddbda3 /test_files.py
downloadpython-coveragepy-git-0cc8fd18714cb214327a0a58b704401a9efdf8dc.tar.gz
Initial coverage.py 3.0 beta 1
Diffstat (limited to 'test_files.py')
-rw-r--r--test_files.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/test_files.py b/test_files.py
new file mode 100644
index 00000000..88d34a2a
--- /dev/null
+++ b/test_files.py
@@ -0,0 +1,53 @@
+# File-based unit tests for coverage.py
+
+import path, sys, unittest
+import coverage
+
+class OneFileTestCase(unittest.TestCase):
+ def __init__(self, filename):
+ unittest.TestCase.__init__(self)
+ self.filename = filename
+
+ def shortDescription(self):
+ return self.filename
+
+ def setUp(self):
+ # Create a temporary directory.
+ self.noise = str(random.random())[2:]
+ self.temproot = path.path(tempfile.gettempdir()) / 'test_coverage'
+ self.tempdir = self.temproot / self.noise
+ self.tempdir.makedirs()
+ self.olddir = os.getcwd()
+ os.chdir(self.tempdir)
+ # Keep a counter to make every call to checkCoverage unique.
+ self.n = 0
+
+ # Capture stdout, so we can use print statements in the tests and not
+ # pollute the test output.
+ self.oldstdout = sys.stdout
+ self.capturedstdout = StringIO()
+ sys.stdout = self.capturedstdout
+ coverage.begin_recursive()
+
+ def tearDown(self):
+ coverage.end_recursive()
+ sys.stdout = self.oldstdout
+ # Get rid of the temporary directory.
+ os.chdir(self.olddir)
+ self.temproot.rmtree()
+
+ def runTest(self):
+ # THIS ISN'T DONE YET!
+ pass
+
+class MyTestSuite(unittest.TestSuite):
+ def __init__(self):
+ unittest.TestSuite.__init__(self)
+ for f in path.path('test').walk('*.py'):
+ self.addFile(f)
+
+ def addFile(self, f):
+ self.addTest(OneFileTestCase(f))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='MyTestSuite')