Skip to content

Commit d15ae13

Browse files
authored
[internal] Remove lfs multipart test (#3471)
* Remove lfs multipart test * fix
1 parent ef2f8b6 commit d15ae13

File tree

2 files changed

+8
-70
lines changed

2 files changed

+8
-70
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,11 +3623,6 @@ def create_repo(
36233623
if provided_space_args:
36243624
warnings.warn(f"Ignoring provided {', '.join(provided_space_args)} because repo_type is not 'space'.")
36253625

3626-
if getattr(self, "_lfsmultipartthresh", None):
3627-
# Testing purposes only.
3628-
# See https://github.com/huggingface/huggingface_hub/pull/733/files#r820604472
3629-
json["lfsmultipartthresh"] = self._lfsmultipartthresh # type: ignore
3630-
36313626
if resource_group_id is not None:
36323627
json["resourceGroupId"] = resource_group_id
36333628

tests/test_hf_api.py

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import pytest
3333

34-
import huggingface_hub.lfs
3534
from huggingface_hub import HfApi, SpaceHardware, SpaceStage, SpaceStorage, constants
3635
from huggingface_hub._commit_api import (
3736
CommitOperationAdd,
@@ -2732,86 +2731,30 @@ def setup_local_clone(self) -> None:
27322731
subprocess.run(["git", "lfs", "track", "*.epub"], check=True, cwd=self.cache_dir)
27332732

27342733
@require_git_lfs
2735-
def test_end_to_end_thresh_6M(self):
2736-
# Little-hack: create repo with defined `_lfsmultipartthresh`. Only for tests purposes
2737-
self._api._lfsmultipartthresh = 6 * 10**6
2734+
def test_git_push_end_to_end(self):
27382735
self.repo_url = self._api.create_repo(repo_id=repo_name())
27392736
self.repo_id = self.repo_url.repo_id
2740-
self._api._lfsmultipartthresh = None
27412737
self.setup_local_clone()
27422738

27432739
subprocess.run(
27442740
["wget", LARGE_FILE_18MB], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cache_dir
27452741
)
27462742
subprocess.run(["git", "add", "*"], check=True, cwd=self.cache_dir)
27472743
subprocess.run(["git", "commit", "-m", "commit message"], check=True, cwd=self.cache_dir)
2748-
2749-
# This will fail as we haven't set up our custom transfer agent yet.
2750-
failed_process = subprocess.run(
2751-
["git", "push"],
2752-
stdout=subprocess.PIPE,
2753-
stderr=subprocess.PIPE,
2754-
cwd=self.cache_dir,
2755-
)
2756-
self.assertEqual(failed_process.returncode, 1)
2757-
self.assertIn('Run "hf lfs-enable-largefiles ./path/to/your/repo"', failed_process.stderr.decode())
2758-
# ^ Instructions on how to fix this are included in the error message.
27592744
subprocess.run(["hf", "lfs-enable-largefiles", self.cache_dir], check=True)
27602745

27612746
start_time = time.time()
27622747
subprocess.run(["git", "push"], check=True, cwd=self.cache_dir)
27632748
print("took", time.time() - start_time)
27642749

27652750
# To be 100% sure, let's download the resolved file
2766-
pdf_url = f"{self.repo_url}/resolve/main/progit.pdf"
2767-
DEST_FILENAME = "uploaded.pdf"
2768-
subprocess.run(
2769-
["wget", pdf_url, "-O", DEST_FILENAME],
2770-
check=True,
2771-
stdout=subprocess.PIPE,
2772-
stderr=subprocess.PIPE,
2773-
cwd=self.cache_dir,
2774-
)
2775-
dest_filesize = (self.cache_dir / DEST_FILENAME).stat().st_size
2776-
assert dest_filesize == 18685041
2777-
2778-
@require_git_lfs
2779-
def test_end_to_end_thresh_16M(self):
2780-
# Here we'll push one multipart and one non-multipart file in the same commit, and see what happens
2781-
# Little-hack: create repo with defined `_lfsmultipartthresh`. Only for tests purposes
2782-
self._api._lfsmultipartthresh = 16 * 10**6
2783-
self.repo_url = self._api.create_repo(repo_id=repo_name())
2784-
self.repo_id = self.repo_url.repo_id
2785-
self._api._lfsmultipartthresh = None
2786-
self.setup_local_clone()
2787-
2788-
subprocess.run(
2789-
["wget", LARGE_FILE_18MB], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cache_dir
2790-
)
2791-
subprocess.run(
2792-
["wget", LARGE_FILE_14MB], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cache_dir
2793-
)
2794-
subprocess.run(["git", "add", "*"], check=True, cwd=self.cache_dir)
2795-
subprocess.run(["git", "commit", "-m", "both files in same commit"], check=True, cwd=self.cache_dir)
2796-
subprocess.run(["hf", "lfs-enable-largefiles", self.cache_dir], check=True)
2797-
2798-
start_time = time.time()
2799-
subprocess.run(["git", "push"], check=True, cwd=self.cache_dir)
2800-
print("took", time.time() - start_time)
2801-
2802-
def test_upload_lfs_file_multipart(self):
2803-
"""End to end test to check upload an LFS file using multipart upload works."""
2804-
self._api._lfsmultipartthresh = 16 * 10**6
2805-
self.repo_id = self._api.create_repo(repo_id=repo_name()).repo_id
2806-
self._api._lfsmultipartthresh = None
2807-
2808-
with patch.object(
2809-
huggingface_hub.lfs,
2810-
"_upload_parts_iteratively",
2811-
wraps=huggingface_hub.lfs._upload_parts_iteratively,
2812-
) as mock:
2813-
self._api.upload_file(repo_id=self.repo_id, path_or_fileobj=b"0" * 18 * 10**6, path_in_repo="lfs.bin")
2814-
mock.assert_called_once() # It used multipart upload
2751+
with SoftTemporaryDirectory() as tmp_dir:
2752+
filepath = hf_hub_download(
2753+
repo_id=self.repo_id,
2754+
filename="progit.pdf",
2755+
cache_dir=tmp_dir,
2756+
)
2757+
assert Path(filepath).stat().st_size == 18685041
28152758

28162759

28172760
class ParseHFUrlTest(unittest.TestCase):

0 commit comments

Comments
 (0)