[Python-checkins] r83527 - python/branches/py3k/Lib/test/test_trace.py

georg.brandl python-checkins at python.org
Mon Aug 2 14:48:47 CEST 2010


Author: georg.brandl
Date: Mon Aug  2 14:48:46 2010
New Revision: 83527

Log:
#3821: beginnings of a trace.py unittest.

Added:
   python/branches/py3k/Lib/test/test_trace.py   (contents, props changed)

Added: python/branches/py3k/Lib/test/test_trace.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_trace.py	Mon Aug  2 14:48:46 2010
@@ -0,0 +1,47 @@
+# Testing the trace module
+
+from test.support import run_unittest, TESTFN, rmtree, unlink, captured_stdout
+import unittest
+import trace
+import os, sys
+
+class TestCoverage(unittest.TestCase):
+    def tearDown(self):
+        rmtree(TESTFN)
+        unlink(TESTFN)
+
+    def _coverage(self, tracer):
+        tracer.run('from test import test_pprint; test_pprint.test_main()')
+        r = tracer.results()
+        r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
+
+    def test_coverage(self):
+        tracer = trace.Trace(trace=0, count=1)
+        with captured_stdout() as stdout:
+            self._coverage(tracer)
+        stdout = stdout.getvalue()
+        self.assertTrue("pprint.py" in stdout)
+        self.assertTrue("case.py" in stdout)   # from unittest
+        files = os.listdir(TESTFN)
+        self.assertTrue("pprint.cover" in files)
+        self.assertTrue("unittest.case.cover" in files)
+
+    def test_coverage_ignore(self):
+        # Ignore all files, nothing should be traced nor printed
+        libpath = os.path.normpath(os.path.dirname(os.__file__))
+        # sys.prefix does not work when running from a checkout
+        tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, libpath],
+                             trace=0, count=1)
+        with captured_stdout() as stdout:
+            self._coverage(tracer)
+        self.assertEquals(stdout.getvalue(), "")
+        if os.path.exists(TESTFN):
+            files = os.listdir(TESTFN)
+            self.assertEquals(files, [])
+
+
+def test_main():
+    run_unittest(__name__)
+
+if __name__ == "__main__":
+    test_main()


More information about the Python-checkins mailing list