-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathtest_offline_utils.py
36 lines (27 loc) · 1.25 KB
/
test_offline_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from io import BytesIO
import pytest
import requests
from huggingface_hub.file_download import http_get
from .testing_utils import (
OfflineSimulationMode,
RequestWouldHangIndefinitelyError,
offline,
)
def test_offline_with_timeout():
with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT):
with pytest.raises(RequestWouldHangIndefinitelyError):
requests.request("GET", "https://huggingface.co")
with pytest.raises(requests.exceptions.ConnectTimeout):
requests.request("GET", "https://huggingface.co", timeout=1.0)
with pytest.raises(requests.exceptions.ConnectTimeout):
http_get("https://huggingface.co", BytesIO())
def test_offline_with_connection_error():
with offline(OfflineSimulationMode.CONNECTION_FAILS):
with pytest.raises(requests.exceptions.ConnectionError):
requests.request("GET", "https://huggingface.co")
with pytest.raises(requests.exceptions.ConnectionError):
http_get("https://huggingface.co", BytesIO())
def test_offline_with_datasets_offline_mode_enabled():
with offline(OfflineSimulationMode.HF_HUB_OFFLINE_SET_TO_1):
with pytest.raises(ConnectionError):
http_get("https://huggingface.co", BytesIO())