Example #1
0
 def test_with_file_where_we_need_to_read_more_than_chunk_size(self):
     """When we encounter character that may be part of a new line, we rewind further."""
     with tempfile.NamedTemporaryFile(delete=False) as t:
         t.write(b"abcd\nfg")
     expected_result = (3, 4)
     with io.open(t.name, mode="rb") as fp:
         r = _get_what_to_read_next(
             fp, previously_read_position=7, chunk_size=3
         )
         self.assertEqual(expected_result, r)
     os.unlink(t.name)
Example #2
0
 def test_with_file_with_seven_bytes_of_alphanumeric(self):
     """Test with alpha-numeric contents of size 7 bytes with chunk_size of 3. Expect (4, 3)."""
     with tempfile.NamedTemporaryFile(delete=False) as t:
         t.write(b"abcdefg")
     expected_result = (4, 3)
     with io.open(t.name, mode="rb") as fp:
         r = _get_what_to_read_next(
             fp, previously_read_position=7, chunk_size=3
         )
         self.assertEqual(expected_result, r)
     os.unlink(t.name)
Example #3
0
 def test_with_empty_file(self):
     """Expect (0, 0) when we pass in empty file."""
     with tempfile.NamedTemporaryFile(delete=False) as t:
         pass
     expected_result = (0, 0)
     with io.open(t.name, mode="rb") as fp:
         r = _get_what_to_read_next(
             fp, previously_read_position=0, chunk_size=3
         )
         self.assertEqual(expected_result, r)
     os.unlink(t.name)
Example #4
0
 def test_with_file_with_single_new_line(self):
     """Test file with a single new line with variety of new_lines."""
     for n in new_lines_bytes:
         with tempfile.NamedTemporaryFile(delete=False) as t:
             t.write(n)
         expected_result = (0, len(n))
         chunk_size = len(n) + 1  # chunk size must be greater than len(n)
         with io.open(t.name, mode="rb") as fp:
             r = _get_what_to_read_next(
                 fp, previously_read_position=len(n), chunk_size=chunk_size
             )
             self.assertEqual(r, expected_result)
         os.unlink(t.name)