def test_read_all_write_one(self): readers = [] for tmpfilename in self.tmpfilenames: readers.append(TextFileReader(tmpfilename, interval=0.2)) transforms = [PrefixTransform('prefix_1'), PrefixTransform('prefix_2')] outfilename = self.tmpdirname + '/f_out' writers = [TextFileWriter(outfilename)] listener = Listener(readers, transforms, writers) listener.run() out_lines = [] with open(outfilename, 'r') as f: for line in f.readlines(): out_lines.append(line.rstrip()) out_lines.sort() source_lines = [] for f in SAMPLE_DATA: source_lines.extend( ['prefix_2 prefix_1 ' + f for f in SAMPLE_DATA[f]]) source_lines.sort() logging.debug('out: %s, source: %s', out_lines, source_lines) self.assertEqual(out_lines, source_lines)
def test_read_one_write_all(self): readers = TextFileReader(self.tmpfilenames[0]) outfilenames = [ self.tmpdirname + '/' + f for f in ['f1_out', 'f2_out', 'f3_out'] ] writers = [TextFileWriter(ofn) for ofn in outfilenames] listener = Listener(readers=readers, writers=writers) listener.run() for ofn in outfilenames: line_num = 0 with open(ofn, 'r') as f: for line in f.readlines(): self.assertEqual(SAMPLE_DATA['f1'][line_num], line.rstrip()) line_num += 1