@@ -778,6 +778,208 @@ def test_tag_delete_basic(self, runner: CliRunner) -> None:
778
778
api .delete_tag .assert_called_once_with (repo_id = DUMMY_MODEL_ID , tag = "1.0" , repo_type = "model" )
779
779
780
780
781
+ class TestBranchCommands :
782
+ def test_branch_create_basic (self , runner : CliRunner ) -> None :
783
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
784
+ api = api_cls .return_value
785
+ result = runner .invoke (app , ["repo" , "branch" , "create" , DUMMY_MODEL_ID , "dev" ])
786
+ assert result .exit_code == 0
787
+ api_cls .assert_called_once_with (token = None )
788
+ api .create_branch .assert_called_once_with (
789
+ repo_id = DUMMY_MODEL_ID ,
790
+ branch = "dev" ,
791
+ revision = None ,
792
+ repo_type = "model" ,
793
+ exist_ok = False ,
794
+ )
795
+
796
+ def test_branch_create_with_all_options (self , runner : CliRunner ) -> None :
797
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
798
+ api = api_cls .return_value
799
+ result = runner .invoke (
800
+ app ,
801
+ [
802
+ "repo" ,
803
+ "branch" ,
804
+ "create" ,
805
+ DUMMY_MODEL_ID ,
806
+ "dev" ,
807
+ "--repo-type" ,
808
+ "dataset" ,
809
+ "--revision" ,
810
+ "v1.0.0" ,
811
+ "--token" ,
812
+ "my-token" ,
813
+ "--exist-ok" ,
814
+ ],
815
+ )
816
+ assert result .exit_code == 0
817
+ api_cls .assert_called_once_with (token = "my-token" )
818
+ api .create_branch .assert_called_once_with (
819
+ repo_id = DUMMY_MODEL_ID ,
820
+ branch = "dev" ,
821
+ revision = "v1.0.0" ,
822
+ repo_type = "dataset" ,
823
+ exist_ok = True ,
824
+ )
825
+
826
+ def test_branch_delete_basic (self , runner : CliRunner ) -> None :
827
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
828
+ api = api_cls .return_value
829
+ result = runner .invoke (app , ["repo" , "branch" , "delete" , DUMMY_MODEL_ID , "dev" ])
830
+ assert result .exit_code == 0
831
+ api_cls .assert_called_once_with (token = None )
832
+ api .delete_branch .assert_called_once_with (
833
+ repo_id = DUMMY_MODEL_ID ,
834
+ branch = "dev" ,
835
+ repo_type = "model" ,
836
+ )
837
+
838
+ def test_branch_delete_with_all_options (self , runner : CliRunner ) -> None :
839
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
840
+ api = api_cls .return_value
841
+ result = runner .invoke (
842
+ app ,
843
+ [
844
+ "repo" ,
845
+ "branch" ,
846
+ "delete" ,
847
+ DUMMY_MODEL_ID ,
848
+ "dev" ,
849
+ "--repo-type" ,
850
+ "dataset" ,
851
+ "--token" ,
852
+ "my-token" ,
853
+ ],
854
+ )
855
+ assert result .exit_code == 0
856
+ api_cls .assert_called_once_with (token = "my-token" )
857
+ api .delete_branch .assert_called_once_with (
858
+ repo_id = DUMMY_MODEL_ID ,
859
+ branch = "dev" ,
860
+ repo_type = "dataset" ,
861
+ )
862
+
863
+
864
+ class TestRepoMoveCommand :
865
+ def test_repo_move_basic (self , runner : CliRunner ) -> None :
866
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
867
+ api = api_cls .return_value
868
+ result = runner .invoke (app , ["repo" , "move" , DUMMY_MODEL_ID , "new-id" ])
869
+ assert result .exit_code == 0
870
+ api_cls .assert_called_once_with (token = None )
871
+ api .move_repo .assert_called_once_with (
872
+ from_id = DUMMY_MODEL_ID ,
873
+ to_id = "new-id" ,
874
+ repo_type = "model" ,
875
+ )
876
+
877
+ def test_repo_move_with_all_options (self , runner : CliRunner ) -> None :
878
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
879
+ api = api_cls .return_value
880
+ result = runner .invoke (
881
+ app ,
882
+ [
883
+ "repo" ,
884
+ "move" ,
885
+ DUMMY_MODEL_ID ,
886
+ "new-id" ,
887
+ "--repo-type" ,
888
+ "dataset" ,
889
+ "--token" ,
890
+ "my-token" ,
891
+ ],
892
+ )
893
+ assert result .exit_code == 0
894
+ api_cls .assert_called_once_with (token = "my-token" )
895
+ api .move_repo .assert_called_once_with (
896
+ from_id = DUMMY_MODEL_ID ,
897
+ to_id = "new-id" ,
898
+ repo_type = "dataset" ,
899
+ )
900
+
901
+
902
+ class TestRepoSettingsCommand :
903
+ def test_repo_settings_basic (self , runner : CliRunner ) -> None :
904
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
905
+ api = api_cls .return_value
906
+ result = runner .invoke (app , ["repo" , "settings" , DUMMY_MODEL_ID ])
907
+ assert result .exit_code == 0
908
+ api_cls .assert_called_once_with (token = None )
909
+ api .update_repo_settings .assert_called_once_with (
910
+ repo_id = DUMMY_MODEL_ID ,
911
+ gated = None ,
912
+ private = None ,
913
+ xet_enabled = None ,
914
+ repo_type = "model" ,
915
+ )
916
+
917
+ def test_repo_settings_with_all_options (self , runner : CliRunner ) -> None :
918
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
919
+ api = api_cls .return_value
920
+ result = runner .invoke (
921
+ app ,
922
+ [
923
+ "repo" ,
924
+ "settings" ,
925
+ DUMMY_MODEL_ID ,
926
+ "--gated" ,
927
+ "manual" ,
928
+ "--private" ,
929
+ "--repo-type" ,
930
+ "dataset" ,
931
+ "--token" ,
932
+ "my-token" ,
933
+ ],
934
+ )
935
+ assert result .exit_code == 0
936
+ api_cls .assert_called_once_with (token = "my-token" )
937
+ kwargs = api .update_repo_settings .call_args .kwargs
938
+ assert kwargs ["repo_id" ] == DUMMY_MODEL_ID
939
+ assert kwargs ["repo_type" ] == "dataset"
940
+ assert kwargs ["private" ] is True
941
+ assert kwargs ["xet_enabled" ] is None
942
+ assert kwargs ["gated" ] == "manual"
943
+
944
+
945
+ class TestRepoDeleteCommand :
946
+ def test_repo_delete_basic (self , runner : CliRunner ) -> None :
947
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
948
+ api = api_cls .return_value
949
+ result = runner .invoke (app , ["repo" , "delete" , DUMMY_MODEL_ID ])
950
+ assert result .exit_code == 0
951
+ api_cls .assert_called_once_with (token = None )
952
+ api .delete_repo .assert_called_once_with (
953
+ repo_id = DUMMY_MODEL_ID ,
954
+ repo_type = "model" ,
955
+ missing_ok = False ,
956
+ )
957
+
958
+ def test_repo_delete_with_all_options (self , runner : CliRunner ) -> None :
959
+ with patch ("huggingface_hub.cli.repo.get_hf_api" ) as api_cls :
960
+ api = api_cls .return_value
961
+ result = runner .invoke (
962
+ app ,
963
+ [
964
+ "repo" ,
965
+ "delete" ,
966
+ DUMMY_MODEL_ID ,
967
+ "--repo-type" ,
968
+ "dataset" ,
969
+ "--token" ,
970
+ "my-token" ,
971
+ "--missing-ok" ,
972
+ ],
973
+ )
974
+ assert result .exit_code == 0
975
+ api_cls .assert_called_once_with (token = "my-token" )
976
+ api .delete_repo .assert_called_once_with (
977
+ repo_id = DUMMY_MODEL_ID ,
978
+ repo_type = "dataset" ,
979
+ missing_ok = True ,
980
+ )
981
+
982
+
781
983
@contextmanager
782
984
def tmp_current_directory () -> Generator [str , None , None ]:
783
985
with SoftTemporaryDirectory () as tmp_dir :
0 commit comments