diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-08-09 18:12:23 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-08-09 18:12:23 -0400 |
commit | cba5899f0bad8a49b17750df58ddd532975c1062 (patch) | |
tree | 02eac123c89f439b440c7efb6a7aa0a98bd12e80 /test | |
parent | b159081bb7df0c838bcf01ca9e70899a61ae9d9b (diff) | |
download | python-coveragepy-git-cba5899f0bad8a49b17750df58ddd532975c1062.tar.gz |
Fix a problem with DecoratorTools fiddling with the trace function and screwing us up. Now the Python trace function is simpler, with no variability of registered trace function. Fixes bugs #12 and #13.
Diffstat (limited to 'test')
-rw-r--r-- | test/farm/run/run_timid.py | 50 | ||||
-rw-r--r-- | test/farm/run/src/showtrace.py | 15 |
2 files changed, 65 insertions, 0 deletions
diff --git a/test/farm/run/run_timid.py b/test/farm/run/run_timid.py new file mode 100644 index 00000000..bbc322e2 --- /dev/null +++ b/test/farm/run/run_timid.py @@ -0,0 +1,50 @@ +# Test that the --timid command line argument properly swaps the tracer function +# for a simpler one. +# +# This is complicated by the fact that alltests.cmd will run the test suite +# twice for each version: once with a compiled C-based trace function, and once +# without it, to also test the Python trace function. So this test has to +# examine an environment variable set in alltests.cmd to know whether to expect +# to see the C trace function or not. + +import os + +copy("src", "out") +run(""" + coverage -e -x showtrace.py regular + coverage -e -x --timid showtrace.py timid + """, rundir="out", outfile="showtraceout.txt") + +# When running timidly, the trace function is always Python. +contains("out/showtraceout.txt", "timid coverage.collector.PyTracer") + +if os.environ.get('COVERAGE_TEST_TRACER', 'c') == 'c': + # If the C trace function is being tested, then regular running should have + # the C function (shown as None in f_trace since it isn't a Python + # function). + contains("out/showtraceout.txt", "regular None") +else: + # If the Python trace function is being tested, then regular running will + # also show the Python function. + contains("out/showtraceout.txt", "regular coverage.collector.PyTracer") + +# Try the environment variable. +old_opts = os.environ.get('COVERAGE_OPTIONS') +os.environ['COVERAGE_OPTIONS'] = '--timid' + +run(""" + coverage -e -x showtrace.py regular + coverage -e -x --timid showtrace.py timid + """, rundir="out", outfile="showtraceout.txt") + +contains("out/showtraceout.txt", + "timid coverage.collector.PyTracer", + "regular coverage.collector.PyTracer" + ) + +if old_opts: + os.environ['COVERAGE_OPTIONS'] = old_opts +else: + del os.environ['COVERAGE_OPTIONS'] + +clean("out") diff --git a/test/farm/run/src/showtrace.py b/test/farm/run/src/showtrace.py new file mode 100644 index 00000000..49e212e8 --- /dev/null +++ b/test/farm/run/src/showtrace.py @@ -0,0 +1,15 @@ +# Show the current frame's trace function, so that we can test what the +# command-line options do to the trace function used. + +import sys + +# Print the argument as a label for the output. +print sys.argv[1], + +# Show what the trace function is. If a C-based function is used, then f_trace +# is None. +trace_fn = sys._getframe(0).f_trace +if trace_fn is None: + print "None" +else: + print trace_fn.im_class |