示例#1
0
 def _get_sample_offset(self, line_num):
     """
     Returns the correct offset of line 'line_num'
     referring to the file a_few_lines.log construction.
     Be careful when modifying a_few_lines.log.
     """
     assert line_num <= self._count_lines_in_file(
         TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME))
     return line_num * AFewLinesLogParams.SINGLE_LINE_LENGTH
示例#2
0
 def test_getting_line_by_offset_basic(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         read_line = ReadUtils._read_entire_line(fh, 2, 10)
         assert read_line == ('aaa-0-bbb', 0, 9)
         read_line = ReadUtils._read_entire_line(fh, 2, 200)
         assert read_line == ('aaa-0-bbb', 0, 9)
         read_line = ReadUtils._read_entire_line(fh, 42, 10)
         assert read_line == ('aaa-4-bbb', 40, 49)
         read_line = ReadUtils._read_entire_line(fh, 99, 10)
         assert read_line == ('aaa-9-bbb', 90, 99)
示例#3
0
 def test_getting_line_by_offset_basic(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         read_line = ReadUtils._read_entire_line(fh, 2, 10)
         assert read_line == ('aaa-0-bbb', 0, 9)
         read_line = ReadUtils._read_entire_line(fh, 2, 200)
         assert read_line == ('aaa-0-bbb', 0, 9)
         read_line = ReadUtils._read_entire_line(fh, 42, 10)
         assert read_line == ('aaa-4-bbb', 40, 49)
         read_line = ReadUtils._read_entire_line(fh, 99, 10)
         assert read_line == ('aaa-9-bbb', 90, 99)
示例#4
0
 def test_getting_line_by_offset_huge(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         for j in six.moves.range(1, 120, 7):
             for i in six.moves.range(100):
                 assert ReadUtils.get_line_containing_offset(fh, i, j) == \
                        AFewLinesLogParams.get_line_with_borders(i)
示例#5
0
 def test_getting_line_by_offset_huge(self):
     with open(TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)) as fh:
         for j in six.moves.range(1, 120, 7):
             for i in six.moves.range(100):
                 assert ReadUtils.get_line_containing_offset(fh, i, j) == \
                        AFewLinesLogParams.get_line_with_borders(i)
示例#6
0
 def test_yield_nothing_when_offset_is_zero(self):
     log_file_path = TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)
     offset = 0
     self._run_reverse_and_check_results(log_file_path, [offset], 0)
示例#7
0
 def test_file_size_as_offset(self):
     log_file_path = TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)
     file_size_as_offset = os.path.getsize(log_file_path)
     self._run_reverse_and_check_results(
         log_file_path, [file_size_as_offset],
         self._count_lines_in_file(log_file_path))
示例#8
0
 def _sample_call_with_specified_bufsize(self, bufsize):
     log_file_path = TestPaths.get_file_path(AFewLinesLogParams.FILE_NAME)
     how_many_lines = 7
     offset = self._get_sample_offset(how_many_lines)
     self._run_reverse_and_check_results(log_file_path, [offset, bufsize],
                                         how_many_lines)