Skip to content

Commit 67a5030

Browse files
committed
reformat files
1 parent c0f862b commit 67a5030

File tree

3 files changed

+45
-35
lines changed

3 files changed

+45
-35
lines changed

ecs_logging/_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ def json_dumps(value: Dict[str, Any], ensure_ascii: bool = True) -> str:
124124
pass
125125

126126
json_dumps = functools.partial(
127-
json.dumps, sort_keys=True, separators=(",", ":"), default=_json_dumps_fallback, ensure_ascii=ensure_ascii
127+
json.dumps,
128+
sort_keys=True,
129+
separators=(",", ":"),
130+
default=_json_dumps_fallback,
131+
ensure_ascii=ensure_ascii,
128132
)
129133

130134
# Because we want to use 'sorted_keys=True' we manually build

tests/test_stdlib_formatter.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,14 @@ def test_ensure_ascii_default():
374374
record = make_record()
375375
record.msg = "Hello 世界"
376376
record.args = ()
377-
377+
378378
formatter = ecs_logging.StdlibFormatter(exclude_fields=["process"])
379379
result = formatter.format(record)
380-
380+
381381
# With ensure_ascii=True (default), non-ASCII characters should be escaped
382382
assert "\\u4e16\\u754c" in result
383383
assert "世界" not in result
384-
384+
385385
# Verify the JSON is valid
386386
parsed = json.loads(result)
387387
assert parsed["message"] == "Hello 世界"
@@ -392,16 +392,18 @@ def test_ensure_ascii_true():
392392
record = make_record()
393393
record.msg = "Café ☕"
394394
record.args = ()
395-
396-
formatter = ecs_logging.StdlibFormatter(exclude_fields=["process"], ensure_ascii=True)
395+
396+
formatter = ecs_logging.StdlibFormatter(
397+
exclude_fields=["process"], ensure_ascii=True
398+
)
397399
result = formatter.format(record)
398-
400+
399401
# With ensure_ascii=True, non-ASCII characters should be escaped
400402
assert "\\u00e9" in result # é is escaped
401403
assert "\\u2615" in result # ☕ is escaped
402404
assert "Café" not in result
403405
assert "☕" not in result
404-
406+
405407
# Verify the JSON is valid and correctly decoded
406408
parsed = json.loads(result)
407409
assert parsed["message"] == "Café ☕"
@@ -412,14 +414,16 @@ def test_ensure_ascii_false():
412414
record = make_record()
413415
record.msg = "Hello 世界"
414416
record.args = ()
415-
416-
formatter = ecs_logging.StdlibFormatter(exclude_fields=["process"], ensure_ascii=False)
417+
418+
formatter = ecs_logging.StdlibFormatter(
419+
exclude_fields=["process"], ensure_ascii=False
420+
)
417421
result = formatter.format(record)
418-
422+
419423
# With ensure_ascii=False, non-ASCII characters should be preserved
420424
assert "世界" in result
421425
assert "\\u4e16" not in result
422-
426+
423427
# Verify the JSON is valid
424428
parsed = json.loads(result)
425429
assert parsed["message"] == "Hello 世界"
@@ -430,15 +434,17 @@ def test_ensure_ascii_false_with_emoji():
430434
record = make_record()
431435
record.msg = "Café ☕ 你好"
432436
record.args = ()
433-
434-
formatter = ecs_logging.StdlibFormatter(exclude_fields=["process"], ensure_ascii=False)
437+
438+
formatter = ecs_logging.StdlibFormatter(
439+
exclude_fields=["process"], ensure_ascii=False
440+
)
435441
result = formatter.format(record)
436-
442+
437443
# With ensure_ascii=False, all non-ASCII characters should be preserved
438444
assert "Café" in result
439445
assert "☕" in result
440446
assert "你好" in result
441-
447+
442448
# Verify the JSON is valid and correctly decoded
443449
parsed = json.loads(result)
444450
assert parsed["message"] == "Café ☕ 你好"
@@ -449,18 +455,18 @@ def test_ensure_ascii_with_extra_fields():
449455
record = make_record()
450456
record.msg = "Test message"
451457
record.args = ()
452-
458+
453459
formatter = ecs_logging.StdlibFormatter(
454460
exclude_fields=["process"],
455461
ensure_ascii=False,
456-
extra={"user": "用户", "city": "北京"}
462+
extra={"user": "用户", "city": "北京"},
457463
)
458464
result = formatter.format(record)
459-
465+
460466
# With ensure_ascii=False, non-ASCII in extra fields should be preserved
461467
assert "用户" in result
462468
assert "北京" in result
463-
469+
464470
# Verify the JSON is valid
465471
parsed = json.loads(result)
466472
assert parsed["user"] == "用户"

