-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete folder with commit endpoint (#1163)
* add test * not good implementation * Add tests * delete_folder + doc * clearer error message in case of implicit delete operation
- Loading branch information
Showing
8 changed files
with
211 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
|
||
from huggingface_hub._commit_api import CommitOperationDelete | ||
|
||
|
||
class TestCommitOperationDelete(unittest.TestCase): | ||
def test_implicit_file(self): | ||
self.assertFalse(CommitOperationDelete(path_in_repo="path/to/file").is_folder) | ||
self.assertFalse( | ||
CommitOperationDelete(path_in_repo="path/to/file.md").is_folder | ||
) | ||
|
||
def test_implicit_folder(self): | ||
self.assertTrue(CommitOperationDelete(path_in_repo="path/to/folder/").is_folder) | ||
self.assertTrue( | ||
CommitOperationDelete(path_in_repo="path/to/folder.md/").is_folder | ||
) | ||
|
||
def test_explicit_file(self): | ||
# Weird case: if user explicitly set as file (`is_folder`=False) but path has a | ||
# trailing "/" => user input has priority | ||
self.assertFalse( | ||
CommitOperationDelete( | ||
path_in_repo="path/to/folder/", is_folder=False | ||
).is_folder | ||
) | ||
self.assertFalse( | ||
CommitOperationDelete( | ||
path_in_repo="path/to/folder.md/", is_folder=False | ||
).is_folder | ||
) | ||
|
||
def test_explicit_folder(self): | ||
# No need for the trailing "/" is `is_folder` explicitly passed | ||
self.assertTrue( | ||
CommitOperationDelete( | ||
path_in_repo="path/to/folder", is_folder=True | ||
).is_folder | ||
) | ||
self.assertTrue( | ||
CommitOperationDelete( | ||
path_in_repo="path/to/folder.md", is_folder=True | ||
).is_folder | ||
) | ||
|
||
def test_is_folder_wrong_value(self): | ||
with self.assertRaises(ValueError): | ||
CommitOperationDelete(path_in_repo="path/to/folder", is_folder="any value") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters