def test_return_line_with_buffer_space_with_two_new_lines(self):
        """With two new lines as its sole contents, the buffer space is expected to return b''."""
        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 = b""
                r = b.return_line()
                self.assertEqual(r, expected_result)
    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_return_line_with_buffer_space_with_fully_read_in_contents_at_its_last_line(
            self):
        """With some bytestrings in between 2 new lines, expect to have the bytestrings in the middle."""
        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"LastLineYay"
                expected_result = b"LastLineYay"
                r = b.return_line()
                self.assertEqual(r, expected_result)
    def test_return_line_with_buffer_space_with_some_contents_between_two_new_lines(
            self):
        """With some bytestrings in between 2 new lines, expect to have the bytestrings in the middle."""
        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 + b"Something" + n
                expected_result = b"Something"
                r = b.return_line()
                self.assertEqual(r, expected_result)
    def test_has_returned_every_line_with_fully_read_in_and_processed_buffer_space(
            self):
        """BufferWorkSpace that has been fully read in and fully processed has not returned everything.

        Note: not fully read in and some unprocessed buffer is represented by read_position = 0 and read_buffer = 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

            b = BufferWorkSpace(fp_mock, chunk_size=io.DEFAULT_BUFFER_SIZE)
            b.read_position = 0
            b.read_buffer = None
            r = b.has_returned_every_line()
            self.assertTrue(r)
    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)
Пример #8
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)