MCPcopy Index your code
hub / github.com/python/cpython / test_peek

Method test_peek

Lib/test/test_httplib.py:1658–1687  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1656
1657
1658 def test_peek(self):
1659 resp = self.resp
1660 # patch up the buffered peek so that it returns not too much stuff
1661 oldpeek = resp.fp.peek
1662 def mypeek(n=-1):
1663 p = oldpeek(n)
1664 if n >= 0:
1665 return p[:n]
1666 return p[:10]
1667 resp.fp.peek = mypeek
1668
1669 all = []
1670 while True:
1671 # try a short peek
1672 p = resp.peek(3)
1673 if p:
1674 self.assertGreater(len(p), 0)
1675 # then unbounded peek
1676 p2 = resp.peek()
1677 self.assertGreaterEqual(len(p2), len(p))
1678 self.assertStartsWith(p2, p)
1679 next = resp.read(len(p2))
1680 self.assertEqual(next, p2)
1681 else:
1682 next = resp.read()
1683 self.assertFalse(next)
1684 all.append(next)
1685 if not next:
1686 break
1687 self.assertEqual(b"".join(all), self.lines_expected)
1688
1689 def test_readline(self):
1690 resp = self.resp

Callers

nothing calls this directly

Calls 9

assertGreaterMethod · 0.80
assertGreaterEqualMethod · 0.80
assertStartsWithMethod · 0.80
assertFalseMethod · 0.80
peekMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected