mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import importlib
|
||||
import io
|
||||
|
||||
import pytest
|
||||
import requests as rq
|
||||
|
||||
from unshackle.core.session import RnetSession
|
||||
@@ -60,57 +59,6 @@ def test_each_session_kind_gets_its_transport():
|
||||
assert dl.transport_for(transport) is transport
|
||||
|
||||
|
||||
def test_requests_transport_has_no_retries_and_no_record():
|
||||
session = rq.Session()
|
||||
view = dl.transport_for(session).session
|
||||
assert view is not session
|
||||
assert view.record_request is False
|
||||
assert all(adapter.max_retries.total == 0 for adapter in view.adapters.values())
|
||||
|
||||
|
||||
class _RnetSession(RnetSession):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.calls: list[dict] = []
|
||||
|
||||
def get(self, url, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
return _Response()
|
||||
|
||||
|
||||
def test_rnet_transport_turns_retries_and_record_off():
|
||||
session = _RnetSession()
|
||||
dl.transport_for(session).get("http://127.0.0.1:1/a")
|
||||
assert session.calls[0]["max_retries"] == 0
|
||||
assert session.calls[0]["record_request"] is False
|
||||
assert session.calls[0]["stream"] is True
|
||||
|
||||
|
||||
def test_requests_body_reads_raw_and_read1_only_while_racing():
|
||||
response = _Response({"Content-Length": "6"})
|
||||
body = dl.RequestsBody(response, raw=True)
|
||||
racing = iter([True, False, False])
|
||||
assert b"".join(body.chunks(2, lambda: next(racing))) == b"abcdef"
|
||||
assert response.raw.calls == ["read1", "read", "read"]
|
||||
|
||||
|
||||
class _Transport(dl.Transport):
|
||||
def __init__(self):
|
||||
self.response = _Response({"Content-Length": "6"})
|
||||
|
||||
def get(self, url, **kwargs):
|
||||
return dl.RequestsBody(self.response, raw=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("claimed, expected", [(None, {"read"}), (lambda: False, {"read1"})])
|
||||
def test_download_reads_read1_only_for_a_claimable_segment(tmp_path, claimed, expected):
|
||||
transport = _Transport()
|
||||
events = dl.download("http://127.0.0.1:1/a", tmp_path / "a.bin", transport, claimed=claimed, racing=lambda: True)
|
||||
list(events)
|
||||
assert (tmp_path / "a.bin").read_bytes() == b"abcdef"
|
||||
assert set(transport.response.raw.calls) == expected
|
||||
|
||||
|
||||
def test_an_encoded_body_goes_through_iter_content():
|
||||
response = _Response({"content-encoding": "gzip", "Content-Length": "6"})
|
||||
body = dl.RequestsBody(response, raw=True)
|
||||
@@ -118,11 +66,3 @@ def test_an_encoded_body_goes_through_iter_content():
|
||||
assert body.content_length == 0
|
||||
assert list(body.chunks(2, None)) == [b"abcdef"]
|
||||
assert response.raw.calls == []
|
||||
|
||||
|
||||
def test_another_session_kind_is_read_with_iter_content_and_a_timeout():
|
||||
session = _Session()
|
||||
transport = dl.transport_for(session)
|
||||
assert transport.session is session
|
||||
assert list(transport.get("http://127.0.0.1:1/a").chunks(2, None)) == [b"abcdef"]
|
||||
assert session.calls[0]["timeout"] == (dl.CONNECT_TIMEOUT, dl.READ_TIMEOUT)
|
||||
|
||||
Reference in New Issue
Block a user