Skip to content

Commit 15445eb

Browse files
committed
style: apply ruff formatting to DurableContext test files
1 parent 2ce1c6d commit 15445eb

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

tests/functional/logger/required_dependencies/test_logger_durable_context.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def handler(event, context):
6666

6767
# THEN lambda contextual info from the unwrapped context should be in the logs
6868
log = capture_logging_output(stdout)
69-
69+
7070
expected_logger_context_keys = (
7171
"function_name",
7272
"function_memory_size",
@@ -75,7 +75,7 @@ def handler(event, context):
7575
)
7676
for key in expected_logger_context_keys:
7777
assert key in log
78-
78+
7979
# Verify the actual values match the embedded lambda_context
8080
assert log["function_name"] == durable_context.lambda_context.function_name
8181
assert log["function_memory_size"] == durable_context.lambda_context.memory_limit_in_mb
@@ -88,7 +88,7 @@ def test_inject_lambda_context_with_durable_context_log_event(durable_context, s
8888
"""Test that inject_lambda_context with log_event=True works with DurableContext."""
8989
# GIVEN Logger is initialized
9090
logger = Logger(service=service_name, stream=stdout)
91-
91+
9292
test_event = {"test_key": "test_value"}
9393

9494
# WHEN a lambda function is decorated with log_event=True and receives DurableContext
@@ -101,7 +101,7 @@ def handler(event, context):
101101
# THEN both the event and lambda contextual info should be logged
102102
logs = capture_multiple_logging_statements_output(stdout)
103103
assert len(logs) >= 2 # At least event log and info log
104-
104+
105105
# First log should be the event
106106
assert logs[0]["message"] == test_event
107107

@@ -121,11 +121,11 @@ def handler(event, context):
121121

122122
# THEN the custom key should be cleared and lambda context should be present
123123
log = capture_logging_output(stdout)
124-
124+
125125
# Lambda context fields should be present
126126
assert "function_name" in log
127127
assert log["function_name"] == durable_context.lambda_context.function_name
128-
128+
129129
# Custom key should not be present (cleared)
130130
assert "custom_key" not in log or log.get("custom_key") != "initial_value"
131131

@@ -144,7 +144,7 @@ def handler(event, context):
144144

145145
# THEN lambda contextual info should be in the logs
146146
log = capture_logging_output(stdout)
147-
147+
148148
expected_logger_context_keys = (
149149
"function_name",
150150
"function_memory_size",
@@ -153,6 +153,6 @@ def handler(event, context):
153153
)
154154
for key in expected_logger_context_keys:
155155
assert key in log
156-
156+
157157
assert log["function_name"] == lambda_context.function_name
158158
assert log["message"] == "Hello from standard lambda"

tests/functional/metrics/required_dependencies/test_metrics_durable_context.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import pytest
88

99
from aws_lambda_powertools import Metrics
10-
from aws_lambda_powertools.utilities.typing import DurableContextProtocol
1110

1211
# Reset cold start flag before each test
1312
from aws_lambda_powertools.metrics.provider import cold_start
13+
from aws_lambda_powertools.utilities.typing import DurableContextProtocol
1414

1515

1616
def capture_metrics_output(capsys):
@@ -66,22 +66,22 @@ def lambda_handler(evt, context):
6666

6767
# THEN metrics should be emitted successfully
6868
output = capture_metrics_output(capsys)
69-
69+
7070
assert output["test_metric"] == [1.0]
7171
assert output["service"] == service
7272

7373

7474
def test_log_metrics_capture_cold_start_with_durable_context(capsys, namespace, service):
7575
"""Test that capture_cold_start_metric works with DurableContext."""
7676
reset_cold_start_flag()
77-
77+
7878
# GIVEN Metrics is initialized
7979
my_metrics = Metrics(service=service, namespace=namespace)
80-
80+
8181
# Create a DurableContext with embedded Lambda context
8282
LambdaContext = namedtuple("LambdaContext", "function_name")
8383
lambda_ctx = LambdaContext("durable_test_function")
84-
84+
8585
durable_ctx = Mock(spec=DurableContextProtocol)
8686
durable_ctx.lambda_context = lambda_ctx
8787
durable_ctx.state = Mock(operations=[{"id": "op1"}])
@@ -95,27 +95,25 @@ def lambda_handler(evt, context):
9595

9696
# THEN ColdStart metric should be captured with the function name from unwrapped context
9797
outputs = capture_metrics_output_multiple_emf_objects(capsys)
98-
98+
9999
# Cold start is in a separate EMF blob
100100
cold_start_output = outputs[0]
101101
assert cold_start_output["ColdStart"] == [1.0]
102102
assert cold_start_output["function_name"] == "durable_test_function"
103103
assert cold_start_output["service"] == service
104104

105105

106-
def test_log_metrics_capture_cold_start_with_durable_context_explicit_function_name(
107-
capsys, namespace, service
108-
):
106+
def test_log_metrics_capture_cold_start_with_durable_context_explicit_function_name(capsys, namespace, service):
109107
"""Test capture_cold_start_metric with explicit function_name and DurableContext."""
110108
reset_cold_start_flag()
111-
109+
112110
# GIVEN Metrics is initialized with explicit function_name
113111
my_metrics = Metrics(service=service, namespace=namespace, function_name="explicit_function")
114-
112+
115113
# Create a DurableContext
116114
LambdaContext = namedtuple("LambdaContext", "function_name")
117115
lambda_ctx = LambdaContext("context_function")
118-
116+
119117
durable_ctx = Mock(spec=DurableContextProtocol)
120118
durable_ctx.lambda_context = lambda_ctx
121119
durable_ctx.state = Mock(operations=[{"id": "op1"}])
@@ -129,7 +127,7 @@ def lambda_handler(evt, context):
129127

130128
# THEN explicit function_name should take priority
131129
output = capture_metrics_output(capsys)
132-
130+
133131
assert output.get("function_name") == "explicit_function"
134132

135133

@@ -147,18 +145,18 @@ def lambda_handler(evt, context):
147145

148146
# THEN metrics should be emitted successfully
149147
output = capture_metrics_output(capsys)
150-
148+
151149
assert output["regression_test"] == [42.0]
152150
assert output["service"] == service
153151

154152

155153
def test_log_metrics_capture_cold_start_standard_context_still_works(capsys, namespace, service):
156154
"""Test that capture_cold_start_metric with standard context still works (regression test)."""
157155
reset_cold_start_flag()
158-
156+
159157
# GIVEN Metrics is initialized
160158
my_metrics = Metrics(service=service, namespace=namespace)
161-
159+
162160
LambdaContext = namedtuple("LambdaContext", "function_name")
163161
standard_context = LambdaContext("standard_function")
164162

@@ -171,6 +169,6 @@ def lambda_handler(evt, context):
171169

172170
# THEN ColdStart metric should be captured
173171
output = capture_metrics_output(capsys)
174-
172+
175173
assert "ColdStart" in output or output.get("ColdStart") == [1.0]
176174
assert output.get("function_name") == "standard_function"

0 commit comments

Comments
 (0)