Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve rmtree issue on windows #105

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DUMMY_MODEL_ID,
DUMMY_MODEL_ID_REVISION_ONE_SPECIFIC_COMMIT,
require_git_lfs,
set_write_permission_and_retry,
)


Expand Down Expand Up @@ -118,7 +119,9 @@ def setUp(self) -> None:
self.tmp_file_content = "Content of the file"
with open(self.tmp_file, "w+") as f:
f.write(self.tmp_file_content)
self.addCleanup(lambda: shutil.rmtree(self.tmp_dir))
self.addCleanup(
lambda: shutil.rmtree(self.tmp_dir, onerror=set_write_permission_and_retry)
)

def test_upload_file_validation(self):
with self.assertRaises(ValueError, msg="Wrong repo type"):
Expand Down Expand Up @@ -304,7 +307,7 @@ def setUpClass(cls):

def setUp(self):
try:
shutil.rmtree(WORKING_REPO_DIR)
shutil.rmtree(WORKING_REPO_DIR, onerror=set_write_permission_and_retry)
except FileNotFoundError:
pass

Expand Down
3 changes: 2 additions & 1 deletion tests/test_hubmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from huggingface_hub.hub_mixin import ModelHubMixin

from .testing_constants import ENDPOINT_STAGING, PASS, USER
from .testing_utils import set_write_permission_and_retry


REPO_NAME = "mixin-repo-{}".format(int(time.time() * 10e3))
Expand Down Expand Up @@ -59,7 +60,7 @@ class HubMixingCommonTest(unittest.TestCase):
class HubMixingTest(HubMixingCommonTest):
def tearDown(self) -> None:
try:
shutil.rmtree(WORKING_REPO_DIR)
shutil.rmtree(WORKING_REPO_DIR, onerror=set_write_permission_and_retry)
except FileNotFoundError:
pass

Expand Down
3 changes: 2 additions & 1 deletion tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from huggingface_hub.repository import Repository

from .testing_constants import ENDPOINT_STAGING, PASS, USER
from .testing_utils import set_write_permission_and_retry


REPO_NAME = "repo-{}".format(int(time.time() * 10e3))
Expand All @@ -48,7 +49,7 @@ def setUpClass(cls):

def setUp(self):
try:
shutil.rmtree(WORKING_REPO_DIR)
shutil.rmtree(WORKING_REPO_DIR, onerror=set_write_permission_and_retry)
except FileNotFoundError:
pass

Expand Down
6 changes: 6 additions & 0 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import stat
import unittest
from contextlib import contextmanager
from distutils.util import strtobool
Expand Down Expand Up @@ -139,3 +140,8 @@ def offline_socket(*args, **kwargs):
yield
else:
raise ValueError("Please use a value from the OfflineSimulationMode enum.")


def set_write_permission_and_retry(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)