Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c1dba111
Unverified
Commit
c1dba111
authored
Jul 28, 2023
by
Lucain
Committed by
GitHub
Jul 28, 2023
Browse files
Add test when downloading from gated repo (#25039)
parent
6232c380
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
tests/utils/test_hub_utils.py
tests/utils/test_hub_utils.py
+13
-0
No files found.
tests/utils/test_hub_utils.py
View file @
c1dba111
...
...
@@ -36,6 +36,9 @@ RANDOM_BERT = "hf-internal-testing/tiny-random-bert"
CACHE_DIR
=
os
.
path
.
join
(
TRANSFORMERS_CACHE
,
"models--hf-internal-testing--tiny-random-bert"
)
FULL_COMMIT_HASH
=
"9b8c223d42b2188cb49d29af482996f9d0f3e5a6"
GATED_REPO
=
"hf-internal-testing/dummy-gated-model"
README_FILE
=
"README.md"
class
GetFromCacheTests
(
unittest
.
TestCase
):
def
test_cached_file
(
self
):
...
...
@@ -124,3 +127,13 @@ class GetFromCacheTests(unittest.TestCase):
self
.
assertEqual
(
get_file_from_repo
(
tmp_dir
,
"a.txt"
),
str
(
filename
))
self
.
assertIsNone
(
get_file_from_repo
(
tmp_dir
,
"b.txt"
))
def
test_get_file_gated_repo
(
self
):
"""Test download file from a gated repo fails with correct message when not authenticated."""
with
self
.
assertRaisesRegex
(
EnvironmentError
,
"You are trying to access a gated repo."
):
cached_file
(
GATED_REPO
,
README_FILE
,
use_auth_token
=
False
)
def
test_has_file_gated_repo
(
self
):
"""Test check file existence from a gated repo fails with correct message when not authenticated."""
with
self
.
assertRaisesRegex
(
EnvironmentError
,
"is a gated repository"
):
has_file
(
GATED_REPO
,
README_FILE
,
use_auth_token
=
False
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment