def test_rewind_body_failed_seek(self) -> None: class BadSeek(io.StringIO): def seek(self, offset: int, whence: int = 0) -> NoReturn: raise OSError with pytest.raises(UnrewindableBodyError): rewind_body(BadSeek(), body_pos=2)
def test_rewind_body_failed_seek(self): class BadSeek: def seek(self, pos, offset=0): raise OSError with pytest.raises(UnrewindableBodyError): rewind_body(BadSeek(), body_pos=2)
def test_rewind_body_failed_tell(self): body = io.BytesIO(b"test data") body.read() # Consume body # Simulate failed tell() body_pos = _FAILEDTELL with pytest.raises(UnrewindableBodyError): rewind_body(body, body_pos)
def test_rewind_body_failed_seek(self): class BadSeek(): def seek(self, pos, offset=0): raise IOError with pytest.raises(UnrewindableBodyError): rewind_body(BadSeek(), body_pos=2)
def test_rewind_body_failed_tell(self): body = io.BytesIO(b'test data') body.read() # Consume body # Simulate failed tell() body_pos = _FAILEDTELL with pytest.raises(UnrewindableBodyError): rewind_body(body, body_pos)
def test_rewind_body_bad_position(self): body = io.BytesIO(b"test data") body.read() # Consume body # Pass non-integer position with pytest.raises(ValueError): rewind_body(body, body_pos=None) with pytest.raises(ValueError): rewind_body(body, body_pos=object())
def test_rewind_body_bad_position(self): body = io.BytesIO(b'test data') body.read() # Consume body # Pass non-integer position with pytest.raises(ValueError): rewind_body(body, body_pos=None) with pytest.raises(ValueError): rewind_body(body, body_pos=object())
def test_rewind_body(self): body = io.BytesIO(b"test data") assert body.read() == b"test data" # Assert the file object has been consumed assert body.read() == b"" # Rewind it back to just be b'data' rewind_body(body, 5) assert body.read() == b"data"
def test_rewind_body(self): body = io.BytesIO(b'test data') assert body.read() == b'test data' # Assert the file object has been consumed assert body.read() == b'' # Rewind it back to just be b'data' rewind_body(body, 5) assert body.read() == b'data'
def test_rewind_body(self): body = io.BytesIO(b'test data') self.assertEqual(body.read(), b'test data') # Assert the file object has been consumed self.assertEqual(body.read(), b'') # Rewind it back to just be b'data' rewind_body(body, 5) self.assertEqual(body.read(), b'data')
def test_rewind_body(self): body = io.BytesIO(b'test data') self.assertEqual(body.read(), b'test data') # Assert the file object has been consumed self.assertEqual(body.read(), b'') # Rewind it back to just be b'data' rewind_body(body, 5) self.assertEqual(body.read(), b'data')