Debian Codegraph @

tests/test_argyll.py

raw
1 import os
2 from subprocess import Popen
3 import sys
4
5 import pytest
6
7 from DisplayCAL import config
8 from DisplayCAL.argyll import (
9 debug_print,
10 get_argyll_util,
11 get_argyll_version,
12 get_argyll_version_string,
13 verbose_print,
14 )
15
16 from DisplayCAL.dev.mocks import check_call, check_call_str
17 from tests.data.argyll_sp_data import SUBPROCESS_COM
18
19
20 @pytest.fixture(scope="function")
21 def setup_verbose_level(request):
22 """Fixture to set up the verbose level for tests."""
23 from DisplayCAL import options
24
25 orig_value = options.VERBOSE
26 options.VERBOSE = request.param
27 yield
28 options.VERBOSE = orig_value
29
30
31 @pytest.fixture(scope="function")
32 def setup_debug_level(request):
33 """Fixture to set up the debug level for tests."""
34 from DisplayCAL import options
35
36 orig_value = options.DEBUG
37 options.DEBUG = request.param
38 yield
39 options.DEBUG = orig_value
40
41
42 # todo: deactivated test temporarily
43 # def test_xicclu_is_working_properly(data_files):
44 # """testing if ``DisplayCAL.worker_base.Xicclu`` is working properly"""
45 # from DisplayCAL.icc_profile import ICCProfile
46 # from DisplayCAL.worker_base import Xicclu
47 #
48 # profile = ICCProfile(profile=data_files["default.icc"].absolute())
49 # xicclu = Xicclu(profile, "r", "a", pcs="X", scale=100)
50 # assert xicclu() is not None
51
52
53 def test_get_argyll_util(setup_argyll):
54 """Test get_argyll_util() function."""
55 config.initcfg()
56 result = get_argyll_util("ccxxmake")
57 expected_result = os.path.join(config.getcfg("argyll.dir"), "ccxxmake")
58 if sys.platform == "win32":
59 expected_result += ".exe"
60 assert result == expected_result
61
62
63 def test_get_argyll_version_string_1(setup_argyll):
64 """Test get_argyll_version_string() function."""
65 config.initcfg()
66 with check_call(Popen, "communicate", SUBPROCESS_COM):
67 result = get_argyll_version_string("ccxxmake")
68 expected_result = "2.3.0"
69 assert result == expected_result
70
71
72 def test_get_argyll_version_1(setup_argyll):
73 """Test get_argyll_version() function."""
74 with check_call_str("DisplayCAL.argyll.get_argyll_version_string", "2.3.0"):
75 result = get_argyll_version("ccxxmake")
76 expected_result = [2, 3, 0]
77 assert result == expected_result
78
79
80 def test_verbose_print_verbose_level_skipped(setup_argyll, capsys):
81 """Test verbose_print() function."""
82 test_value = "Test message"
83 verbose_print(test_value)
84 assert capsys.readouterr().out == f"{test_value}\n"
85
86
87 @pytest.mark.parametrize("setup_verbose_level", [3], indirect=True)
88 def test_verbose_print_verbose_level_is_lower_than_verbose(
89 setup_argyll, setup_verbose_level, capsys
90 ):
91 """Test verbose_print() function."""
92 test_value = "Test message"
93 verbose_print(test_value, verbose_level=2)
94 assert capsys.readouterr().out == f"{test_value}\n"
95
96
97 @pytest.mark.parametrize("setup_verbose_level", [3], indirect=True)
98 def test_verbose_print_verbose_level_is_equal_to_verbose(
99 setup_argyll, setup_verbose_level, capsys
100 ):
101 """Test verbose_print() function."""
102 test_value = "Test message"
103 verbose_print(test_value, verbose_level=3)
104 assert capsys.readouterr().out == f"{test_value}\n"
105
106
107 @pytest.mark.parametrize("setup_verbose_level", [3], indirect=True)
108 def test_verbose_print_verbose_level_is_higher_than_verbose(
109 setup_argyll, setup_verbose_level, capsys
110 ):
111 """Test verbose_print() function."""
112 test_value = "Test message"
113 verbose_print(test_value, verbose_level=4)
114 assert capsys.readouterr().out != f"{test_value}\n"
115
116
117 @pytest.mark.parametrize(
118 "setup_verbose_level, test_value",
119 [(3, True), (3, False)],
120 indirect=["setup_verbose_level"],
121 )
122 def test_verbose_print_verbose_with_an_if_statement(
123 setup_argyll, setup_verbose_level, test_value, capsys
124 ):
125 """Test verbose_print() function with an if statement."""
126 cond1_value = ["Info:", "name", "=", "exe"]
127 cond2_value = ["Info:", "name", "not found in", "PATH"]
128 verbose_print(*(cond1_value if test_value else cond2_value), verbose_level=3)
129
130 assert capsys.readouterr().out == (
131 " ".join(cond1_value if test_value else cond2_value) + "\n"
132 )
133
134 @pytest.mark.parametrize("setup_debug_level", [1], indirect=True)
135 def test_debug_print_debug_level_skipped(setup_argyll, setup_debug_level, capsys):
136 """Test debug_print() function."""
137 test_value = "Test message"
138 debug_print(test_value)
139 assert capsys.readouterr().out == f"{test_value}\n"
140
141
142 @pytest.mark.parametrize("setup_debug_level", [3], indirect=True)
143 def test_debug_print_debug_level_is_lower_than_debug(
144 setup_argyll, setup_debug_level, capsys
145 ):
146 """Test debug_print() function."""
147 test_value = "Test message"
148 debug_print(test_value, debug_level=2)
149 assert capsys.readouterr().out == f"{test_value}\n"
150
151
152 @pytest.mark.parametrize("setup_debug_level", [3], indirect=True)
153 def test_debug_print_debug_level_is_equal_to_debug(
154 setup_argyll, setup_debug_level, capsys
155 ):
156 """Test debug_print() function."""
157 test_value = "Test message"
158 debug_print(test_value, debug_level=3)
159 assert capsys.readouterr().out == f"{test_value}\n"
160
161
162 @pytest.mark.parametrize("setup_debug_level", [3], indirect=True)
163 def test_debug_print_debug_level_is_higher_than_debug(
164 setup_argyll, setup_debug_level, capsys
165 ):
166 """Test debug_print() function."""
167 test_value = "Test message"
168 debug_print(test_value, debug_level=4)
169 assert capsys.readouterr().out != f"{test_value}\n"
170
171
172 @pytest.mark.parametrize(
173 "setup_debug_level, test_value",
174 [(3, True), (3, False)],
175 indirect=["setup_debug_level"],
176 )
177 def test_debug_print_debug_with_an_if_statement(
178 setup_argyll, setup_debug_level, test_value, capsys
179 ):
180 """Test debug_print() function with an if statement."""
181 cond1_value = ["Info:", "name", "=", "exe"]
182 cond2_value = ["Info:", "name", "not found in", "PATH"]
183 debug_print(*(cond1_value if test_value else cond2_value), debug_level=3)
184
185 assert capsys.readouterr().out == (
186 " ".join(cond1_value if test_value else cond2_value) + "\n"
187 )