-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up utils.hub using the latest from hf_hub #18857
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ | |
|
||
import os | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
import transformers.models.bart.tokenization_bart | ||
from transformers import AutoConfig, logging | ||
from huggingface_hub.utils import are_progress_bars_disabled | ||
from transformers import logging | ||
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context | ||
from transformers.utils.logging import disable_progress_bar, enable_progress_bar | ||
|
||
|
@@ -126,14 +126,8 @@ def test_advisory_warnings(self): | |
|
||
|
||
def test_set_progress_bar_enabled(): | ||
TINY_MODEL = "hf-internal-testing/tiny-random-distilbert" | ||
with patch("tqdm.auto.tqdm") as mock_tqdm: | ||
disable_progress_bar() | ||
_ = AutoConfig.from_pretrained(TINY_MODEL, force_download=True) | ||
mock_tqdm.assert_not_called() | ||
disable_progress_bar() | ||
assert are_progress_bars_disabled() | ||
|
||
mock_tqdm.reset_mock() | ||
|
||
enable_progress_bar() | ||
_ = AutoConfig.from_pretrained(TINY_MODEL, force_download=True) | ||
mock_tqdm.assert_called() | ||
enable_progress_bar() | ||
assert not are_progress_bars_disabled() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not manage to adapt this test with mock since:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In You can have a look here for the setup and here for a test where tqdm is enabled. However from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And in general, are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No they're not used anywhere now (we do use tqdm in other places, so should switch to the one in logging, but probably for another PR). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here to be more precise you can use
except LocalEntryNotFoundError
.And since the newly introduced exception is defined as
(EntryNotFoundError, FileNotFoundError, ValueError)
, you will never catch it because you catchEntryNotFoundError
line 382 above.In the end, I suggest to use
except LocalEntryNotFoundError:
instead ofexcept ValueError:
and to reorder theexcept (...)
.(Here is a link to the doc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Will adapt.