MCPcopy Create free account
hub / github.com/apify/impit / test_iter_bytes

Method test_iter_bytes

impit-python/test/async_client_test.py:567–588  ·  view source on GitHub ↗
(self, browser: Browser)

Source from the content-addressed store, hash-verified

565 assert response.is_stream_consumed is True # type: ignore[unreachable] # Mypy can't detect a change of state
566
567 async def test_iter_bytes(self, browser: Browser) -> None:
568 impit = AsyncClient(browser=browser)
569
570 async with impit.stream('GET', get_httpbin_url('/')) as response:
571 assert response.status_code == 200
572 assert response.is_closed is False
573 assert response.is_stream_consumed is False
574
575 content = b''.join([item async for item in response.aiter_bytes()])
576
577 assert isinstance(content, bytes)
578 assert len(content) > 0
579
580 # After `iter_bytes`` we should get an error since `content` and `text` are not cached
581 with pytest.raises(StreamConsumed):
582 _ = response.text
583
584 with pytest.raises(StreamConsumed):
585 _ = response.content
586
587 assert response.is_closed is True
588 assert response.is_stream_consumed is True # type: ignore[unreachable] # Mypy can't detect a change of state
589
590 async def test_response_with_context_manager(self, browser: Browser) -> None:
591 impit = AsyncClient(browser=browser)

Callers

nothing calls this directly

Calls 4

streamMethod · 0.95
AsyncClientClass · 0.90
get_httpbin_urlFunction · 0.85
aiter_bytesMethod · 0.80

Tested by

no test coverage detected