From a6574ecba7931306e2a60fdf7da62f09f2326ad6 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sun, 21 Feb 2010 14:20:48 -0500 Subject: [PATCH] basic emitter tests --- saucebrush/tests/__init__.py | 2 ++ saucebrush/tests/emitters.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 saucebrush/tests/emitters.py diff --git a/saucebrush/tests/__init__.py b/saucebrush/tests/__init__.py index d27f9e5..1a891c9 100644 --- a/saucebrush/tests/__init__.py +++ b/saucebrush/tests/__init__.py @@ -1,9 +1,11 @@ import unittest from saucebrush.tests.filters import FilterTestCase from saucebrush.tests.sources import SourceTestCase +from saucebrush.tests.emitters import EmitterTestCase filter_suite = unittest.TestLoader().loadTestsFromTestCase(FilterTestCase) source_suite = unittest.TestLoader().loadTestsFromTestCase(SourceTestCase) +emitter_suite = unittest.TestLoader().loadTestsFromTestCase(EmitterTestCase) if __name__ == '__main__': unittest.main() diff --git a/saucebrush/tests/emitters.py b/saucebrush/tests/emitters.py new file mode 100644 index 0000000..9d6496d --- /dev/null +++ b/saucebrush/tests/emitters.py @@ -0,0 +1,25 @@ +import unittest +from cStringIO import StringIO +from saucebrush.emitters import DebugEmitter, CSVEmitter + +class EmitterTestCase(unittest.TestCase): + + def setUp(self): + self.output = StringIO() + + def test_debug_emitter(self): + de = DebugEmitter(self.output) + data = de.attach([1,2,3]) + for _ in data: + pass + self.assertEquals(self.output.getvalue(), '1\n2\n3\n') + + def test_csv_emitter(self): + ce = CSVEmitter(self.output, ('x','y','z')) + data = ce.attach([{'x':1,'y':2,'z':3}, {'x':5, 'y':5, 'z':5}]) + for _ in data: + pass + self.assertEquals(self.output.getvalue(), 'x,y,z\r\n1,2,3\r\n5,5,5\r\n') + +if __name__ == '__main__': + unittest.main()