Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
working-directory: ./src # For code coverage to work
run: |
source ../.venv/bin/activate
PYTEST="python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none --reruns 8 --reruns-delay 2 --only-rerun '(OSError|FileNotFoundError|Timeout|HTTPError.*409|HTTPError.*502|HTTPError.*504)'"
PYTEST="python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none --reruns 3 --reruns-delay 2 --only-rerun '(OSError|FileNotFoundError|Timeout|HTTPError.*409|HTTPError.*502|HTTPError.*504)'"

case "${{ matrix.test_name }}" in

Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
"--cov=./huggingface_hub",
"--cov-report=xml:../coverage.xml",
"--vcr-record=none",
"--reruns", "8",
"--reruns", "3",
"--reruns-delay", "2",
"--only-rerun", "(OSError|FileNotFoundError|Timeout|HTTPError.*409|HTTPError.*502|HTTPError.*504)",
"../tests"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import warnings
from collections.abc import Iterator
from datetime import datetime, timezone
Expand Down Expand Up @@ -357,6 +358,7 @@ def test_copy_files_bucket_to_same_bucket_file(api: HfApi, bucket_write: str, tm

def test_copy_files_bucket_to_different_bucket_folder(api: HfApi, bucket_write: str, bucket_write_2: str, tmp_path):
api.batch_bucket_files(bucket_write, add=[(b"a", "logs/a.txt"), (b"b", "logs/sub/b.txt"), (b"c", "other/c.txt")])
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back

api.copy_files(
f"hf://buckets/{bucket_write}/logs",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,7 @@ def test_list_and_delete_lfs_files(self, api: HfApi, repo_factory: RepoFactory)
)

# List LFS files
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back
lfs_files = [file for file in api.list_lfs_files(repo_id=repo_id)]
assert len(lfs_files) == 3
assert {file.filename for file in lfs_files} == {
Expand All @@ -3150,6 +3151,7 @@ def test_list_and_delete_lfs_files(self, api: HfApi, repo_factory: RepoFactory)

# Permanently delete LFS files
api.permanently_delete_lfs_files(repo_id=repo_id, lfs_files=lfs_files_on_main)
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back

# LFS file from the branch remains
lfs_files = [file for file in api.list_lfs_files(repo_id=repo_id)]
Expand Down Expand Up @@ -4053,6 +4055,7 @@ def test_access_requests_normal_usage(self, api: HfApi) -> None:

# Grant access to a user
api.grant_access(self.repo_id, OTHER_USER)
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back

# User is in accepted list
requests = list(api.list_accepted_access_requests(self.repo_id))
Expand All @@ -4066,6 +4069,7 @@ def test_access_requests_normal_usage(self, api: HfApi) -> None:

# Cancel access
api.cancel_access_request(self.repo_id, OTHER_USER)
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back
requests = list(api.list_accepted_access_requests(self.repo_id))
assert len(requests) == 0 # not accepted anymore
requests = list(api.list_pending_access_requests(self.repo_id))
Expand All @@ -4074,6 +4078,7 @@ def test_access_requests_normal_usage(self, api: HfApi) -> None:

# Reject access
api.reject_access_request(self.repo_id, OTHER_USER, rejection_reason="This is a rejection reason")
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back
requests = list(api.list_pending_access_requests(self.repo_id))
assert len(requests) == 0 # not pending anymore
requests = list(api.list_rejected_access_requests(self.repo_id))
Expand All @@ -4082,6 +4087,7 @@ def test_access_requests_normal_usage(self, api: HfApi) -> None:

# Accept again
api.accept_access_request(self.repo_id, OTHER_USER)
time.sleep(1) # hub-ci: give the server time to propagate the write before reading it back
requests = list(api.list_accepted_access_requests(self.repo_id))
assert len(requests) == 1
assert requests[0].username == OTHER_USER
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils_strict_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ def __repr__(self):
assert repr(obj) == "CustomRepr(x=1)"


@pytest.fixture
def isolated_jedi_cache(tmp_path, monkeypatch):
# parso writes its on-disk cache non-atomically => xdist workers sharing ~/.cache/jedi can read a half-written file
monkeypatch.setattr(jedi.settings, "cache_directory", str(tmp_path))


@pytest.mark.usefixtures("isolated_jedi_cache")
def test_autocompletion_attribute_without_kwargs():
# Create a sample script
completions = jedi.Script("""
Expand All @@ -581,6 +588,7 @@ class Config:
assert "hidden_size" in completion_names


@pytest.mark.usefixtures("isolated_jedi_cache")
def test_autocompletion_attribute_with_kwargs():
# Create a sample script
completions = jedi.Script("""
Expand All @@ -602,6 +610,7 @@ class Config:
assert "foo" not in completion_names # not an official arg


@pytest.mark.usefixtures("isolated_jedi_cache")
def test_autocompletion_init_without_kwargs():
# Create a sample script
completions = jedi.Script("""
Expand All @@ -621,6 +630,7 @@ class Config:
assert "hidden_size=" in completion_names


@pytest.mark.usefixtures("isolated_jedi_cache")
def test_autocompletion_init_with_kwargs():
# Create a sample script
completions = jedi.Script("""
Expand Down
Loading