mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
Improve type annotation of `galaxy.util.unittest_utils` module
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user