|
31 | 31 |
|
32 | 32 | import pytest |
33 | 33 |
|
34 | | -import huggingface_hub.lfs |
35 | 34 | from huggingface_hub import HfApi, SpaceHardware, SpaceStage, SpaceStorage, constants |
36 | 35 | from huggingface_hub._commit_api import ( |
37 | 36 | CommitOperationAdd, |
@@ -2732,86 +2731,30 @@ def setup_local_clone(self) -> None: |
2732 | 2731 | subprocess.run(["git", "lfs", "track", "*.epub"], check=True, cwd=self.cache_dir) |
2733 | 2732 |
|
2734 | 2733 | @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): |
2738 | 2735 | self.repo_url = self._api.create_repo(repo_id=repo_name()) |
2739 | 2736 | self.repo_id = self.repo_url.repo_id |
2740 | | - self._api._lfsmultipartthresh = None |
2741 | 2737 | self.setup_local_clone() |
2742 | 2738 |
|
2743 | 2739 | subprocess.run( |
2744 | 2740 | ["wget", LARGE_FILE_18MB], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cache_dir |
2745 | 2741 | ) |
2746 | 2742 | subprocess.run(["git", "add", "*"], check=True, cwd=self.cache_dir) |
2747 | 2743 | 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. |
2759 | 2744 | subprocess.run(["hf", "lfs-enable-largefiles", self.cache_dir], check=True) |
2760 | 2745 |
|
2761 | 2746 | start_time = time.time() |
2762 | 2747 | subprocess.run(["git", "push"], check=True, cwd=self.cache_dir) |
2763 | 2748 | print("took", time.time() - start_time) |
2764 | 2749 |
|
2765 | 2750 | # 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 |
2815 | 2758 |
|
2816 | 2759 |
|
2817 | 2760 | class ParseHFUrlTest(unittest.TestCase): |
|
0 commit comments