From e201df8eda7f6f79cff8e92ca85f64eec266c114 Mon Sep 17 00:00:00 2001 From: Michael Stephens Date: Wed, 30 Jun 2010 14:27:57 -0400 Subject: [PATCH] include exception data in error stream output --- saucebrush/__init__.py | 5 +++-- saucebrush/filters.py | 8 ++++---- saucebrush/tests/recipes.py | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/saucebrush/__init__.py b/saucebrush/__init__.py index 87bfd56..5abf8b5 100644 --- a/saucebrush/__init__.py +++ b/saucebrush/__init__.py @@ -34,9 +34,10 @@ class Recipe(object): return filters - def reject_record(self, record, message): + def reject_record(self, record, exception): if self.error_stream: - self.error_stream.run([record]) + self.error_stream.run([{'record': record, + 'exception': repr(exception)}]) def run(self, source): # load filters diff --git a/saucebrush/filters.py b/saucebrush/filters.py index 143c41b..7fee37a 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -30,10 +30,10 @@ class Filter(object): raise NotImplementedError('process_record not defined in ' + self.__class__.__name__) - def reject_record(self, record, message): + def reject_record(self, record, exception): recipe = getattr(self, '_recipe') if recipe: - recipe.reject_record(record, message) + recipe.reject_record(record, exception) def attach(self, source, recipe=None): self._recipe = recipe @@ -43,7 +43,7 @@ class Filter(object): if result is not None: yield result except Exception as e: - self.reject_record(record, unicode(e)) + self.reject_record(record, e) class YieldFilter(Filter): @@ -61,7 +61,7 @@ class YieldFilter(Filter): for result in self.process_record(record): yield result except Exception as e: - self.reject_record(record, unicode(e)) + self.reject_record(record, e) class FieldFilter(Filter): diff --git a/saucebrush/tests/recipes.py b/saucebrush/tests/recipes.py index 8b9ecea..f996fe2 100644 --- a/saucebrush/tests/recipes.py +++ b/saucebrush/tests/recipes.py @@ -23,7 +23,9 @@ class RecipeTestCase(unittest.TestCase): saver = Saver() recipe = Recipe(Raiser(), error_stream=saver) recipe.run([{'a': 1}, {'b': 2}]) - self.assertEqual(saver.saved, [{'a': 1}, {'b': 2}]) + + self.assertEqual(saver.saved[0]['record'], {'a': 1}) + self.assertEqual(saver.saved[1]['record'], {'b': 2}) if __name__ == '__main__':