launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #10813
[Merge] lp:~lifeless/python-oops/pprint into lp:python-oops
Robert Collins has proposed merging lp:~lifeless/python-oops/pprint into lp:python-oops.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lifeless/python-oops/pprint/+merge/119069
Make it easy to show oopses on the console. Also add missing build infrastructure like .testr.conf.
--
https://code.launchpad.net/~lifeless/python-oops/pprint/+merge/119069
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-oops/pprint into lp:python-oops.
=== 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 @@
+[DEFAULT]
+test_command=PYTHONPATH=. bin/py -m subunit.run $LISTOPT $IDOPTION oops.tests.test_suite
+test_id_option=--load-list $IDFILE
+test_list_option=--list
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2012-08-10 01:06:20 +0000
@@ -0,0 +1,13 @@
+all:
+
+bin/buildout: buildout.cfg versions.cfg setup.py download-cache eggs
+ ./bootstrap.py \
+ --setup-source=download-cache/ez_setup.py \
+ --download-base=download-cache/dist --eggs=eggs
+
+
+download-cache:
+ bzr checkout --lightweight lp:lp-source-dependencies download-cache
+
+eggs:
+ mkdir eggs
=== modified file 'NEWS'
--- NEWS 2012-06-26 21:23:59 +0000
+++ NEWS 2012-08-10 01:06:20 +0000
@@ -6,6 +6,10 @@
NEXT
----
+* New publishers pprint_to_stream. Very useful for interactive observing of
+ Oops reports - just hook it up to your source (e.g. via oops_amqp) and
+ off you go. (Robert Collins)
+
0.0.11
------
=== modified file 'README'
--- README 2012-06-26 21:28:11 +0000
+++ README 2012-08-10 01:06:20 +0000
@@ -107,6 +107,9 @@
>>> report['id']
'id 1'
+* The pprint_to_stream publisher will print out reports to a stream after
+pprinting them. This can be very helpful for interactive use.
+
* The related project oops_datedir_repo contains a local disk based repository which
can be used as a publisher.
@@ -133,3 +136,7 @@
For instance::
$ bin/py -m testtools.run oops.tests.test_suite
+
+Alternative you can use the testr command from testrepository::
+
+ $ testr run
=== 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 @@
__all__ = [
'Config',
'convert_result_to_list',
+ 'pprint_to_stream',
'publish_new_only',
'publish_to_many',
'publish_with_fallback',
@@ -38,6 +39,7 @@
from oops.config import Config
from oops.publishers import (
convert_result_to_list,
+ pprint_to_stream,
publish_new_only,
publish_to_many,
publish_with_fallback,
=== 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 @@
__metaclass__ = type
__all__ = [
- 'publish_new_only',
+ 'pprint_to_stream',
+ 'publish_with_fallback',
+ 'publish_to_many',
]
+from hashlib import md5
+from pprint import pformat
+
+
+def pprint_to_stream(stream):
+ """Pretty print reports to stream.
+
+ Reports will be given an id by hashing the report if none is present.
+ """
+ def pprinter(report):
+ report = dict(report)
+ output = pformat(report)
+ if not report.get('id'):
+ report['id'] = md5(output).hexdigest()
+ output = pformat(report)
+ stream.write(output)
+ return [report['id']]
+ return pprinter
+
def publish_new_only(publisher):
"""Wraps a publisher with a check that the report has not had an id set.
=== 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 @@
__metaclass__ = type
+from hashlib import md5
+from pprint import pformat
+from StringIO import StringIO
+
import testtools
from oops import (
convert_result_to_list,
+ pprint_to_stream,
publish_new_only,
publish_to_many,
publish_with_fallback,
@@ -168,3 +173,27 @@
def trueish(report):
return "aaa"
self.assertEqual(["aaa"], convert_result_to_list(trueish)({}))
+
+
+class TestPPrintToStream(testtools.TestCase):
+
+ def test_inherits_id_when_set(self):
+ output = StringIO()
+ publisher = pprint_to_stream(output)
+ published = publisher({'foo': 'bar', 'id': 'quux'})
+ self.assertEqual(['quux'], published)
+
+ def test_returns_pprint_hash(self):
+ output = StringIO()
+ publisher = pprint_to_stream(output)
+ published = publisher({'foo': 'bar'})
+ pprint_value = pformat({'foo': 'bar'})
+ self.assertEqual([md5(pprint_value).hexdigest()], published)
+
+ def test_outputs_pprint(self):
+ output = StringIO()
+ publisher = pprint_to_stream(output)
+ publisher({'foo': 'bar'})
+ self.assertEqual(
+ "{'foo': 'bar', 'id': 'dd63dafcbd4d5b28badfcaf86fb6fcdb'}",
+ output.getvalue())