Skip to content

Commit 07463ed

Browse files
committed
fix ruff: move yaml import to top level
Assisted-by: Claude Sonnet 4.6
1 parent 69f319b commit 07463ed

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

opentelemetry-sdk/tests/_configuration/file/test_env_substitution.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import unittest
1717
from unittest.mock import patch
1818

19+
import yaml
20+
1921
from opentelemetry.sdk._configuration.file import (
2022
EnvSubstitutionError,
2123
substitute_env_vars,
@@ -123,8 +125,6 @@ def test_newline_in_value_prevents_yaml_injection(self):
123125
environment variables." A value like "legit\\nmalicious_key: val"
124126
must be emitted as a quoted scalar, not raw YAML.
125127
"""
126-
import yaml
127-
128128
with patch.dict(
129129
os.environ,
130130
{"SERVICE_NAME": "legit-service\nmalicious_key: injected_value"},
@@ -138,34 +138,24 @@ def test_newline_in_value_prevents_yaml_injection(self):
138138

139139
def test_newline_in_value_preserved_as_literal(self):
140140
"""Newline within a value is preserved as a literal newline character."""
141-
import yaml
142-
143141
with patch.dict(os.environ, {"MULTI": "line1\nline2"}):
144142
result = substitute_env_vars("key: ${MULTI}")
145143
parsed = yaml.safe_load(result)
146144
self.assertEqual(parsed["key"], "line1\nline2")
147145

148146
def test_carriage_return_in_value_is_escaped(self):
149147
"""Carriage return in value is escaped, not injected."""
150-
import yaml
151-
152148
with patch.dict(os.environ, {"VAL": "text\r\nmore"}):
153149
result = substitute_env_vars("key: ${VAL}")
154150
parsed = yaml.safe_load(result)
155151
self.assertIsInstance(parsed["key"], str)
156152

157153
def test_type_coercion_preserved_for_simple_values(self):
158154
"""Simple values without newlines still undergo YAML type coercion per spec."""
159-
import yaml
160-
161-
with patch.dict(
162-
os.environ, {"BOOL_VAL": "true", "INT_VAL": "42"}
163-
):
155+
with patch.dict(os.environ, {"BOOL_VAL": "true", "INT_VAL": "42"}):
164156
bool_result = yaml.safe_load(
165157
substitute_env_vars("key: ${BOOL_VAL}")
166158
)
167-
int_result = yaml.safe_load(
168-
substitute_env_vars("key: ${INT_VAL}")
169-
)
159+
int_result = yaml.safe_load(substitute_env_vars("key: ${INT_VAL}"))
170160
self.assertIs(bool_result["key"], True)
171161
self.assertEqual(int_result["key"], 42)

0 commit comments

Comments
 (0)