Debian Codegraph @

tests/test_argyll_instruments.py

raw
1 from typing import Union
2
3 import pytest
4 from _pytest.fixtures import SubRequest
5
6 from DisplayCAL.argyll_instruments import (
7 get_canonical_instrument_name,
8 remove_vendor_names,
9 )
10 from DisplayCAL.cgats import CGATS
11
12 INSTR_STR = "i1 DisplayPro, ColorMunki Display"
13 INSTR_STR_INVERSE = "eye-one displayPro, ColorMunki Display"
14
15 REPLACEMENT_STR_STR = {
16 "DTP94-LCD mode": "DTP94",
17 "eye-one display": "i1 Display",
18 "Spyder 2 LCD": "Spyder2",
19 "Spyder 3": "Spyder3",
20 }
21
22 REPLACEMENT_BSTR_BSTR = {
23 b"DTP94-LCD mode": b"DTP94",
24 b"eye-one display": b"i1 Display",
25 b"Spyder 2 LCD": b"Spyder2",
26 b"Spyder 3": b"Spyder3",
27 }
28
29 REPLACEMENT_STR_BSTR = {
30 "DTP94-LCD mode": b"DTP94",
31 "eye-one display": b"i1 Display",
32 "Spyder 2 LCD": b"Spyder2",
33 "Spyder 3": b"Spyder3",
34 }
35
36 REPLACEMENT_BSTR_STR = {
37 b"DTP94-LCD mode": "DTP94",
38 b"eye-one display": "i1 Display",
39 b"Spyder 2 LCD": "Spyder2",
40 b"Spyder 3": "Spyder3",
41 }
42
43
44 @pytest.fixture(
45 scope="session",
46 name="inst_str_format",
47 params=("instrument_byte", "instrument_str"),
48 )
49 def fixture_inst_str_format(request: SubRequest) -> str:
50 """ "Return string format of instrument."""
51 return request.param
52
53
54 @pytest.fixture(scope="module", name="target_instrument")
55 def fixture_target_instrument(inst_str_format: str, data_files) -> Union[bytes, str]:
56 """Return target instrument."""
57 path = data_files["0_16.ti3"]
58 cgats = CGATS(path)
59 if inst_str_format == "instrument_byte":
60 target_instrument = cgats.queryv1("TARGET_INSTRUMENT")
61 assert target_instrument == b"X-Rite i1 DisplayPro, ColorMunki Display"
62 else:
63 target_instrument = cgats.queryv1("TARGET_INSTRUMENT").decode("utf-8")
64 assert target_instrument == "X-Rite i1 DisplayPro, ColorMunki Display"
65 return target_instrument
66
67
68 @pytest.mark.parametrize("inverse", (True, False), ids=("inverse", "not inverse"))
69 @pytest.mark.parametrize(
70 "replacement",
71 (
72 REPLACEMENT_STR_STR,
73 REPLACEMENT_BSTR_BSTR,
74 REPLACEMENT_BSTR_STR,
75 REPLACEMENT_STR_BSTR,
76 None,
77 ),
78 ids=(
79 "rep_string-string",
80 "rep_bytes-bytes",
81 "rep_bytes-string",
82 "rep_string-bytes",
83 "no replacement",
84 ),
85 )
86 def test_get_canonical_instrument_name(
87 replacement: dict[Union[str, bytes], Union[str, bytes]],
88 target_instrument: Union[bytes, str],
89 inverse: bool,
90 ) -> None:
91 """Test argyll_instruments.get_canonical_instrument_name()."""
92 result = get_canonical_instrument_name(target_instrument, replacement, inverse)
93 if inverse and replacement:
94 expected_result = (
95 INSTR_STR_INVERSE.encode("utf-8")
96 if isinstance(target_instrument, bytes)
97 else INSTR_STR_INVERSE
98 )
99 else:
100 expected_result = (
101 INSTR_STR.encode("utf-8")
102 if isinstance(target_instrument, bytes)
103 else INSTR_STR
104 )
105 assert result == expected_result
106
107
108 def test_remove_vendor_names(target_instrument: Union[bytes, str]) -> None:
109 """testing the argyll_instruments.remove_vendor_names() function"""
110 if isinstance(target_instrument, str):
111 pytest.skip()
112 result = remove_vendor_names(target_instrument)
113 expected_result = b"i1 DisplayPro, ColorMunki Display"
114 assert result == expected_result