blob: 247c49ce60e509d6667dbb757cb47019fb855a61 [file] [log] [blame]
Georg Brandl283b1252010-08-02 12:48:46 +00001# Testing the trace module
2
3from test.support import run_unittest, TESTFN, rmtree, unlink, captured_stdout
4import unittest
5import trace
6import os, sys
7
8class TestCoverage(unittest.TestCase):
9 def tearDown(self):
10 rmtree(TESTFN)
11 unlink(TESTFN)
12
13 def _coverage(self, tracer):
14 tracer.run('from test import test_pprint; test_pprint.test_main()')
15 r = tracer.results()
16 r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
17
18 def test_coverage(self):
19 tracer = trace.Trace(trace=0, count=1)
20 with captured_stdout() as stdout:
21 self._coverage(tracer)
22 stdout = stdout.getvalue()
23 self.assertTrue("pprint.py" in stdout)
24 self.assertTrue("case.py" in stdout) # from unittest
25 files = os.listdir(TESTFN)
26 self.assertTrue("pprint.cover" in files)
27 self.assertTrue("unittest.case.cover" in files)
28
29 def test_coverage_ignore(self):
30 # Ignore all files, nothing should be traced nor printed
31 libpath = os.path.normpath(os.path.dirname(os.__file__))
32 # sys.prefix does not work when running from a checkout
33 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, libpath],
34 trace=0, count=1)
35 with captured_stdout() as stdout:
36 self._coverage(tracer)
37 self.assertEquals(stdout.getvalue(), "")
38 if os.path.exists(TESTFN):
39 files = os.listdir(TESTFN)
40 self.assertEquals(files, [])
41
42
43def test_main():
44 run_unittest(__name__)
45
46if __name__ == "__main__":
47 test_main()