mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
test_infinite_depth_support.py
This commit is contained in:
parent
8f5c2e3f85
commit
c84286c189
2 changed files with 113 additions and 9 deletions
9
a.py
9
a.py
|
|
@ -1,9 +0,0 @@
|
|||
import pysnooper
|
||||
|
||||
@pysnooper.snoop(depth = float('inf'))
|
||||
def func(x):
|
||||
if x == 0:
|
||||
return
|
||||
func(x - 1)
|
||||
|
||||
func(3)
|
||||
113
tests/test_infinite_depth_support.py
Normal file
113
tests/test_infinite_depth_support.py
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2023 Elijah Qi and Liuqing Yang.
|
||||
# This program is distributed under the MIT license.
|
||||
|
||||
import io
|
||||
import textwrap
|
||||
import threading
|
||||
import types
|
||||
import sys
|
||||
|
||||
from pysnooper.utils import truncate
|
||||
import pytest
|
||||
|
||||
import pysnooper
|
||||
from pysnooper import pycompat
|
||||
from pysnooper.variables import needs_parentheses
|
||||
from .utils import (assert_output, assert_sample_output, VariableEntry,
|
||||
CallEntry, LineEntry, ReturnEntry, OpcodeEntry,
|
||||
ReturnValueEntry, ExceptionEntry, ExceptionValueEntry,
|
||||
SourcePathEntry, CallEndedByExceptionEntry,
|
||||
ElapsedTimeEntry)
|
||||
from . import mini_toolbox
|
||||
|
||||
@pytest.mark.parametrize("normalize", (True, False))
|
||||
def test_var_order(normalize):
|
||||
string_io = io.StringIO()
|
||||
|
||||
def func1(x):
|
||||
return x
|
||||
|
||||
def func(x):
|
||||
func1(x)
|
||||
|
||||
def foo(x):
|
||||
func(x)
|
||||
|
||||
def recursive_function(x):
|
||||
if x == 0:
|
||||
return 1
|
||||
|
||||
foo(x)
|
||||
|
||||
recursive_function(x - 1)
|
||||
|
||||
with pysnooper.snoop(string_io, depth=float('inf'), normalize=normalize, color=False):
|
||||
recursive_function(1)
|
||||
|
||||
output = string_io.getvalue()
|
||||
with open('test_var_order.txt', 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
assert_output(
|
||||
output,
|
||||
(
|
||||
SourcePathEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
LineEntry("recursive_function(1)"),
|
||||
VariableEntry("x", "1"),
|
||||
VariableEntry("foo"),
|
||||
VariableEntry("recursive_function"),
|
||||
|
||||
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("x", "1"),
|
||||
VariableEntry("func1"),
|
||||
CallEntry("def func(x):"),
|
||||
LineEntry("func1(x)"),
|
||||
|
||||
VariableEntry("x", "1"),
|
||||
CallEntry("def func1(x):"),
|
||||
LineEntry("return x"),
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry("1"),
|
||||
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry("None"),
|
||||
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry("None"),
|
||||
|
||||
LineEntry("recursive_function(x - 1)"),
|
||||
|
||||
VariableEntry("x", "0"),
|
||||
VariableEntry("foo"),
|
||||
VariableEntry("recursive_function"),
|
||||
|
||||
CallEntry("def recursive_function(x):"),
|
||||
LineEntry("if x == 0:"),
|
||||
LineEntry("return 1"),
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry("1"),
|
||||
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry("None"),
|
||||
|
||||
LineEntry("with pysnooper.snoop(string_io, depth=float('inf'), normalize=normalize, color=False):"),
|
||||
ElapsedTimeEntry(),
|
||||
),
|
||||
normalize=normalize,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue