

def test_backward_reader(self):
    f = tempfile.TemporaryFile(mode='r+')
    forward_lines = []
    backward_lines = []
    forward_lines = list(f)
    backward_lines = list(read_backwards(f))
    backward_lines.reverse()
    self.assertEqual(forward_lines, backward_lines)
    contents = ['Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do', 'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut', 'enim ad minim veniam, quis nostrud exercitation ullamco laboris', 'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor', 'in reprehenderit in voluptate velit esse cillum dolore eu fugiat', 'nulla pariatur. Excepteur sint occaecat cupidatat non proident,', 'sunt in culpa qui officia deserunt mollit anim id est laborum.']
    for i in range(5):
        for line in contents:
            f.write(('%s\n' % line))
    for bufsize in (1, 5000):
        f.seek(0)
        forward_lines = list(f)
        backward_lines = list(read_backwards(f, bufsize=bufsize))
        backward_lines.reverse()
        self.assertEqual(forward_lines, backward_lines)
        forward_lines = []
        for i in range((2 * len(bufsize))):
            forward_lines.append(f.readline())
        backward_lines = list(read_backwards(f, from_byte=f.tell(), bufsize=bufsize))
        backward_lines.reverse()
        self.assertEqual(forward_lines, backward_lines)
    f.close()
    f = tempfile.TemporaryFile(mode='r+')
    written = '\n'.join(contents)
    f.write(written)
    for from_byte in range(1, len(written)):
        lines = written[:from_byte].split('\n')
        if (lines[(- 1)] == ''):
            lines = lines[:(- 1)]
        append_newline = (written[(from_byte - 1)] == '\n')
        if append_newline:
            lines = ['{0}\n'.format(line) for line in lines]
        else:
            lines[:(- 1)] = ['{0}\n'.format(line) for line in lines[:(- 1)]]
        lines = list(reversed(lines))
        for bufsize in range(1, 30):
            self.assertEqual(list(read_backwards(f, from_byte=from_byte, bufsize=bufsize)), lines)

dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/unit/test_logs_handlers.py TestLogs.test_backward_reader/VarMisuse@180/452 `contents`->`bufsize`