From 689679aa144314c9ac0dc4a48d336889992de1a5 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 25 Apr 2011 21:29:20 -0400 Subject: A fix for bug #123, but it doesn't restore tracing properly yet, still want to get to the bottom of that. --HG-- branch : bug_123 --- test/test_oddball.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/test_oddball.py b/test/test_oddball.py index e94e2bad..9b65a986 100644 --- a/test/test_oddball.py +++ b/test/test_oddball.py @@ -348,3 +348,20 @@ if sys.version_info >= (2, 5): doctest.testmod(sys.modules[__name__]) # we're not __main__ :( ''', [1,11,12,14,16,17], "") + + +if hasattr(sys, 'gettrace'): + class GettraceTest(CoverageTest): + """Tests that we work properly with `sys.gettrace()`.""" + def test_round_trip(self): + self.check_coverage('''\ + import sys + def foo(n): + return 3*n + def bar(n): + return 5*n + a = foo(6) + sys.settrace(sys.gettrace()) + a = bar(8) + ''', + [1,2,3,4,5,6,7,8], "") -- cgit v1.2.1 From a243a6a2b34eb9ef5cba3346796160e06ba77930 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 27 Apr 2011 09:42:41 -0400 Subject: C trace function now roundtrips properly. Fixes #123 and #125. --HG-- branch : bug_123 --- test/farm/run/run_timid.py | 5 ++--- test/farm/run/src/showtrace.py | 9 +++++++-- test/test_oddball.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/farm/run/run_timid.py b/test/farm/run/run_timid.py index 3810e6db..19651a1c 100644 --- a/test/farm/run/run_timid.py +++ b/test/farm/run/run_timid.py @@ -20,9 +20,8 @@ contains("out/showtraceout.txt", "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 (shown as None in f_trace since it isn't a Python - # function). - contains("out/showtraceout.txt", "regular None") + # the C function, which registers itself as f_trace. + contains("out/showtraceout.txt", "regular Tracer") else: # If the Python trace function is being tested, then regular running will # also show the Python function. diff --git a/test/farm/run/src/showtrace.py b/test/farm/run/src/showtrace.py index c3b4356c..e97412e0 100644 --- a/test/farm/run/src/showtrace.py +++ b/test/farm/run/src/showtrace.py @@ -4,7 +4,7 @@ import sys # Show what the trace function is. If a C-based function is used, then f_trace -# is None. +# may be None. trace_fn = sys._getframe(0).f_trace if trace_fn is None: trace_name = "None" @@ -13,6 +13,11 @@ else: try: trace_name = trace_fn.im_class.__name__ except AttributeError: - trace_name = trace_fn.__self__.__class__.__name__ + 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/test/test_oddball.py b/test/test_oddball.py index 9b65a986..859648fa 100644 --- a/test/test_oddball.py +++ b/test/test_oddball.py @@ -365,3 +365,20 @@ if hasattr(sys, 'gettrace'): a = bar(8) ''', [1,2,3,4,5,6,7,8], "") + + def test_multi_layers(self): + self.check_coverage('''\ + import sys + def level1(): + a = 3 + level2() + b = 5 + def level2(): + c = 7 + sys.settrace(sys.gettrace()) + d = 9 + e = 10 + level1() + f = 12 + ''', + [1,2,3,4,5,6,7,8,9,10,11,12], "") -- cgit v1.2.1