diff options
Diffstat (limited to 'tests/farm/run')
| -rw-r--r-- | tests/farm/run/run_chdir.py | 12 | ||||
| -rw-r--r-- | tests/farm/run/run_timid.py | 60 | ||||
| -rw-r--r-- | tests/farm/run/run_xxx.py | 12 | ||||
| -rw-r--r-- | tests/farm/run/src/chdir.py | 4 | ||||
| -rw-r--r-- | tests/farm/run/src/showtrace.py | 23 | ||||
| -rw-r--r-- | tests/farm/run/src/subdir/placeholder | 0 | ||||
| -rw-r--r-- | tests/farm/run/src/xxx | 8 |
7 files changed, 119 insertions, 0 deletions
diff --git a/tests/farm/run/run_chdir.py b/tests/farm/run/run_chdir.py new file mode 100644 index 00000000..f459f500 --- /dev/null +++ b/tests/farm/run/run_chdir.py @@ -0,0 +1,12 @@ +copy("src", "out") +run(""" + coverage run chdir.py + coverage -r + """, rundir="out", outfile="stdout.txt") +contains("out/stdout.txt", + "Line One", + "Line Two", + "chdir" + ) +doesnt_contain("out/stdout.txt", "No such file or directory") +clean("out") diff --git a/tests/farm/run/run_timid.py b/tests/farm/run/run_timid.py new file mode 100644 index 00000000..ce78fff1 --- /dev/null +++ b/tests/farm/run/run_timid.py @@ -0,0 +1,60 @@ +# Test that the --timid command line argument properly swaps the tracer +# function for a simpler one. +# +# This is complicated by the fact that the tests are run 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 igor.py to know whether to expect to see +# the C trace function or not. + +import os + +# When meta-coverage testing, this test doesn't work, because it finds +# coverage.py's own trace function. +if os.environ.get('COVERAGE_COVERAGE', ''): + skip("Can't test timid during coverage measurement.") + +copy("src", "out") +run(""" + python showtrace.py none + coverage -e -x showtrace.py regular + coverage -e -x --timid showtrace.py timid + """, rundir="out", outfile="showtraceout.txt") + +# When running without coverage, no trace function +# When running timidly, the trace function is always Python. +contains("out/showtraceout.txt", + "none None", + "timid 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, which registers itself as f_trace. + contains("out/showtraceout.txt", "regular CTracer") +else: + # If the Python trace function is being tested, then regular running will + # also show the Python function. + contains("out/showtraceout.txt", "regular 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", + "none None", + "timid PyTracer", + "regular PyTracer", + ) + +if old_opts: + os.environ['COVERAGE_OPTIONS'] = old_opts +else: + del os.environ['COVERAGE_OPTIONS'] + +clean("out") diff --git a/tests/farm/run/run_xxx.py b/tests/farm/run/run_xxx.py new file mode 100644 index 00000000..19e94a42 --- /dev/null +++ b/tests/farm/run/run_xxx.py @@ -0,0 +1,12 @@ +copy("src", "out") +run(""" + coverage -e -x xxx + coverage -r + """, rundir="out", outfile="stdout.txt") +contains("out/stdout.txt", + "xxx: 3 4 0 7", + "\nxxx ", # The reporting line for xxx + " 7 1 86%" # The reporting data for xxx + ) +doesnt_contain("out/stdout.txt", "No such file or directory") +clean("out") diff --git a/tests/farm/run/src/chdir.py b/tests/farm/run/src/chdir.py new file mode 100644 index 00000000..6d834924 --- /dev/null +++ b/tests/farm/run/src/chdir.py @@ -0,0 +1,4 @@ +import os +print("Line One") +os.chdir("subdir") +print("Line Two") diff --git a/tests/farm/run/src/showtrace.py b/tests/farm/run/src/showtrace.py new file mode 100644 index 00000000..e97412e0 --- /dev/null +++ b/tests/farm/run/src/showtrace.py @@ -0,0 +1,23 @@ +# 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 + +# Show what the trace function is. If a C-based function is used, then f_trace +# may be None. +trace_fn = sys._getframe(0).f_trace +if trace_fn is None: + trace_name = "None" +else: + # Get the name of the tracer class. Py3k has a different way to get it. + try: + trace_name = trace_fn.im_class.__name__ + except AttributeError: + try: + trace_name = trace_fn.__self__.__class__.__name__ + except AttributeError: + # A C-based function could also manifest as an f_trace value + # which doesn't have im_class or __self__. + trace_name = trace_fn.__class__.__name__ + +print("%s %s" % (sys.argv[1], trace_name)) diff --git a/tests/farm/run/src/subdir/placeholder b/tests/farm/run/src/subdir/placeholder new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/farm/run/src/subdir/placeholder diff --git a/tests/farm/run/src/xxx b/tests/farm/run/src/xxx new file mode 100644 index 00000000..8f727f08 --- /dev/null +++ b/tests/farm/run/src/xxx @@ -0,0 +1,8 @@ +# This is a python file though it doesn't look like it, like a main script. +a = b = c = d = 0 +a = 3 +b = 4 +if not b: + c = 6 +d = 7 +print("xxx: %r %r %r %r" % (a, b, c, d)) |
