Coverage for utilities/tests/test_deprecated.py: 100%

1"""Define the unit tests helper module for the deprecation management."""

2

3 from __future__ import annotations

4

5 import contextlib

6 import sys

7 import typing

8

9 if typing.TYPE_CHECKING:

10 from colour.hints import Any

11

12 from colour.utilities.deprecation import ModuleAPI, ObjectRemoved, ObjectRenamed

13

14

15 class deprecated(ModuleAPI):

16 """Define a class acting like the *deprecated* module."""

17

18 def __getattr__(self, attribute: str) -> Any:

19 """Return the value from the attribute with the specified name."""

20

21 return super().__getattr__(attribute)

22

23

24 NAME: Any = None

25"""An non-deprecated module attribute."""

26

27 NEW_NAME: Any = None

28"""A module attribute with a new name."""

29

30 with contextlib.suppress(KeyError):

31 sys.modules["colour.utilities.tests.test_deprecated"] = deprecated( # pyright: ignore

32 sys.modules["colour.utilities.tests.test_deprecated"],

33 {

34 "OLD_NAME": ObjectRenamed(

35 name="colour.utilities.tests.test_deprecated.OLD_NAME",

36 new_name="colour.utilities.tests.test_deprecated.NEW_NAME",

37 ),

38 "REMOVED": ObjectRemoved(

39 name="colour.utilities.tests.test_deprecated.REMOVED"

40 ),

41 },

42 )

43

44 del ModuleAPI

45 del ObjectRenamed

46 del ObjectRemoved

47 del sys