-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* offline mode simulator * add HF_HUB_OFFLINE env var * add tests * doc tweak * Re-align from transformers and @aaugustin cc @lhoestq Co-authored-by: Julien Chaumond <julien@huggingface.co>
- Loading branch information
Showing
5 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters