예제 #1
0
 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')
예제 #2
0
 def test_debug_emitter(self):
     with closing(StringIO()) as output:
         de = DebugEmitter(output)
         list(de.attach([1,2,3]))
         self.assertEqual(output.getvalue(), '1\n2\n3\n')
예제 #3
0
 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')
예제 #4
0
from saucebrush.filters import Splitter, PhoneNumberCleaner, FieldMerger, FieldAdder
from saucebrush.emitters import DebugEmitter
import operator
from itertools import count
import saucebrush

data = [{
    'person': {
        'firstname': 'James',
        'lastname': 'Turk'
    },
    'phones': [{
        'phone': '222-222-2222'
    }, {
        'phone': '(202) 333-3321'
    }]
}]

namemerger = FieldMerger({'name': ('firstname', 'lastname')},
                         lambda x, y: ' '.join((x, y)))
phonecleaner = PhoneNumberCleaner(('phone', ))
splitter = Splitter({'person': [namemerger], 'phones': [phonecleaner]})
ider = FieldAdder('id', count())

saucebrush.run_recipe(data, ider, splitter, DebugEmitter())