Example #1
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)
Example #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)
Example #3
0
 def _find_left(self, opened_file):
     left = 0
     right = ReadUtils.size_of_opened_file(opened_file)
     while left + 1 < right:
         curr = (left + right) // 2
         line, line_begin, line_end = ReadUtils.get_line_containing_offset(
             opened_file, curr, ReadUtils.STANDARD_BUFFER_SIZE
         )
         groups = self._super_parser.get_ordered_groups(line)
         assert len(groups) <= 1
         if self._investigation_step.compare_with_bound(
             InvestigationStep.LEFT_BOUND, groups
         ) == CompareResult.LT:
             # omit actual line and go right
             left = line_end + 1
         else:
             # going left, omit actual line, but maybe it will be returned
             right = line_begin
     return right
Example #4
0
 def _find_right(self, opened_file):
     left = 0
     right = ReadUtils.size_of_opened_file(opened_file)
     while left + 1 < right:
         curr = (left + right) // 2
         line, line_begin, line_end = ReadUtils.get_line_containing_offset(
             opened_file, curr, ReadUtils.STANDARD_BUFFER_SIZE
         )
         groups = self._super_parser.get_ordered_groups(line)
         assert len(groups) <= 1
         if self._investigation_step.compare_with_bound(InvestigationStep.RIGHT_BOUND, groups)\
                 in [CompareResult.LT, CompareResult.EQ]:
             # go to the end of current line, maybe it will be returned
             left = line_end
         else:
             # going left, current line is not interesting
             right = line_begin - 1
     if right == 0:
         return 0
     _, _, end_offset = ReadUtils.get_line_containing_offset(
         opened_file, right - 1, ReadUtils.STANDARD_BUFFER_SIZE
     )
     return end_offset + 1
Example #5
0
 def _find_right(self, opened_file, value, super_parser):
     return ReadUtils.binary_search_right(
         opened_file, 0, ReadUtils.size_of_opened_file(opened_file), value,
         super_parser)
Example #6
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)
Example #7
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)
Example #8
0
 def _find_right(self, opened_file, value, super_parser):
     return ReadUtils.binary_search_right(
         opened_file, 0, ReadUtils.size_of_opened_file(opened_file), value, super_parser
     )