diff options
author | Georg Brandl <georg@python.org> | 2010-08-02 12:48:46 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-02 12:48:46 (GMT) |
commit | 283b1255516c67332f28a0dff4fb28aa93f07d11 (patch) | |
tree | 69c71eabd107911376b7d66aeefcb4dd07051fae /Lib/test/test_trace.py | |
parent | dc50c696ab7e091cef5d88d98be44cef15efcc1f (diff) | |
download | cpython-283b1255516c67332f28a0dff4fb28aa93f07d11.zip cpython-283b1255516c67332f28a0dff4fb28aa93f07d11.tar.gz cpython-283b1255516c67332f28a0dff4fb28aa93f07d11.tar.bz2 |
#3821: beginnings of a trace.py unittest.
Diffstat (limited to 'Lib/test/test_trace.py')
-rw-r--r-- | Lib/test/test_trace.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py new file mode 100644 index 0000000..247c49c --- /dev/null +++ b/Lib/test/test_trace.py @@ -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() |