Skip to content

Instantly share code, notes, and snippets.

@elliott-beach
Created September 2, 2017 02:51
Show Gist options
  • Select an option

  • Save elliott-beach/d17e2af653b71c97174c53f86e67214b to your computer and use it in GitHub Desktop.

Select an option

Save elliott-beach/d17e2af653b71c97174c53f86e67214b to your computer and use it in GitHub Desktop.
Converted to python3 / BytesIO form, the tests pass
import unittest
import requests
from io import BytesIO
print(requests.__file__)
class TestIterLines(unittest.TestCase):
def iter_lines_response(self, chunk_size, delimiter=None):
response = requests.Response()
response.raw = BytesIO(b'01\r\n45')
gen = response.iter_lines(chunk_size=chunk_size, delimiter=delimiter)
result = list(gen)
self.assertEqual(result, [b'01', b'45'])
def test_splitlines_before_delimiter(self): self.iter_lines_response(2)
def test_splitlines_in_delimiter(self): self.iter_lines_response(3)
def test_splitlines_after_delimiter(self): self.iter_lines_response(4)
def test_splitlines_in_line(self): self.iter_lines_response(5)
def test_split_before_delimiter(self): self.iter_lines_response(2, b'\r\n')
def test_split_in_delimiter(self): self.iter_lines_response(3, b'\r\n')
def test_split_after_delimiter(self): self.iter_lines_response(4, b'\r\n')
def test_split_in_line(self): self.iter_lines_response(5, b'\r\n')
# all pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment