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

18 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

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

2 

3from __future__ import annotations 

4 

5import contextlib 

6import sys 

7import typing 

8 

9if typing.TYPE_CHECKING: 

10 from colour.hints import Any 

11 

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

13 

14 

15class 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 

24NAME: Any = None 

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

26 

27NEW_NAME: Any = None 

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

29 

30with 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 

44del ModuleAPI 

45del ObjectRenamed 

46del ObjectRemoved 

47del sys