Beispiel #1
0
 def _run_truncating_file_handle_iter_test(self,
                                           s,
                                           delim=' ',
                                           chunk_size=10):
     tracker = restriction_trackers.OffsetRestrictionTracker(
         restriction_trackers.OffsetRange(0, len(s)))
     handle = io._TruncatingFileHandle(StringIO(s),
                                       tracker,
                                       splitter=io._DelimSplitter(
                                           delim, chunk_size))
     self.assertEqual(s, ''.join(list(handle)))
Beispiel #2
0
 def _run_truncating_file_handle_test(
     self, s, splits, delim=' ', chunk_size=10):
   split_results = []
   next_range = restriction_trackers.OffsetRange(0, len(s))
   for split in list(splits) + [None]:
     tracker = restriction_trackers.OffsetRestrictionTracker(next_range)
     handle = io._TruncatingFileHandle(
         StringIO(s), tracker, splitter=io._DelimSplitter(delim, chunk_size))
     data = ''
     chunk = handle.read(1)
     if split is not None:
       _, next_range = tracker.try_split(split)
     while chunk:
       data += chunk
       chunk = handle.read(7)
     split_results.append(data)
   return split_results