Merge lp:~lifeless/python-timeline/bug-891989 into lp:python-timeline

Proposed by Robert Collins on 2012-10-04
Status: Needs review
Proposed branch: lp:~lifeless/python-timeline/bug-891989
Merge into: lp:python-timeline
Diff against target: 70 lines (+16/-1)
3 files modified
NEWS (+3/-0)
timeline/tests/test_timeline.py (+3/-0)
timeline/timeline.py (+10/-1)
To merge this branch: bzr merge lp:~lifeless/python-timeline/bug-891989
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code 2012-10-04 Approve on 2012-10-04
Review via email: mp+127951@code.launchpad.net

Description of the Change

Fix a bug to make backtraces slightly nicer.

To post a comment you must log in.
Steve Kowalik (stevenk) :
review: Approve (code)

Unmerged revisions

11. By Robert Collins on 2012-10-04

* The default stack formatter now no longer includes itself in the formatted
  stack. (Robert Collins, #891989)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-11-16 04:12:15 +0000
3+++ NEWS 2012-10-04 08:00:51 +0000
4@@ -6,6 +6,9 @@
5 NEXT
6 ----
7
8+* The default stack formatter now no longer includes itself in the formatted
9+ stack. (Robert Collins, #891989)
10+
11 0.0.3
12 -----
13
14
15=== modified file 'timeline/tests/test_timeline.py'
16--- timeline/tests/test_timeline.py 2011-11-16 04:32:24 +0000
17+++ timeline/tests/test_timeline.py 2012-10-04 08:00:51 +0000
18@@ -19,6 +19,7 @@
19 import datetime
20
21 import testtools
22+from testtools.matchers import EndsWith
23
24 from timeline.timedaction import TimedAction
25 from timeline.timeline import OverlappingActionError, Timeline
26@@ -128,6 +129,8 @@
27 action = timeline.start("Sending mail", "Noone")
28 self.assertNotEqual(None, action.backtrace)
29 self.assertIsInstance(action.backtrace, basestring)
30+ self.assertThat(action.backtrace,
31+ EndsWith(' action = timeline.start("Sending mail", "Noone")\n'))
32
33 def test_backtraces_can_be_disabled(self):
34 # Passing format_stack=None to Timeline prevents backtrace gathering.
35
36=== modified file 'timeline/timeline.py'
37--- timeline/timeline.py 2011-11-16 04:32:24 +0000
38+++ timeline/timeline.py 2012-10-04 08:00:51 +0000
39@@ -19,6 +19,7 @@
40 __metaclass__ = type
41
42 import datetime
43+import sys
44 import traceback
45
46 from pytz import utc as UTC
47@@ -45,6 +46,14 @@
48 # do an actual stacked/tree model of actions - if needed.
49
50
51+def format_stack():
52+ """Format a stack like traceback.format_stack, but skip 2 frames.
53+
54+ This means the stack formatting frame isn't in the backtrace itself.
55+ """
56+ return traceback.format_stack(f=sys._getframe(2))
57+
58+
59 class Timeline:
60 """A sequence of TimedActions.
61
62@@ -55,7 +64,7 @@
63 :ivar baseline: The point the timeline starts at.
64 """
65
66- def __init__(self, actions=None, format_stack=traceback.format_stack):
67+ def __init__(self, actions=None, format_stack=format_stack):
68 """Create a Timeline.
69
70 :param actions: An optional object to use to store the timeline. This

Subscribers

People subscribed via source and target branches

to all changes: