Add infinite depth support for function call tracing

This commit adds a new feature that enables infinite depth support for function call tracing in pysnooper. The test_infinite_depth_support test case has been added to verify the correct behavior of the feature. The test case covers the case of tracing a recursive function call with unlimited depth and checks the output against the expected values. The feature works by setting the depth parameter to float('inf') in the pysnooper.snoop function.
This commit is contained in:
Elijah Qi 2023-04-15 23:46:27 -04:00
parent c84286c189
commit 70f69a5cb7
2 changed files with 6 additions and 8 deletions

View file

@ -1,4 +1,5 @@
# Copyright 2019 Ram Rachum and collaborators.
# -*- coding: utf-8 -*-
# Copyright 2023 Elijah Qi and Liuqing Yang.
# This program is distributed under the MIT license.
import io

View file

@ -22,7 +22,7 @@ from .utils import (assert_output, assert_sample_output, VariableEntry,
from . import mini_toolbox
@pytest.mark.parametrize("normalize", (True, False))
def test_var_order(normalize):
def test_infinite_depth_support(normalize):
string_io = io.StringIO()
def func1(x):
@ -46,8 +46,6 @@ def test_var_order(normalize):
recursive_function(1)
output = string_io.getvalue()
with open('test_var_order.txt', 'w') as f:
f.write(output)
assert_output(
output,
@ -66,13 +64,12 @@ def test_var_order(normalize):
CallEntry("def recursive_function(x):"),
LineEntry("if x == 0:"),
LineEntry(),
LineEntry("foo(x)"),
VariableEntry("x", "1"),
VariableEntry("func1"),
CallEntry("def func(x):"),
LineEntry("func1(x)"),
VariableEntry("func"),
CallEntry("def foo(x):"),
LineEntry("func(x)"),
VariableEntry("x", "1"),
VariableEntry("func1"),