Skip to content

Commit 6649019

Browse files
committed
chore: update CLI to accept log level as string
1 parent 85bae2a commit 6649019

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

src/aws_durable_execution_sdk_python_testing/cli.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CliConfig:
4444
# Server configuration
4545
host: str = "0.0.0.0" # noqa:S104
4646
port: int = 5000
47-
log_level: int = 20 # INFO level
47+
log_level: str = "info"
4848
lambda_endpoint: str = "http://127.0.0.1:3001"
4949
local_runner_endpoint: str = "http://0.0.0.0:5000"
5050
local_runner_region: str = "us-west-2"
@@ -56,7 +56,7 @@ def from_environment(cls) -> CliConfig:
5656
return cls(
5757
host=os.getenv("AWS_DEX_HOST", "0.0.0.0"), # noqa:S104
5858
port=int(os.getenv("AWS_DEX_PORT", "5000")),
59-
log_level=int(os.getenv("AWS_DEX_LOG_LEVEL", "20")),
59+
log_level=os.getenv("AWS_DEX_LOG_LEVEL", "info"),
6060
lambda_endpoint=os.getenv(
6161
"AWS_DEX_LAMBDA_ENDPOINT", "http://127.0.0.1:3001"
6262
),
@@ -89,10 +89,14 @@ def run(self, args: list[str] | None = None) -> int:
8989
parsed_args = parser.parse_args(args)
9090

9191
# Configure logging based on log level
92-
logging.basicConfig(
93-
level=parsed_args.log_level
92+
level_name = (
93+
parsed_args.log_level.upper()
9494
if hasattr(parsed_args, "log_level")
95-
else self.config.log_level,
95+
else self.config.log_level.upper()
96+
)
97+
level = logging.getLevelNamesMapping().get(level_name, logging.INFO)
98+
logging.basicConfig(
99+
level=level,
96100
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
97101
)
98102

@@ -151,9 +155,10 @@ def _create_start_server_parser(self, subparsers) -> None:
151155
)
152156
start_server_parser.add_argument(
153157
"--log-level",
154-
type=int,
158+
type=str,
159+
choices=[level.lower() for level in logging.getLevelNamesMapping().keys()],
155160
default=self.config.log_level,
156-
help=f"Logging level as integer (default: {self.config.log_level}, env: AWS_DEX_LOG_LEVEL)",
161+
help=f"Logging level (default: {self.config.log_level}, env: AWS_DEX_LOG_LEVEL)",
157162
)
158163
start_server_parser.add_argument(
159164
"--lambda-endpoint",

tests/cli_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_cli_config_has_correct_default_values() -> None:
2424

2525
assert config.host == "0.0.0.0" # noqa: S104
2626
assert config.port == 5000
27-
assert config.log_level == 20
27+
assert config.log_level == "info"
2828
assert config.lambda_endpoint == "http://127.0.0.1:3001"
2929
assert config.local_runner_endpoint == "http://0.0.0.0:5000"
3030
assert config.local_runner_region == "us-west-2"
@@ -38,7 +38,7 @@ def test_cli_config_from_environment_uses_defaults_when_no_env_vars() -> None:
3838

3939
assert config.host == "0.0.0.0" # noqa: S104
4040
assert config.port == 5000
41-
assert config.log_level == 20
41+
assert config.log_level == "info"
4242
assert config.lambda_endpoint == "http://127.0.0.1:3001"
4343
assert config.local_runner_endpoint == "http://0.0.0.0:5000"
4444
assert config.local_runner_region == "us-west-2"
@@ -50,7 +50,7 @@ def test_cli_config_from_environment_uses_all_env_vars_when_set() -> None:
5050
env_vars = {
5151
"AWS_DEX_HOST": "127.0.0.1",
5252
"AWS_DEX_PORT": "8080",
53-
"AWS_DEX_LOG_LEVEL": "10",
53+
"AWS_DEX_LOG_LEVEL": "debug",
5454
"AWS_DEX_LAMBDA_ENDPOINT": "http://localhost:4000",
5555
"AWS_DEX_LOCAL_RUNNER_ENDPOINT": "http://localhost:8080",
5656
"AWS_DEX_LOCAL_RUNNER_REGION": "us-east-1",
@@ -62,7 +62,7 @@ def test_cli_config_from_environment_uses_all_env_vars_when_set() -> None:
6262

6363
assert config.host == "127.0.0.1"
6464
assert config.port == 8080
65-
assert config.log_level == 10
65+
assert config.log_level == "debug"
6666
assert config.lambda_endpoint == "http://localhost:4000"
6767
assert config.local_runner_endpoint == "http://localhost:8080"
6868
assert config.local_runner_region == "us-east-1"
@@ -82,7 +82,7 @@ def test_cli_config_from_environment_uses_partial_env_vars_with_defaults() -> No
8282
assert config.host == "192.168.1.1"
8383
assert config.port == 9000
8484
# Other values should be defaults
85-
assert config.log_level == 20
85+
assert config.log_level == "info"
8686
assert config.lambda_endpoint == "http://127.0.0.1:3001"
8787

8888

@@ -173,7 +173,7 @@ def test_start_server_command_parses_arguments_correctly() -> None:
173173
"--port",
174174
"8080",
175175
"--log-level",
176-
"10",
176+
"debug",
177177
"--lambda-endpoint",
178178
"http://localhost:4000",
179179
"--local-runner-endpoint",
@@ -303,7 +303,7 @@ def test_logging_configuration_uses_specified_log_level() -> None:
303303
with patch("logging.basicConfig") as mock_basic_config:
304304
with patch("sys.stdout", new_callable=StringIO):
305305
with patch.object(app, "start_server_command", return_value=0):
306-
app.run(["start-server", "--log-level", "10"])
306+
app.run(["start-server", "--log-level", "debug"])
307307

308308
mock_basic_config.assert_called_once()
309309
call_args = mock_basic_config.call_args
@@ -348,7 +348,7 @@ def test_start_server_command_works_with_mocked_dependencies() -> None:
348348
"--port",
349349
"8080",
350350
"--log-level",
351-
"10",
351+
"debug",
352352
]
353353
)
354354

@@ -359,7 +359,7 @@ def test_start_server_command_works_with_mocked_dependencies() -> None:
359359
call_args = mock_web_runner.call_args[0][0] # First positional argument
360360
assert call_args.web_service.host == "127.0.0.1"
361361
assert call_args.web_service.port == 8080
362-
assert call_args.web_service.log_level == 10
362+
assert call_args.web_service.log_level == "debug"
363363

364364

365365
def test_start_server_command_handles_server_startup_errors() -> None:
@@ -398,7 +398,7 @@ def test_start_server_command_creates_correct_web_runner_config() -> None:
398398
"--port",
399399
"9000",
400400
"--log-level",
401-
"30",
401+
"warning",
402402
"--lambda-endpoint",
403403
"http://custom-lambda:4000",
404404
"--local-runner-endpoint",
@@ -419,7 +419,7 @@ def test_start_server_command_creates_correct_web_runner_config() -> None:
419419
# Verify web service configuration
420420
assert config.web_service.host == "192.168.1.100"
421421
assert config.web_service.port == 9000
422-
assert config.web_service.log_level == 30
422+
assert config.web_service.log_level == "warning"
423423

424424
# Verify Lambda service configuration
425425
assert config.lambda_endpoint == "http://custom-lambda:4000"

tests/runner_web_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def test_should_pass_correct_configuration_to_web_server():
705705
"""Test that WebServer receives correct configuration from WebRunnerConfig."""
706706
# Arrange
707707
web_config = WebServiceConfig(
708-
host="custom-host", port=9999, log_level=30, max_request_size=2048
708+
host="custom-host", port=9999, log_level="warning", max_request_size=2048
709709
)
710710
runner_config = WebRunnerConfig(web_service=web_config)
711711
runner = WebRunner(runner_config)
@@ -734,7 +734,7 @@ def test_should_pass_correct_configuration_to_web_server():
734734
assert passed_config == web_config
735735
assert passed_config.host == "custom-host"
736736
assert passed_config.port == 9999
737-
assert passed_config.log_level == 30
737+
assert passed_config.log_level == "warning"
738738
assert passed_config.max_request_size == 2048
739739

740740
# Cleanup
@@ -1284,7 +1284,7 @@ def test_should_integrate_with_cli_start_server_command():
12841284
"--port",
12851285
"7777",
12861286
"--log-level",
1287-
"30",
1287+
"warning",
12881288
"--lambda-endpoint",
12891289
"http://integration-lambda:4000",
12901290
"--local-runner-endpoint",
@@ -1306,7 +1306,7 @@ def test_should_integrate_with_cli_start_server_command():
13061306
# Verify web service configuration
13071307
assert config.web_service.host == "integration-host"
13081308
assert config.web_service.port == 7777
1309-
assert config.web_service.log_level == 30
1309+
assert config.web_service.log_level == "warning"
13101310

13111311
# Verify Lambda service configuration
13121312
assert config.lambda_endpoint == "http://integration-lambda:4000"
@@ -1430,7 +1430,7 @@ def test_should_preserve_cli_configuration_through_web_runner():
14301430
"--port",
14311431
"9999",
14321432
"--log-level",
1433-
"40", # ERROR level
1433+
"error", # ERROR level
14341434
"--lambda-endpoint",
14351435
"http://config-lambda:5000",
14361436
"--local-runner-endpoint",
@@ -1452,7 +1452,7 @@ def test_should_preserve_cli_configuration_through_web_runner():
14521452
# Verify web service configuration
14531453
assert config.web_service.host == "config-test-host"
14541454
assert config.web_service.port == 9999
1455-
assert config.web_service.log_level == 40
1455+
assert config.web_service.log_level == "error"
14561456

14571457
# Verify Lambda service configuration
14581458
assert config.lambda_endpoint == "http://config-lambda:5000"
@@ -1472,7 +1472,7 @@ def test_should_handle_environment_variable_integration():
14721472
env_vars = {
14731473
"AWS_DEX_HOST": "env-host",
14741474
"AWS_DEX_PORT": "8888",
1475-
"AWS_DEX_LOG_LEVEL": "50", # CRITICAL level
1475+
"AWS_DEX_LOG_LEVEL": "critical", # CRITICAL level
14761476
"AWS_DEX_LAMBDA_ENDPOINT": "http://env-lambda:6000",
14771477
"AWS_DEX_LOCAL_RUNNER_ENDPOINT": "http://env-runner:7000",
14781478
"AWS_DEX_LOCAL_RUNNER_REGION": "sa-east-1",
@@ -1505,7 +1505,7 @@ def test_should_handle_environment_variable_integration():
15051505
# Verify environment variables were used
15061506
assert config.web_service.host == "env-host"
15071507
assert config.web_service.port == 8888
1508-
assert config.web_service.log_level == 50
1508+
assert config.web_service.log_level == "critical"
15091509
assert config.lambda_endpoint == "http://env-lambda:6000"
15101510
assert config.local_runner_endpoint == "http://env-runner:7000"
15111511
assert config.local_runner_region == "sa-east-1"

0 commit comments

Comments
 (0)