From 93eecf679e236c39b04a29ad9d4d9522ced9d68b Mon Sep 17 00:00:00 2001 From: AndreaYanglq <97621027+AndreaYanglq@users.noreply.github.com> Date: Sat, 15 Apr 2023 22:57:04 -0400 Subject: [PATCH] add test_depth_inf --- .DS_Store | Bin 0 -> 6148 bytes tests/test_depth_inf/__init__.py | 0 tests/test_depth_inf/factorial.py | 13 ++++++ tests/test_depth_inf/test_depth_inf.py | 59 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .DS_Store create mode 100644 tests/test_depth_inf/__init__.py create mode 100644 tests/test_depth_inf/factorial.py create mode 100644 tests/test_depth_inf/test_depth_inf.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..835a6b7eff91ecd3069a57f1dee80cbb762e33fa GIT binary patch literal 6148 zcmeHKy-ve05I(m-3LsF24s7HJ5PgGy!V~ZSl>VqiB27fgz?O|yU|@q6U}i%Mzy<>g zVrGK{cD}PsYpbDRLI~YezAyFN*qDFI?`Qp51(0Z}{=f z%y`~+-VF=uD5WLLo6`}Es7pim9ct4qTA#We6RMog&UU$7UA$i28g4VjPqPWzpH+DL zsmc5UN}<}2+8*1=bLz%iZoBsnCu7}gt;?h=?#)}}X=z@oHlzV%_~lUVz+*r!o$@S~ z%Ts-@dS`Sh8P8=kJJaK*^t#TCS9Iv{s=meG_Jp1u(W)7(@?D OJ_NK3;zWU8Rp1lve!eFF literal 0 HcmV?d00001 diff --git a/tests/test_depth_inf/__init__.py b/tests/test_depth_inf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_depth_inf/factorial.py b/tests/test_depth_inf/factorial.py new file mode 100644 index 0000000..e7539d3 --- /dev/null +++ b/tests/test_depth_inf/factorial.py @@ -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)) + diff --git a/tests/test_depth_inf/test_depth_inf.py b/tests/test_depth_inf/test_depth_inf.py new file mode 100644 index 0000000..c8e904b --- /dev/null +++ b/tests/test_depth_inf/test_depth_inf.py @@ -0,0 +1,59 @@ +# Copyright 2019 Ram Rachum and collaborators. +# This program is distributed under the MIT license. + +import io +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() + ) + ) + +