mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-04-23 03:00:38 -04:00
Show function return value. Resolves #32
This commit is contained in:
committed by
Loukas Leontopoulos
parent
43af67b1d9
commit
37ff7769a8
@@ -213,6 +213,8 @@ class Tracer:
|
||||
|
||||
self.write('{indent}{now_string} {event:9} '
|
||||
'{line_no:4} {source_line}'.format(**locals()))
|
||||
if event == 'return':
|
||||
self.write('{indent}{now_string} return_value {line_no:4} {arg}'.format(**locals()))
|
||||
return self.trace
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from python_toolbox import temp_file_tools
|
||||
import pysnooper
|
||||
|
||||
from .utils import (assert_output, VariableEntry, CallEntry, LineEntry,
|
||||
ReturnEntry, OpcodeEntry, ExceptionEntry)
|
||||
ReturnEntry, OpcodeEntry, Return_valueEntry, ExceptionEntry)
|
||||
|
||||
|
||||
def test_string_io():
|
||||
@@ -36,6 +36,7 @@ def test_string_io():
|
||||
VariableEntry('y', '8'),
|
||||
LineEntry('return y + x'),
|
||||
ReturnEntry('return y + x'),
|
||||
Return_valueEntry('15'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -78,6 +79,7 @@ def test_variables():
|
||||
VariableEntry('foo.x', '16'),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('None')
|
||||
)
|
||||
)
|
||||
|
||||
@@ -125,14 +127,17 @@ def test_depth():
|
||||
VariableEntry(),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('20'),
|
||||
|
||||
VariableEntry(),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('20'),
|
||||
|
||||
VariableEntry(),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('20'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -167,6 +172,7 @@ def test_method_and_prefix():
|
||||
LineEntry('self.x **= 2'),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry(),
|
||||
),
|
||||
prefix='ZZZ'
|
||||
)
|
||||
@@ -194,6 +200,7 @@ def test_file_output():
|
||||
VariableEntry('y', '8'),
|
||||
LineEntry('return y + x'),
|
||||
ReturnEntry('return y + x'),
|
||||
Return_valueEntry('15'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -229,8 +236,10 @@ def test_confusing_decorator_lines():
|
||||
CallEntry('x = lambda bar: 7'),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('7'),
|
||||
# back in my_function
|
||||
ReturnEntry(),
|
||||
Return_valueEntry('15'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -248,5 +257,6 @@ def test_lambda():
|
||||
CallEntry(source_regex='^my_function = pysnooper.*'),
|
||||
LineEntry(source_regex='^my_function = pysnooper.*'),
|
||||
ReturnEntry(source_regex='^my_function = pysnooper.*'),
|
||||
Return_valueEntry('49'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -81,13 +81,13 @@ class _BaseEventEntry(_BaseEntry):
|
||||
|
||||
line_pattern = re.compile(
|
||||
(r"""^(?P<prefix>.*?)(?P<indent>(?: {4})*)[0-9:.]{15} """
|
||||
r"""(?P<event_name>[a-z]*) +(?P<line_number>[0-9]*) """
|
||||
r"""(?P<event_name>[a-z_]*) +(?P<line_number>[0-9]*) """
|
||||
r"""+(?P<source>.*)$""")
|
||||
)
|
||||
|
||||
@caching.CachedProperty
|
||||
def event_name(self):
|
||||
return re.match('^[A-Z][a-z]*', type(self).__name__).group(0).lower()
|
||||
return re.match('^[A-Z][a-z_]*', type(self).__name__).group(0).lower()
|
||||
|
||||
def _check_source(self, source):
|
||||
if self.source is not None:
|
||||
@@ -121,6 +121,8 @@ class ExceptionEntry(_BaseEventEntry):
|
||||
class OpcodeEntry(_BaseEventEntry):
|
||||
pass
|
||||
|
||||
class Return_valueEntry(_BaseEventEntry):
|
||||
pass
|
||||
|
||||
class OutputFailure(Exception):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user