2121from opentelemetry .attributes import BoundedAttributes
2222from opentelemetry .context import get_current
2323from opentelemetry .sdk ._logs import (
24- LogRecordContextDeprecatedWarning ,
25- LogRecordInitDeprecatedWarning ,
2624 LogDroppedAttributesWarning ,
2725 LogLimits ,
2826 LogRecord ,
27+ LogRecordContextDeprecatedWarning ,
28+ LogRecordInitDeprecatedWarning ,
2929)
3030from opentelemetry .sdk .resources import Resource
3131from opentelemetry .trace .span import TraceFlags
@@ -143,14 +143,17 @@ def test_log_record_dropped_attributes_set_limits_warning_once(self):
143143 attributes = attr ,
144144 limits = limits ,
145145 )
146-
146+
147147 # Check that at least one LogDroppedAttributesWarning was emitted
148148 dropped_attributes_warnings = [
149149 w for w in cw if isinstance (w .message , LogDroppedAttributesWarning )
150150 ]
151- self .assertEqual (len (dropped_attributes_warnings ), 1 ,
152- "Expected exactly one LogDroppedAttributesWarning due to simplefilter('once')" )
153-
151+ self .assertEqual (
152+ len (dropped_attributes_warnings ),
153+ 1 ,
154+ "Expected exactly one LogDroppedAttributesWarning due to simplefilter('once')" ,
155+ )
156+
154157 # Check the message content of the LogDroppedAttributesWarning
155158 warning_message = str (dropped_attributes_warnings [0 ].message )
156159 self .assertIn (
@@ -183,11 +186,16 @@ def test_log_record_context_deprecated_init_warning(self):
183186
184187 # Check that at least one LogRecordContextDeprecatedWarning was emitted
185188 context_deprecated_warnings = [
186- w for w in cw if isinstance (w .message , LogRecordContextDeprecatedWarning )
189+ w
190+ for w in cw
191+ if isinstance (w .message , LogRecordContextDeprecatedWarning )
187192 ]
188- self .assertEqual (len (context_deprecated_warnings ), 1 ,
189- "Expected exactly one LogRecordContextDeprecatedWarning due to simplefilter('once')" )
190-
193+ self .assertEqual (
194+ len (context_deprecated_warnings ),
195+ 1 ,
196+ "Expected exactly one LogRecordContextDeprecatedWarning due to simplefilter('once')" ,
197+ )
198+
191199 # Check the message content of the LogRecordContextDeprecatedWarning
192200 warning_message = str (context_deprecated_warnings [0 ].message )
193201 self .assertIn (
@@ -198,27 +206,37 @@ def test_log_record_context_deprecated_init_warning(self):
198206 with warnings .catch_warnings (record = True ) as cw :
199207 for _ in range (10 ):
200208 LogRecord (context = get_current ())
201-
209+
202210 # Check that no LogRecordContextDeprecatedWarning was emitted when using context
203211 context_deprecated_warnings = [
204- w for w in cw if isinstance (w .message , LogRecordContextDeprecatedWarning )
212+ w
213+ for w in cw
214+ if isinstance (w .message , LogRecordContextDeprecatedWarning )
205215 ]
206- self .assertEqual (len (context_deprecated_warnings ), 0 ,
207- "Expected no LogRecordContextDeprecatedWarning when using context parameter" )
216+ self .assertEqual (
217+ len (context_deprecated_warnings ),
218+ 0 ,
219+ "Expected no LogRecordContextDeprecatedWarning when using context parameter" ,
220+ )
208221
209222 def test_log_record_init_deprecated_warning (self ):
210223 """Test that LogRecord initialization emits a LogRecordInitDeprecatedWarning."""
211224 with warnings .catch_warnings (record = True ) as cw :
212225 warnings .simplefilter ("always" )
213226 LogRecord ()
214-
227+
215228 # Check that at least one LogRecordInitDeprecatedWarning was emitted
216229 log_record_init_warnings = [
217- w for w in cw if isinstance (w .message , LogRecordInitDeprecatedWarning )
230+ w
231+ for w in cw
232+ if isinstance (w .message , LogRecordInitDeprecatedWarning )
218233 ]
219- self .assertGreater (len (log_record_init_warnings ), 0 ,
220- "Expected at least one LogRecordInitDeprecatedWarning" )
221-
234+ self .assertGreater (
235+ len (log_record_init_warnings ),
236+ 0 ,
237+ "Expected at least one LogRecordInitDeprecatedWarning" ,
238+ )
239+
222240 # Check the message content of the LogRecordInitDeprecatedWarning
223241 warning_message = str (log_record_init_warnings [0 ].message )
224242 self .assertIn (
0 commit comments