tests/test_structlog_formatter.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def test_exception_log_is_ecs_compliant_when_used_with_format_exc_info(
114114
def test_ensure_ascii_default(time):
115115
"""Test that ensure_ascii defaults to True (escaping non-ASCII characters)"""
116116
time.return_value = 1584720997.187709
117-
117+
118118
formatter = ecs_logging.StructlogFormatter()
119119
result = formatter(None, "debug", {"event": "Hello 世界", "log.logger": "test"})
120-
120+
121121
# With ensure_ascii=True (default), non-ASCII characters should be escaped
122122
assert "\\u4e16\\u754c" in result
123123
assert "世界" not in result
124-
124+
125125
# Verify the JSON is valid
126126
parsed = json.loads(result)
127127
assert parsed["message"] == "Hello 世界"
@@ -131,16 +131,16 @@ def test_ensure_ascii_default(time):
131131
def test_ensure_ascii_true(time):
132132
"""Test that ensure_ascii=True escapes non-ASCII characters"""
133133
time.return_value = 1584720997.187709
134-
134+
135135
formatter = ecs_logging.StructlogFormatter(ensure_ascii=True)
136136
result = formatter(None, "info", {"event": "Café ☕", "log.logger": "test"})
137-
137+
138138
# With ensure_ascii=True, non-ASCII characters should be escaped
139139
assert "\\u00e9" in result # é is escaped
140140
assert "\\u2615" in result # ☕ is escaped
141141
assert "Café" not in result
142142
assert "☕" not in result
143-
143+
144144
# Verify the JSON is valid and correctly decoded
145145
parsed = json.loads(result)
146146
assert parsed["message"] == "Café ☕"
@@ -150,14 +150,14 @@ def test_ensure_ascii_true(time):
150150
def test_ensure_ascii_false(time):
151151
"""Test that ensure_ascii=False preserves non-ASCII characters"""
152152
time.return_value = 1584720997.187709
153-
153+
154154
formatter = ecs_logging.StructlogFormatter(ensure_ascii=False)
155155
result = formatter(None, "debug", {"event": "Hello 世界", "log.logger": "test"})
156-
156+
157157
# With ensure_ascii=False, non-ASCII characters should be preserved
158158
assert "世界" in result
159159
assert "\\u4e16" not in result
160-
160+
161161
# Verify the JSON is valid
162162
parsed = json.loads(result)
163163
assert parsed["message"] == "Hello 世界"
@@ -167,15 +167,15 @@ def test_ensure_ascii_false(time):
167167
def test_ensure_ascii_false_with_emoji(time):
168168
"""Test that ensure_ascii=False preserves emoji and special characters"""
169169
time.return_value = 1584720997.187709
170-
170+
171171
formatter = ecs_logging.StructlogFormatter(ensure_ascii=False)
172172
result = formatter(None, "info", {"event": "Café ☕ 你好", "log.logger": "test"})
173-
173+
174174
# With ensure_ascii=False, all non-ASCII characters should be preserved
175175
assert "Café" in result
176176
assert "☕" in result
177177
assert "你好" in result
178-
178+
179179
# Verify the JSON is valid and correctly decoded
180180
parsed = json.loads(result)
181181
assert parsed["message"] == "Café ☕ 你好"
@@ -185,7 +185,7 @@ def test_ensure_ascii_false_with_emoji(time):
185185
def test_ensure_ascii_with_custom_fields(time):
186186
"""Test that ensure_ascii works with custom fields containing non-ASCII"""
187187
time.return_value = 1584720997.187709
188-
188+
189189
formatter = ecs_logging.StructlogFormatter(ensure_ascii=False)
190190
result = formatter(
191191
None,
@@ -197,11 +197,11 @@ def test_ensure_ascii_with_custom_fields(time):
197197
"city": "北京",
198198
},
199199
)
200-
200+
201201
# With ensure_ascii=False, non-ASCII in custom fields should be preserved
202202
assert "用户" in result
203203
assert "北京" in result
204-
204+
205205
# Verify the JSON is valid
206206
parsed = json.loads(result)
207207
assert parsed["user"] == "用户"

0 commit comments

Comments
 (0)