def test_parser_ignore(self): """LineGrouper should skip lines to ignore.""" def never(line): return False def ignore_labels(line): return (not line) or line.isspace() or line.startswith('#') lines = ['abc','\n','1','def','#ignore','2'] self.assertEqual(list(LineGrouper(1)(lines)), [['abc'], ['1'],['def'],['#ignore'],['2']]) self.assertEqual(list(LineGrouper(1, ignore=never)(lines)), [[i.strip()] for i in lines]) self.assertEqual(list(LineGrouper(2, ignore=ignore_labels)(lines)), [['abc','1'],['def','2']])
def test_parser(self): """LineGrouper should return n non-blank lines at a time""" good = [ ' \t >abc \n', '\t def\n', '\t\n', '\t >efg \n', 'ghi', ] c = LineGrouper(2) self.assertEqual(list(c(good)), [['>abc', 'def'],['>efg','ghi']]) c = LineGrouper(1) self.assertEqual(list(c(good)), [['>abc'], ['def'],['>efg'],['ghi']]) c = LineGrouper(4) self.assertEqual(list(c(good)), [['>abc', 'def','>efg','ghi']]) #shouldn't work if not evenly divisible c = LineGrouper(3) self.assertRaises(RecordError, list, c(good))