def test_reverse_readlines(create_file, line_pattern): # Given no_lines = 10000 lines = [line_pattern.format(n=i).encode('utf-8') for i in list(range(0, no_lines))] filename = create_file(filename='samplefile.log', lines=lines) expected = [line_pattern.format(n=no_lines - i - 1) for i in list(range(0, no_lines))] for i, v in enumerate(expected): if not isinstance(v, text_type): expected[i] = text_type(v, errors='replace') # When actual = list(sut.reverse_readlines(filename, block_size=1024)) # Then assert expected == actual
def test_reverse_readlines(create_file, line_pattern): # Given no_lines = 10000 filename = create_file( filename='samplefile.log', lines=[line_pattern.format(n=i) for i in range(0, no_lines)]) expected = [ line_pattern.format(n=no_lines - i - 1) for i in range(0, no_lines) ] # When actual = list(sut.reverse_readlines(filename, buf_size=1024)) # Then assert expected == actual
def test_reverse_readlines(create_file, line_pattern): # Given no_lines = 10000 lines = [line_pattern.format(n=i).encode('utf-8') for i in list(range(0, no_lines))] filename = create_file(filename='samplefile.log', lines=lines) expected = [line_pattern.format(n=no_lines - i - 1) for i in list(range(0, no_lines))] for i, v in enumerate(expected): if not isinstance(v, text_type): expected[i] = text_type(v, errors='replace') # When actual = list(sut.reverse_readlines(filename, block_size=1024)) # Then assert expected == actual