| 1 | from functools import wraps |
| 2 | from typing import Any, Callable, TYPE_CHECKING, TypeVar |
| 3 | from unittest import SkipTest |
| 4 | |
| 5 | from freezegun.api import FakeDate, FakeDatetime, _is_cpython |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | if TYPE_CHECKING: |
| 10 | from typing_extensions import ParamSpec |
| 11 | |
| 12 | P = ParamSpec("P") |
| 13 | |
| 14 | T = TypeVar("T") |
| 15 | |
| 16 | |
| 17 | def is_fake_date(obj: Any) -> bool: |
| 18 | return obj.__class__ is FakeDate |
| 19 | |
| 20 | |
| 21 | def is_fake_datetime(obj: Any) -> bool: |
| 22 | return obj.__class__ is FakeDatetime |
| 23 | |
| 24 | |
| 25 | cpython_only_mark = pytest.mark.skipif( |
| 26 | not _is_cpython, |
| 27 | reason="Requires CPython") |
| 28 | |
| 29 | |
| 30 | def cpython_only(func: "Callable[P, T]") -> "Callable[P, T]": |
| 31 | @wraps(func) |
| 32 | def wrapper(*args: "P.args", **kwargs: "P.kwargs") -> T: |
| 33 | if not _is_cpython: |
| 34 | raise SkipTest("Requires CPython") |
| 35 | return func(*args, **kwargs) |
| 36 | return wrapper |