Coverage for colour/utilities/tests/test_deprecation.py: 100%
124 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.utilities.deprecation` module."""
3from __future__ import annotations
5import sys
7import pytest
9from colour.utilities import ColourUsageWarning
10from colour.utilities.deprecation import (
11 ArgumentFutureRemove,
12 ArgumentFutureRename,
13 ArgumentRemoved,
14 ArgumentRenamed,
15 ModuleAPI,
16 ObjectFutureAccessChange,
17 ObjectFutureAccessRemove,
18 ObjectFutureRemove,
19 ObjectFutureRename,
20 ObjectRemoved,
21 ObjectRenamed,
22 build_API_changes,
23 get_attribute,
24 handle_arguments_deprecation,
25)
27__author__ = "Colour Developers"
28__copyright__ = "Copyright 2013 Colour Developers"
29__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
30__maintainer__ = "Colour Developers"
31__email__ = "colour-developers@colour-science.org"
32__status__ = "Production"
34__all__ = [
35 "TestObjectRenamed",
36 "TestObjectRemoved",
37 "TestObjectFutureRename",
38 "TestObjectFutureRemove",
39 "TestObjectFutureAccessChange",
40 "TestObjectFutureAccessRemove",
41 "TestArgumentRenamed",
42 "TestArgumentRemoved",
43 "TestArgumentFutureRename",
44 "TestArgumentFutureRemove",
45 "TestModuleAPI",
46 "TestGetAttribute",
47 "TestBuildAPIChanges",
48 "TestHandleArgumentsDeprecation",
49]
52class TestObjectRenamed:
53 """
54 Define :class:`colour.utilities.deprecation.ObjectRenamed` class unit
55 tests methods.
56 """
58 def test_required_methods(self) -> None:
59 """Test the presence of required methods."""
61 required_methods = ("__str__",)
63 for method in required_methods:
64 assert method in dir(ObjectRenamed)
66 def test__str__(self) -> None:
67 """
68 Test :meth:`colour.utilities.deprecation.ObjectRenamed.__str__`
69 method.
70 """
72 assert "name" in str(ObjectRenamed("name", "new_name"))
73 assert "new_name" in str(ObjectRenamed("name", "new_name"))
76class TestObjectRemoved:
77 """
78 Define :class:`colour.utilities.deprecation.ObjectRemoved` class unit
79 tests methods.
80 """
82 def test_required_methods(self) -> None:
83 """Test the presence of required methods."""
85 required_methods = ("__str__",)
87 for method in required_methods:
88 assert method in dir(ObjectRemoved)
90 def test__str__(self) -> None:
91 """
92 Test :meth:`colour.utilities.deprecation.ObjectRemoved.__str__`
93 method.
94 """
96 assert "name" in str(ObjectRemoved("name"))
99class TestObjectFutureRename:
100 """
101 Define :class:`colour.utilities.deprecation.ObjectFutureRename` class unit
102 tests methods.
103 """
105 def test_required_methods(self) -> None:
106 """Test the presence of required methods."""
108 required_methods = ("__str__",)
110 for method in required_methods:
111 assert method in dir(ObjectFutureRename)
113 def test__str__(self) -> None:
114 """
115 Test :meth:`colour.utilities.deprecation.ObjectFutureRename.__str__`
116 method.
117 """
119 assert "name" in str(ObjectFutureRename("name", "new_name"))
120 assert "new_name" in str(ObjectFutureRename("name", "new_name"))
123class TestObjectFutureRemove:
124 """
125 Define :class:`colour.utilities.deprecation.ObjectFutureRemove` class unit
126 tests methods.
127 """
129 def test_required_methods(self) -> None:
130 """Test the presence of required methods."""
132 required_methods = ("__str__",)
134 for method in required_methods:
135 assert method in dir(ObjectFutureRemove)
137 def test__str__(self) -> None:
138 """
139 Test :meth:`colour.utilities.deprecation.ObjectFutureRemove.__str__`
140 method.
141 """
143 assert "name" in str(
144 ObjectFutureRemove(
145 "name",
146 )
147 )
150class TestObjectFutureAccessChange:
151 """
152 Define :class:`colour.utilities.deprecation.ObjectFutureAccessChange`
153 class unit tests methods.
154 """
156 def test_required_methods(self) -> None:
157 """Test the presence of required methods."""
159 required_methods = ("__str__",)
161 for method in required_methods:
162 assert method in dir(ObjectFutureAccessChange)
164 def test__str__(self) -> None:
165 """
166 Test :meth:`colour.utilities.deprecation.\
167ObjectFutureAccessChange.__str__` method.
168 """
170 assert "name" in str(ObjectFutureAccessChange("name", "new_access"))
171 assert "new_access" in str(ObjectFutureAccessChange("name", "new_access"))
174class TestObjectFutureAccessRemove:
175 """
176 Define :class:`colour.utilities.deprecation.ObjectFutureAccessRemove`
177 class unit tests methods.
178 """
180 def test_required_methods(self) -> None:
181 """Test the presence of required methods."""
183 required_methods = ("__str__",)
185 for method in required_methods:
186 assert method in dir(ObjectFutureAccessRemove)
188 def test__str__(self) -> None:
189 """
190 Test :meth:`colour.utilities.deprecation.\
191ObjectFutureAccessRemove.__str__` method.
192 """
194 assert "name" in str(
195 ObjectFutureAccessRemove(
196 "name",
197 )
198 )
201class TestArgumentRenamed:
202 """
203 Define :class:`colour.utilities.deprecation.ArgumentRenamed` class unit
204 tests methods.
205 """
207 def test_required_methods(self) -> None:
208 """Test the presence of required methods."""
210 required_methods = ("__str__",)
212 for method in required_methods:
213 assert method in dir(ArgumentRenamed)
215 def test__str__(self) -> None:
216 """
217 Test :meth:`colour.utilities.deprecation.ArgumentRenamed.__str__`
218 method.
219 """
221 assert "name" in str(ArgumentRenamed("name", "new_name"))
222 assert "new_name" in str(ArgumentRenamed("name", "new_name"))
225class TestArgumentRemoved:
226 """
227 Define :class:`colour.utilities.deprecation.ArgumentRemoved` class unit
228 tests methods.
229 """
231 def test_required_methods(self) -> None:
232 """Test the presence of required methods."""
234 required_methods = ("__str__",)
236 for method in required_methods:
237 assert method in dir(ArgumentRemoved)
239 def test__str__(self) -> None:
240 """
241 Test :meth:`colour.utilities.deprecation.ArgumentRemoved.__str__`
242 method.
243 """
245 assert "name" in str(ArgumentRemoved("name"))
248class TestArgumentFutureRename:
249 """
250 Define :class:`colour.utilities.deprecation.ArgumentFutureRename` class
251 unit tests methods.
252 """
254 def test_required_methods(self) -> None:
255 """Test the presence of required methods."""
257 required_methods = ("__str__",)
259 for method in required_methods:
260 assert method in dir(ArgumentFutureRename)
262 def test__str__(self) -> None:
263 """
264 Test :meth:`colour.utilities.deprecation.\
265ArgumentFutureRename.__str__` method.
266 """
268 assert "name" in str(ArgumentFutureRename("name", "new_name"))
269 assert "new_name" in str(ArgumentFutureRename("name", "new_name"))
272class TestArgumentFutureRemove:
273 """
274 Define :class:`colour.utilities.deprecation.ArgumentFutureRemove` class
275 unit tests methods.
276 """
278 def test_required_methods(self) -> None:
279 """Test the presence of required methods."""
281 required_methods = ("__str__",)
283 for method in required_methods:
284 assert method in dir(ArgumentFutureRemove)
286 def test__str__(self) -> None:
287 """
288 Test :meth:`colour.utilities.deprecation.\
289ArgumentFutureRemove.__str__` method.
290 """
292 assert "name" in str(
293 ArgumentFutureRemove(
294 "name",
295 )
296 )
299class TestModuleAPI:
300 """
301 Define :class:`colour.utilities.deprecation.ModuleAPI` class unit tests
302 methods.
303 """
305 def test_required_methods(self) -> None:
306 """Test the presence of required methods."""
308 required_methods = ("__init__", "__getattr__", "__dir__")
310 for method in required_methods:
311 assert method in dir(ModuleAPI)
313 def test__getattr__(self) -> None:
314 """
315 Test :meth:`colour.utilities.deprecation.ModuleAPI.__getattr__`
316 method.
317 """
319 import colour.utilities.tests.test_deprecated # noqa: PLC0415
321 assert colour.utilities.tests.test_deprecated.NAME is None
323 def assert_warns() -> None:
324 """Help to test the runtime warning."""
326 colour.utilities.tests.test_deprecated.OLD_NAME # noqa: B018 # pyright: ignore
328 pytest.warns(ColourUsageWarning, assert_warns)
330 del sys.modules["colour.utilities.tests.test_deprecated"]
332 def test_raise_exception__getattr__(self) -> None:
333 """
334 Test :func:`colour.utilities.deprecation.ModuleAPI.__getattr__`
335 method raised exception.
336 """
338 import colour.utilities.tests.test_deprecated # noqa: PLC0415
340 pytest.raises(
341 AttributeError,
342 getattr,
343 colour.utilities.tests.test_deprecated,
344 "REMOVED",
345 )
347 del sys.modules["colour.utilities.tests.test_deprecated"]
350class TestGetAttribute:
351 """
352 Define :func:`colour.utilities.deprecation.get_attribute` definition unit
353 tests methods.
354 """
356 def test_get_attribute(self) -> None:
357 """Test :func:`colour.utilities.deprecation.get_attribute` definition."""
359 from colour import adaptation # noqa: PLC0415
361 assert get_attribute("colour.adaptation") is adaptation
363 from colour.models import eotf_inverse_sRGB # noqa: PLC0415
365 assert get_attribute("colour.models.eotf_inverse_sRGB") is eotf_inverse_sRGB
367 from colour.utilities.array import as_float # noqa: PLC0415
369 assert get_attribute("colour.utilities.array.as_float") is as_float
371 if "colour.utilities.tests.test_deprecated" in sys.modules: # pragma: no cover
372 del sys.modules["colour.utilities.tests.test_deprecated"]
374 attribute = get_attribute("colour.utilities.tests.test_deprecated.NEW_NAME")
376 import colour.utilities.tests.test_deprecated # noqa: PLC0415
378 assert attribute is colour.utilities.tests.test_deprecated.NEW_NAME
379 del sys.modules["colour.utilities.tests.test_deprecated"]
382class TestBuildAPIChanges:
383 """
384 Define :func:`colour.utilities.deprecation.build_API_changes` definition
385 unit tests methods.
386 """
388 def test_build_API_changes(self) -> None:
389 """
390 Test :func:`colour.utilities.deprecation.build_API_changes`
391 definition.
392 """
394 changes = build_API_changes(
395 {
396 "ObjectRenamed": [
397 [
398 "module.object_1_name",
399 "module.object_1_new_name",
400 ]
401 ],
402 "ObjectFutureRename": [
403 [
404 "module.object_2_name",
405 "module.object_2_new_name",
406 ]
407 ],
408 "ObjectFutureAccessChange": [
409 [
410 "module.object_3_access",
411 "module.sub_module.object_3_new_access",
412 ]
413 ],
414 "ObjectRemoved": ["module.object_4_name"],
415 "ObjectFutureRemove": ["module.object_5_name"],
416 "ObjectFutureAccessRemove": ["module.object_6_access"],
417 "ArgumentRenamed": [
418 [
419 "argument_1_name",
420 "argument_1_new_name",
421 ]
422 ],
423 "ArgumentFutureRename": [
424 [
425 "argument_2_name",
426 "argument_2_new_name",
427 ]
428 ],
429 "ArgumentRemoved": ["argument_3_name"],
430 "ArgumentFutureRemove": ["argument_4_name"],
431 }
432 )
433 for name, change_type in (
434 ("object_1_name", ObjectRenamed),
435 ("object_2_name", ObjectFutureRename),
436 ("object_3_access", ObjectFutureAccessChange),
437 ("object_4_name", ObjectRemoved),
438 ("object_5_name", ObjectFutureRemove),
439 ("object_6_access", ObjectFutureAccessRemove),
440 ("argument_1_name", ArgumentRenamed),
441 ("argument_2_name", ArgumentFutureRename),
442 ("argument_3_name", ArgumentRemoved),
443 ("argument_4_name", ArgumentFutureRemove),
444 ):
445 assert isinstance(changes[name], change_type)
448class TestHandleArgumentsDeprecation:
449 """
450 Define :func:`colour.utilities.deprecation.handle_arguments_deprecation`
451 definition unit tests methods.
452 """
454 def test_handle_arguments_deprecation(self) -> None:
455 """
456 Test :func:`colour.utilities.deprecation.handle_arguments_deprecation`
457 definition.
458 """
460 changes = {
461 "ArgumentRenamed": [
462 [
463 "argument_1_name",
464 "argument_1_new_name",
465 ]
466 ],
467 "ArgumentFutureRename": [
468 [
469 "argument_2_name",
470 "argument_2_new_name",
471 ]
472 ],
473 "ArgumentRemoved": ["argument_3_name"],
474 "ArgumentFutureRemove": ["argument_4_name"],
475 }
477 assert handle_arguments_deprecation(
478 changes,
479 argument_1_name=True,
480 argument_2_name=True,
481 argument_3_name=True,
482 argument_4_name=True,
483 argument_5_name=True,
484 ) == {
485 "argument_1_new_name": True,
486 "argument_2_new_name": True,
487 "argument_4_name": True,
488 "argument_5_name": True,
489 }