Merge lp:~lifeless/python-oops/pprint into lp:python-oops

Proposed by Robert Collins
Status: Merged
Approved by: James Westby
Approved revision: 36
Merged at revision: 35
Proposed branch: lp:~lifeless/python-oops/pprint
Merge into: lp:python-oops
Diff against target: 167 lines (+81/-1)
7 files modified
.testr.conf (+4/-0)
Makefile (+13/-0)
NEWS (+4/-0)
README (+7/-0)
oops/__init__.py (+2/-0)
oops/publishers.py (+22/-1)
oops/tests/test_publishers.py (+29/-0)
To merge this branch: bzr merge lp:~lifeless/python-oops/pprint
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+119069@code.launchpad.net

Description of the change

Make it easy to show oopses on the console. Also add missing build infrastructure like .testr.conf.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.testr.conf'
--- .testr.conf 1970-01-01 00:00:00 +0000
+++ .testr.conf 2012-08-10 01:06:20 +0000
@@ -0,0 +1,4 @@
1[DEFAULT]
2test_command=PYTHONPATH=. bin/py -m subunit.run $LISTOPT $IDOPTION oops.tests.test_suite
3test_id_option=--load-list $IDFILE
4test_list_option=--list
05
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2012-08-10 01:06:20 +0000
@@ -0,0 +1,13 @@
1all:
2
3bin/buildout: buildout.cfg versions.cfg setup.py download-cache eggs
4 ./bootstrap.py \
5 --setup-source=download-cache/ez_setup.py \
6 --download-base=download-cache/dist --eggs=eggs
7
8
9download-cache:
10 bzr checkout --lightweight lp:lp-source-dependencies download-cache
11
12eggs:
13 mkdir eggs
014
=== modified file 'NEWS'
--- NEWS 2012-06-26 21:23:59 +0000
+++ NEWS 2012-08-10 01:06:20 +0000
@@ -6,6 +6,10 @@
6NEXT6NEXT
7----7----
88
9* New publishers pprint_to_stream. Very useful for interactive observing of
10 Oops reports - just hook it up to your source (e.g. via oops_amqp) and
11 off you go. (Robert Collins)
12
90.0.11130.0.11
10------14------
1115
1216
=== modified file 'README'
--- README 2012-06-26 21:28:11 +0000
+++ README 2012-08-10 01:06:20 +0000
@@ -107,6 +107,9 @@
107 >>> report['id']107 >>> report['id']
108 'id 1'108 'id 1'
109109
110* The pprint_to_stream publisher will print out reports to a stream after
111pprinting them. This can be very helpful for interactive use.
112
110* The related project oops_datedir_repo contains a local disk based repository which113* The related project oops_datedir_repo contains a local disk based repository which
111can be used as a publisher.114can be used as a publisher.
112115
@@ -133,3 +136,7 @@
133For instance::136For instance::
134137
135 $ bin/py -m testtools.run oops.tests.test_suite138 $ bin/py -m testtools.run oops.tests.test_suite
139
140Alternative you can use the testr command from testrepository::
141
142 $ testr run
136143
=== modified file 'oops/__init__.py'
--- oops/__init__.py 2012-06-26 21:29:11 +0000
+++ oops/__init__.py 2012-08-10 01:06:20 +0000
@@ -30,6 +30,7 @@
30__all__ = [30__all__ = [
31 'Config',31 'Config',
32 'convert_result_to_list',32 'convert_result_to_list',
33 'pprint_to_stream',
33 'publish_new_only',34 'publish_new_only',
34 'publish_to_many',35 'publish_to_many',
35 'publish_with_fallback',36 'publish_with_fallback',
@@ -38,6 +39,7 @@
38from oops.config import Config39from oops.config import Config
39from oops.publishers import (40from oops.publishers import (
40 convert_result_to_list,41 convert_result_to_list,
42 pprint_to_stream,
41 publish_new_only,43 publish_new_only,
42 publish_to_many,44 publish_to_many,
43 publish_with_fallback,45 publish_with_fallback,
4446
=== modified file 'oops/publishers.py'
--- oops/publishers.py 2012-06-26 20:57:41 +0000
+++ oops/publishers.py 2012-08-10 01:06:20 +0000
@@ -18,9 +18,30 @@
18__metaclass__ = type18__metaclass__ = type
1919
20__all__ = [20__all__ = [
21 'publish_new_only',21 'pprint_to_stream',
22 'publish_with_fallback',
23 'publish_to_many',
22 ]24 ]
2325
26from hashlib import md5
27from pprint import pformat
28
29
30def pprint_to_stream(stream):
31 """Pretty print reports to stream.
32
33 Reports will be given an id by hashing the report if none is present.
34 """
35 def pprinter(report):
36 report = dict(report)
37 output = pformat(report)
38 if not report.get('id'):
39 report['id'] = md5(output).hexdigest()
40 output = pformat(report)
41 stream.write(output)
42 return [report['id']]
43 return pprinter
44
2445
25def publish_new_only(publisher):46def publish_new_only(publisher):
26 """Wraps a publisher with a check that the report has not had an id set.47 """Wraps a publisher with a check that the report has not had an id set.
2748
=== modified file 'oops/tests/test_publishers.py'
--- oops/tests/test_publishers.py 2012-06-26 20:52:24 +0000
+++ oops/tests/test_publishers.py 2012-08-10 01:06:20 +0000
@@ -17,10 +17,15 @@
1717
18__metaclass__ = type18__metaclass__ = type
1919
20from hashlib import md5
21from pprint import pformat
22from StringIO import StringIO
23
20import testtools24import testtools
2125
22from oops import (26from oops import (
23 convert_result_to_list,27 convert_result_to_list,
28 pprint_to_stream,
24 publish_new_only,29 publish_new_only,
25 publish_to_many,30 publish_to_many,
26 publish_with_fallback,31 publish_with_fallback,
@@ -168,3 +173,27 @@
168 def trueish(report):173 def trueish(report):
169 return "aaa"174 return "aaa"
170 self.assertEqual(["aaa"], convert_result_to_list(trueish)({}))175 self.assertEqual(["aaa"], convert_result_to_list(trueish)({}))
176
177
178class TestPPrintToStream(testtools.TestCase):
179
180 def test_inherits_id_when_set(self):
181 output = StringIO()
182 publisher = pprint_to_stream(output)
183 published = publisher({'foo': 'bar', 'id': 'quux'})
184 self.assertEqual(['quux'], published)
185
186 def test_returns_pprint_hash(self):
187 output = StringIO()
188 publisher = pprint_to_stream(output)
189 published = publisher({'foo': 'bar'})
190 pprint_value = pformat({'foo': 'bar'})
191 self.assertEqual([md5(pprint_value).hexdigest()], published)
192
193 def test_outputs_pprint(self):
194 output = StringIO()
195 publisher = pprint_to_stream(output)
196 publisher({'foo': 'bar'})
197 self.assertEqual(
198 "{'foo': 'bar', 'id': 'dd63dafcbd4d5b28badfcaf86fb6fcdb'}",
199 output.getvalue())

Subscribers

People subscribed via source and target branches

to all changes: