@@ -1675,9 +1675,40 @@ def test_read_incomplete_read(self):
16751675 def test_read1_incomplete_read (self ):
16761676 self ._test_incomplete_read (self .resp .read1 , expected_none = True )
16771677
1678- def test_readline_incomplete_read (self ):
1678+ def test_readline_incomplete_read_with_complete_line (self ):
1679+ """
1680+ Test that IncompleteRead is raised when readline finishes
1681+ reading a response but the needed content length is not reached.
1682+ """
1683+ resp = self .resp
1684+ content = resp .fp .read ()
1685+ # For this test case, we must ensure that the last byte read
1686+ # will be a newline. There is a different handling of readline
1687+ # not reaching a newline.
1688+ content = content [:- 1 ] + b"\n "
1689+ resp .fp = io .BytesIO (content )
16791690 self ._test_incomplete_read (self .resp .readline , expected_none = True )
16801691
1692+ def test_readline_incomplete_read_with_incomplete_line (self ):
1693+ """
1694+ Test that IncompleteRead is raised when readline is expected
1695+ to read a line fully but a newline is not reached.
1696+ """
1697+ resp = self .resp
1698+ content = resp .fp .read ()
1699+ # Truncate the content to the last newline.
1700+ content = content [:content .rindex (b"\n " ) - 1 ]
1701+ resp .fp = io .BytesIO (content )
1702+ with self .assertRaises (client .IncompleteRead ) as cm :
1703+ while True :
1704+ data = resp .readline ()
1705+ if not data :
1706+ break
1707+ exception = cm .exception
1708+ self .assertEqual (exception .partial , content .split (b"\n " )[- 1 ])
1709+ self .assertIsNone (exception .expected )
1710+ self .assertTrue (resp .isclosed ())
1711+
16811712
16821713class ExtendedReadTestChunked (ExtendedReadTest ):
16831714 """
0 commit comments