Пример #1
0
 def test_yieldable_for_new_initialized_buffer_work_space(self):
     """Newly empty buffer work space should not be yieldable."""
     with tempfile.NamedTemporaryFile(delete=False) as t:
         with io.open(t.name, mode="rb") as fp:
             b = BufferWorkSpace(fp, chunk_size=io.DEFAULT_BUFFER_SIZE)
             r = b.yieldable()
             self.assertFalse(r)
     os.unlink(t.name)
    def test_yieldable_for_buffer_space_with_two_new_lines(self):
        """Buffer work space with a two new lines are yieldable."""
        with patch("file_read_backwards.buffer_work_space._get_file_size"
                   ) as _get_file_size_mock:
            fp_mock = Mock()
            _get_file_size_mock.return_value = 1024

            for n in new_lines_bytes:
                b = BufferWorkSpace(fp_mock, chunk_size=io.DEFAULT_BUFFER_SIZE)
                b.read_position = 1024 - (len(n) * 2)
                b.read_buffer = n * 2
                expected_result = True
                r = b.yieldable()
                self.assertEqual(r, expected_result)
    def test_yieldable_for_unexhausted_buffer_space_with_single_new_line(self):
        """Buffer work space with a single new line (with read_position > 0) is not be yieldable."""
        with patch("file_read_backwards.buffer_work_space._get_file_size"
                   ) as _get_file_size_mock:
            fp_mock = Mock()
            _get_file_size_mock.return_value = 1024

            for n in new_lines_bytes:
                b = BufferWorkSpace(fp_mock, chunk_size=io.DEFAULT_BUFFER_SIZE)
                b.read_position = 1024 - len(n)
                b.read_buffer = n
                expected_result = False
                r = b.yieldable()
                self.assertEqual(r, expected_result)
    def test_yieldable_for_fully_read_and_returned_contents_in_buffer_space(
            self):
        """BufferWorkSpace that has been fully read in and returned contents is not yieldable.

        Note: fully read-in and returned is represented by read_position = 0, read_buffer is None.
        """
        with patch("file_read_backwards.buffer_work_space._get_file_size"
                   ) as _get_file_size_mock:
            fp_mock = Mock()
            _get_file_size_mock.return_value = 1024

            for n in new_lines_bytes:
                b = BufferWorkSpace(fp_mock, chunk_size=io.DEFAULT_BUFFER_SIZE)
                b.read_position = 0
                b.read_buffer = None
                r = b.yieldable()
                self.assertFalse(r)
Пример #5
0
    def test_yieldable_for_fully_read_with_unreturned_contents_in_buffer_space(
        self,
    ):
        """Buffer work space that has been fully read in and unreturned contents is yieldable.

        Note: fully read in and unreturned contents is represented by read_position = 0 and read_buffer is not None.
        """
        with patch(
            "file_read_backwards.buffer_work_space._get_file_size"
        ) as _get_file_size_mock:
            fp_mock = Mock()
            _get_file_size_mock.return_value = 1024

            for n in new_lines_bytes:
                b = BufferWorkSpace(fp_mock, chunk_size=io.DEFAULT_BUFFER_SIZE)
                b.read_position = 0
                b.read_buffer = b""
                expected_result = True
                r = b.yieldable()
                self.assertEqual(r, expected_result)