2626from huggingface_hub .repository import Repository , is_tracked_with_lfs
2727
2828from .testing_constants import ENDPOINT_STAGING , PASS , USER
29- from .testing_utils import set_write_permission_and_retry
29+ from .testing_utils import set_write_permission_and_retry , with_production_testing
3030
3131
3232REPO_NAME = "repo-{}" .format (int (time .time () * 10e3 ))
@@ -312,35 +312,65 @@ def test_clone_with_repo_name_and_user_namespace(self):
312312 self .assertTrue ("model.bin" in files )
313313
314314 def test_clone_with_repo_name_and_no_namespace (self ):
315- clone = Repository (
316- REPO_NAME ,
315+ self .assertRaises (
316+ OSError ,
317+ Repository ,
318+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
317319 clone_from = REPO_NAME ,
318320 use_auth_token = self ._token ,
319321 git_user = "ci" ,
320322321323 )
322324
323- with clone .commit ("Commit" ):
324- # Create dummy files
325- # one is lfs-tracked, the other is not.
326- with open ("dummy.txt" , "w" ) as f :
327- f .write ("hello" )
328- with open ("model.bin" , "w" ) as f :
329- f .write ("hello" )
325+ def test_clone_with_repo_name_user_and_no_auth_token (self ):
326+ # Create repo
327+ Repository (
328+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
329+ clone_from = f"{ USER } /{ REPO_NAME } " ,
330+ git_user = "ci" ,
331+ 332+ )
330333
331- shutil .rmtree (REPO_NAME )
334+ # Instantiate it without token
335+ Repository (
336+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
337+ clone_from = f"{ USER } /{ REPO_NAME } " ,
338+ git_user = "ci" ,
339+ 340+ )
332341
342+ def test_clone_with_repo_name_org_and_no_auth_token (self ):
343+ # Create repo
333344 Repository (
334345 f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
335- clone_from = REPO_NAME ,
336346 use_auth_token = self ._token ,
347+ clone_from = f"valid_org/{ REPO_NAME } " ,
337348 git_user = "ci" ,
338349339350 )
340351
341- files = os .listdir (f"{ WORKING_REPO_DIR } /{ REPO_NAME } " )
342- self .assertTrue ("dummy.txt" in files )
343- self .assertTrue ("model.bin" in files )
352+ # Instantiate it without token
353+ Repository (
354+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
355+ clone_from = f"valid_org/{ REPO_NAME } " ,
356+ git_user = "ci" ,
357+ 358+ )
359+
360+ @with_production_testing
361+ def test_clone_repo_at_root (self ):
362+ os .environ ["GIT_LFS_SKIP_SMUDGE" ] = "1"
363+ Repository (
364+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
365+ clone_from = "bert-base-cased" ,
366+ )
367+
368+ shutil .rmtree (f"{ WORKING_REPO_DIR } /{ REPO_NAME } " )
369+
370+ Repository (
371+ f"{ WORKING_REPO_DIR } /{ REPO_NAME } " ,
372+ clone_from = "https://huggingface.co/bert-base-cased" ,
373+ )
344374
345375
346376class RepositoryAutoLFSTrackingTest (RepositoryCommonTest ):
@@ -622,12 +652,15 @@ def tearDown(self):
622652 token = self ._token , name = REPO_NAME , repo_type = "dataset"
623653 )
624654 except requests .exceptions .HTTPError :
625- self ._api .delete_repo (
626- token = self ._token ,
627- organization = "valid_org" ,
628- name = REPO_NAME ,
629- repo_type = "dataset" ,
630- )
655+ try :
656+ self ._api .delete_repo (
657+ token = self ._token ,
658+ organization = "valid_org" ,
659+ name = REPO_NAME ,
660+ repo_type = "dataset" ,
661+ )
662+ except requests .exceptions .HTTPError :
663+ pass
631664
632665 shutil .rmtree (
633666 f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " , onerror = set_write_permission_and_retry
@@ -721,7 +754,9 @@ def test_clone_with_repo_name_and_user_namespace(self):
721754 self .assertTrue ("test.py" in files )
722755
723756 def test_clone_with_repo_name_and_no_namespace (self ):
724- clone = Repository (
757+ self .assertRaises (
758+ OSError ,
759+ Repository ,
725760 f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " ,
726761 clone_from = REPO_NAME ,
727762 repo_type = "dataset" ,
@@ -730,21 +765,42 @@ def test_clone_with_repo_name_and_no_namespace(self):
730765731766 )
732767
733- with clone .commit ("Commit" ):
734- for file in os .listdir (DATASET_FIXTURE ):
735- shutil .copyfile (pathlib .Path (DATASET_FIXTURE ) / file , file )
768+ def test_clone_with_repo_name_user_and_no_auth_token (self ):
769+ # Create repo
770+ Repository (
771+ f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " ,
772+ clone_from = f"{ USER } /{ REPO_NAME } " ,
773+ repo_type = "dataset" ,
774+ use_auth_token = self ._token ,
775+ git_user = "ci" ,
776+ 777+ )
736778
737- shutil .rmtree (f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " )
779+ # Instantiate it without token
780+ Repository (
781+ f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " ,
782+ clone_from = f"{ USER } /{ REPO_NAME } " ,
783+ repo_type = "dataset" ,
784+ git_user = "ci" ,
785+ 786+ )
738787
788+ def test_clone_with_repo_name_org_and_no_auth_token (self ):
789+ # Create repo
739790 Repository (
740791 f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " ,
741- clone_from = REPO_NAME ,
742- use_auth_token = self ._token ,
792+ clone_from = f"valid_org/{ REPO_NAME } " ,
743793 repo_type = "dataset" ,
794+ use_auth_token = self ._token ,
744795 git_user = "ci" ,
745796746797 )
747798
748- files = os .listdir (f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " )
749- self .assertTrue ("some_text.txt" in files )
750- self .assertTrue ("test.py" in files )
799+ # Instantiate it without token
800+ Repository (
801+ f"{ WORKING_DATASET_DIR } /{ REPO_NAME } " ,
802+ clone_from = f"valid_org/{ REPO_NAME } " ,
803+ repo_type = "dataset" ,
804+ git_user = "ci" ,
805+ 806+ )
0 commit comments