launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12919
[Merge] lp:~lifeless/python-timeline/bug-891989 into lp:python-timeline
Robert Collins has proposed merging lp:~lifeless/python-timeline/bug-891989 into lp:python-timeline.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #891989 in Timeline: "Backtrace includes format_stack() line"
https://bugs.launchpad.net/python-timeline/+bug/891989
For more details, see:
https://code.launchpad.net/~lifeless/python-timeline/bug-891989/+merge/127951
Fix a bug to make backtraces slightly nicer.
--
https://code.launchpad.net/~lifeless/python-timeline/bug-891989/+merge/127951
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-timeline/bug-891989 into lp:python-timeline.
=== modified file 'NEWS'
--- NEWS 2011-11-16 04:12:15 +0000
+++ NEWS 2012-10-04 08:00:51 +0000
@@ -6,6 +6,9 @@
NEXT
----
+* The default stack formatter now no longer includes itself in the formatted
+ stack. (Robert Collins, #891989)
+
0.0.3
-----
=== modified file 'timeline/tests/test_timeline.py'
--- timeline/tests/test_timeline.py 2011-11-16 04:32:24 +0000
+++ timeline/tests/test_timeline.py 2012-10-04 08:00:51 +0000
@@ -19,6 +19,7 @@
import datetime
import testtools
+from testtools.matchers import EndsWith
from timeline.timedaction import TimedAction
from timeline.timeline import OverlappingActionError, Timeline
@@ -128,6 +129,8 @@
action = timeline.start("Sending mail", "Noone")
self.assertNotEqual(None, action.backtrace)
self.assertIsInstance(action.backtrace, basestring)
+ self.assertThat(action.backtrace,
+ EndsWith(' action = timeline.start("Sending mail", "Noone")\n'))
def test_backtraces_can_be_disabled(self):
# Passing format_stack=None to Timeline prevents backtrace gathering.
=== modified file 'timeline/timeline.py'
--- timeline/timeline.py 2011-11-16 04:32:24 +0000
+++ timeline/timeline.py 2012-10-04 08:00:51 +0000
@@ -19,6 +19,7 @@
__metaclass__ = type
import datetime
+import sys
import traceback
from pytz import utc as UTC
@@ -45,6 +46,14 @@
# do an actual stacked/tree model of actions - if needed.
+def format_stack():
+ """Format a stack like traceback.format_stack, but skip 2 frames.
+
+ This means the stack formatting frame isn't in the backtrace itself.
+ """
+ return traceback.format_stack(f=sys._getframe(2))
+
+
class Timeline:
"""A sequence of TimedActions.
@@ -55,7 +64,7 @@
:ivar baseline: The point the timeline starts at.
"""
- def __init__(self, actions=None, format_stack=traceback.format_stack):
+ def __init__(self, actions=None, format_stack=format_stack):
"""Create a Timeline.
:param actions: An optional object to use to store the timeline. This