-
Notifications
You must be signed in to change notification settings - Fork 955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for infinite depth tracing and fix pytest warning #235
Open
elijahqi
wants to merge
6
commits into
cool-RR:master
Choose a base branch
from
elijahqi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b9f35db
Modify depth to depth_iterator to support float('inf') and also break…
24a8376
Title: Replace deprecated getName() method with name attribute
93eecf6
add test_depth_inf
AndreaYanglq 8f5c2e3
Merge branch 'master' of github.com:elijahqi/PySnooper
c84286c
test_infinite_depth_support.py
70f69a5
Add infinite depth support for function call tracing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/python3 | ||
import pysnooper | ||
# test recursion | ||
@pysnooper.snoop(depth=float("inf"), color = False) | ||
def factorial(x): | ||
"""This is a recursive function | ||
to find the factorial of an integer""" | ||
|
||
if x == 1: | ||
return 1 | ||
else: | ||
return (x * factorial(x-1)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2023 Elijah Qi and Liuqing Yang. | ||
# This program is distributed under the MIT license. | ||
|
||
import io | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
import textwrap | ||
import threading | ||
import types | ||
import os | ||
import sys | ||
|
||
from pysnooper.utils import truncate | ||
import pytest | ||
|
||
import pysnooper | ||
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 | ||
from . import factorial | ||
|
||
|
||
def test_multiple_files(): | ||
with mini_toolbox.OutputCapturer(stdout=False, | ||
stderr=True) as output_capturer: | ||
result = factorial.factorial(3) | ||
assert result == 6 | ||
output = output_capturer.string_io.getvalue() | ||
assert_output( | ||
output, | ||
( | ||
SourcePathEntry(source_path_regex=r'.*factorial\.py$'), | ||
VariableEntry('x', '3'), | ||
CallEntry(), | ||
LineEntry(), | ||
LineEntry(), | ||
VariableEntry('x', '2'), | ||
CallEntry(), | ||
LineEntry(), | ||
LineEntry(), | ||
VariableEntry('x', '1'), | ||
CallEntry(), | ||
LineEntry(), | ||
LineEntry(), | ||
ReturnEntry(), | ||
ReturnValueEntry('1'), | ||
ElapsedTimeEntry(), | ||
ReturnEntry(), | ||
ReturnValueEntry('2'), | ||
ElapsedTimeEntry(), | ||
ReturnEntry(), | ||
ReturnValueEntry('6'), | ||
ElapsedTimeEntry() | ||
) | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# -*- 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_infinite_depth_support(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() | ||
|
||
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("foo(x)"), | ||
|
||
VariableEntry("x", "1"), | ||
VariableEntry("func"), | ||
CallEntry("def foo(x):"), | ||
LineEntry("func(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, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.