From b69031cab50988728de1d6dde9a19af807b78798 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 30 Nov 2025 22:44:45 +0100 Subject: [PATCH 1/3] tests: github xfail on broken connection and rate limit --- upath/tests/implementations/test_github.py | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/upath/tests/implementations/test_github.py b/upath/tests/implementations/test_github.py index 5bf3553c..994df83f 100644 --- a/upath/tests/implementations/test_github.py +++ b/upath/tests/implementations/test_github.py @@ -1,3 +1,4 @@ +import functools import os import platform import sys @@ -17,6 +18,56 @@ ) +def has_internet_connection(): + import requests + + try: + requests.get("http://example.com") + except requests.exceptions.ConnectionError: + return False + else: + return True + + +def xfail_on_github_rate_limit(func): + """ + Method decorator to mark test as xfail when GitHub rate limit is exceeded. + """ + + @functools.wraps(func) + def wrapped_method(self, *args, **kwargs): + import requests + + try: + return func(self, *args, **kwargs) + except AssertionError as e: + if "nodename nor servname provided, or not known" in str(e): + pytest.xfail(reason="No internet connection") + raise + except requests.exceptions.ConnectionError: + pytest.xfail(reason="No internet connection") + except Exception as e: + if "rate limit exceeded" in str(e): + pytest.xfail("GitHub API rate limit exceeded") + else: + raise + + return wrapped_method + + +def wrap_github_rate_limit_check(cls): + """ + Class decorator to wrap all test methods with the + xfail_on_github_rate_limit decorator. + """ + for attr_name in dir(cls): + if attr_name.startswith("test_"): + orig_method = getattr(cls, attr_name) + setattr(cls, attr_name, xfail_on_github_rate_limit(orig_method)) + return cls + + +@wrap_github_rate_limit_check class TestUPathGitHubPath(BaseTests): """ Unit-tests for the GitHubPath implementation of UPath. From 0b480d60daa8c76155c1b84a111a4eee7dc53009 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 30 Nov 2025 22:45:52 +0100 Subject: [PATCH 2/3] tests: huggingface xfail on broken connection --- upath/tests/implementations/test_hf.py | 41 +++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/upath/tests/implementations/test_hf.py b/upath/tests/implementations/test_hf.py index 02dd2c6b..813e3648 100644 --- a/upath/tests/implementations/test_hf.py +++ b/upath/tests/implementations/test_hf.py @@ -1,3 +1,5 @@ +import functools + import pytest from fsspec import get_filesystem_class @@ -12,13 +14,44 @@ pytestmark = pytest.mark.skip +def xfail_on_hf_service_unavailable(func): + """ + Method decorator to mark test as xfail when HuggingFace service is unavailable. + """ + from httpx import HTTPStatusError + + @functools.wraps(func) + def wrapped_method(self, *args, **kwargs): + try: + return func(self, *args, **kwargs) + except HTTPStatusError as err: + if err.response.status_code == 503: + pytest.xfail("HuggingFace API not reachable") + raise + + return wrapped_method + + def test_hfpath(): path = UPath("hf://HuggingFaceTB/SmolLM2-135M") assert isinstance(path, HfPath) - assert path.exists() - - -class TestUPathHttp(BaseTests): + try: + assert path.exists() + except AssertionError: + from httpx import ConnectError + from huggingface_hub import HfApi + + try: + HfApi().repo_info("HuggingFaceTB/SmolLM2-135M") + except ConnectError: + pytest.xfail("No internet connection") + except Exception as err: + if "Service Unavailable" in str(err): + pytest.xfail("HuggingFace API not reachable") + raise + + +class TestUPathHf(BaseTests): @pytest.fixture(autouse=True, scope="function") def path(self, hf_fixture_with_readonly_mocked_hf_api): self.path = UPath(hf_fixture_with_readonly_mocked_hf_api) From 9a347701ed24f52d12dc97e65c218fa6a692cf46 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 30 Nov 2025 22:46:20 +0100 Subject: [PATCH 3/3] tests: http xfail on broken connection --- upath/tests/implementations/test_http.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/upath/tests/implementations/test_http.py b/upath/tests/implementations/test_http.py index 25fe15aa..9ca5d10e 100644 --- a/upath/tests/implementations/test_http.py +++ b/upath/tests/implementations/test_http.py @@ -17,7 +17,19 @@ pytestmark = pytest.mark.skip -def test_httppath(): +@pytest.fixture +def internet_connection(): + import requests + + try: + requests.get("http://example.com") + except requests.exceptions.ConnectionError: + pytest.xfail(reason="No internet connection") + else: + yield + + +def test_httppath(internet_connection): path = UPath("http://example.com") assert isinstance(path, HTTPPath) assert path.exists()