Improve type annotation of `galaxy.util.unittest_utils` module

This commit is contained in:
Nicola Soranzo
2025-04-28 19:42:47 +01:00
parent 3f18c3a9d8
commit 39ee45b351
2 changed files with 21 additions and 7 deletions
+13 -7
View File
@@ -1,12 +1,14 @@
import os
from functools import wraps
from typing import (
Any,
Callable,
TypeVar,
Union,
)
from unittest import SkipTest
import pytest
from typing_extensions import ParamSpec
from galaxy.util import requests
from galaxy.util.commands import which
@@ -20,10 +22,14 @@ def is_site_up(url: str) -> bool:
return False
def skip_if_site_down(url: str) -> Callable:
def method_wrapper(method: Callable):
P = ParamSpec("P")
T = TypeVar("T")
def skip_if_site_down(url: str) -> Callable[[Callable[P, T]], Callable[P, T]]:
def method_wrapper(method: Callable[P, T]) -> Callable[P, T]:
@wraps(method)
def wrapped_method(*args, **kwargs) -> Any:
def wrapped_method(*args: P.args, **kwargs: P.kwargs) -> T:
if not is_site_up(url):
raise SkipTest(f"Test depends on [{url}] being up and it appears to be down.")
return method(*args, **kwargs)
@@ -36,17 +42,17 @@ def skip_if_site_down(url: str) -> Callable:
skip_if_github_down = skip_if_site_down("https://github.com/")
def _identity(func: Callable) -> Callable:
def _identity(func: Callable[P, T]) -> Callable[P, T]:
return func
def skip_unless_executable(executable):
def skip_unless_executable(executable: str) -> Union[Callable[[Callable[P, T]], Callable[P, T]], pytest.MarkDecorator]:
if which(executable):
return _identity
return pytest.mark.skip(f"PATH doesn't contain executable {executable}")
def skip_unless_environ(env_var):
def skip_unless_environ(env_var: str) -> Union[Callable[[Callable[P, T]], Callable[P, T]], pytest.MarkDecorator]:
if os.environ.get(env_var):
return _identity
+8
View File
@@ -35,6 +35,14 @@ disallow_untyped_decorators = True
disallow_untyped_defs = True
warn_return_any = True
[mypy-galaxy.util.unittest_utils]
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
warn_return_any = True
[mypy-galaxy.managers.secured]
disallow_any_generics = True
disallow_subclassing_any = True