@@ -147,3 +147,80 @@ def test_logs_are_masked(captured_logs):
147
147
"try_number=1, map_index=-1, hostname=None, context_carrier=None)" ,
148
148
"timestamp" : "2025-03-25T05:13:27.073918Z" ,
149
149
}
150
+
151
+
152
+ def test_logging_processors_with_colors ():
153
+ """Test that logging_processors creates colored console renderer when colored_console_log=True."""
154
+ from airflow .sdk .log import logging_processors
155
+
156
+ _ , named = logging_processors (enable_pretty_log = True , colored_console_log = True )
157
+ assert "console" in named
158
+ console_renderer = named ["console" ]
159
+ assert hasattr (console_renderer , "_styles" )
160
+
161
+
162
+ def test_logging_processors_without_colors ():
163
+ """Test that logging_processors creates non-colored console renderer when colored_console_log=False."""
164
+ from airflow .sdk .log import logging_processors
165
+
166
+ _ , named = logging_processors (enable_pretty_log = True , colored_console_log = False )
167
+ assert "console" in named
168
+ console_renderer = named ["console" ]
169
+ assert hasattr (console_renderer , "_styles" )
170
+ assert console_renderer ._styles .__name__ == "_PlainStyles"
171
+
172
+
173
+ def test_logging_processors_json_format ():
174
+ """Test that logging_processors creates JSON renderer when enable_pretty_log=False."""
175
+ from airflow .sdk .log import logging_processors
176
+
177
+ _ , named = logging_processors (enable_pretty_log = False , colored_console_log = True )
178
+ assert "console" not in named
179
+ assert "json" in named
180
+
181
+
182
+ def test_configure_logging_respects_colored_console_log_config ():
183
+ """Test that configure_logging respects the colored_console_log configuration."""
184
+ from airflow .sdk .log import configure_logging , reset_logging
185
+
186
+ mock_conf = mock .MagicMock ()
187
+ mock_conf .get .return_value = "INFO"
188
+ mock_conf .getboolean .return_value = False # colored_console_log = False
189
+
190
+ with mock .patch ("airflow.configuration.conf" , mock_conf ):
191
+ reset_logging ()
192
+ configure_logging (enable_pretty_log = True )
193
+ # Check that getboolean was called with colored_console_log
194
+ calls = [call for call in mock_conf .getboolean .call_args_list if call [0 ][1 ] == "colored_console_log" ]
195
+ assert len (calls ) == 1
196
+ assert calls [0 ] == mock .call ("logging" , "colored_console_log" , fallback = True )
197
+
198
+
199
+ def test_configure_logging_explicit_colored_console_log ():
200
+ """Test that configure_logging respects explicit colored_console_log parameter."""
201
+ from airflow .sdk .log import configure_logging , reset_logging
202
+
203
+ mock_conf = mock .MagicMock ()
204
+ mock_conf .get .return_value = "INFO"
205
+ mock_conf .getboolean .return_value = True # colored_console_log = True
206
+
207
+ with mock .patch ("airflow.configuration.conf" , mock_conf ):
208
+ reset_logging ()
209
+ # Explicitly disable colors despite config saying True
210
+ configure_logging (enable_pretty_log = True , colored_console_log = False )
211
+ mock_conf .getboolean .assert_not_called ()
212
+
213
+
214
+ def test_configure_logging_no_airflow_config ():
215
+ """Test that configure_logging defaults work correctly."""
216
+ from airflow .sdk .log import configure_logging , reset_logging
217
+
218
+ # This test can be removed or repurposed since we now always import airflow.configuration
219
+ mock_conf = mock .MagicMock ()
220
+ mock_conf .get .return_value = "INFO"
221
+ mock_conf .getboolean .return_value = True # colored_console_log = True by default
222
+
223
+ with mock .patch ("airflow.configuration.conf" , mock_conf ):
224
+ reset_logging ()
225
+ configure_logging (enable_pretty_log = True )
226
+ mock_conf .getboolean .assert_called_with ("logging" , "colored_console_log" , fallback = True )
0 commit comments