Skip to content

Commit

Permalink
dev(narugo): better test for new function, with 413 error covered
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Jul 28, 2024
1 parent 5612301 commit c390e97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hfutils/operate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def list_all_with_pattern(
except HfHubHTTPError as err:
if err.response.status_code == 413:
new_batch_size = max(1, int(round(batch_size * batch_factor)))
logging.info(f'Reducing batch size {batch_size} --> {new_batch_size} ...')
logging.warning(f'Reducing batch size {batch_size} --> {new_batch_size} ...')
batch_size = new_batch_size
continue
raise

Check warning on line 202 in hfutils/operate/base.py

View check run for this annotation

Codecov / codecov/patch

hfutils/operate/base.py#L202

Added line #L202 was not covered by tests
Expand Down
31 changes: 30 additions & 1 deletion test/operate/test_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from natsort import natsorted

from hfutils.operate import list_files_in_repository
from hfutils.operate import list_files_in_repository, list_all_with_pattern

should_not_exists = [
'.gitignore',
Expand Down Expand Up @@ -120,3 +120,32 @@ def test_list_files_in_repository_large(self):

def test_list_files_in_repository_repo_not_exist(self):
assert list_files_in_repository('deepghs/highres_datasets', repo_type='model') == []

def test_list_all_with_pattern(self):
vs = natsorted([
item.path for item in
list_all_with_pattern(
'deepghs/danbooru_newest',
repo_type='dataset',
pattern='images/*',
)
])
assert vs == natsorted([
*[f'images/0{i:03d}.tar' for i in range(1000)],
*[f'images/0{i:03d}.json' for i in range(1000)],
])

def test_list_all_with_pattern_with_large_startup(self):
vs = natsorted([
item.path for item in
list_all_with_pattern(
'deepghs/danbooru_newest',
repo_type='dataset',
pattern='images/*',
startup_batch=1500,
)
])
assert vs == natsorted([
*[f'images/0{i:03d}.tar' for i in range(1000)],
*[f'images/0{i:03d}.json' for i in range(1000)],
])

0 comments on commit c390e97

Please sign in to comment.