Fix power meter CLI error handling
This commit is contained in:
+16
-1
@@ -3,7 +3,7 @@ import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -12,6 +12,21 @@ from production_analytics.enlyze.exploration import ExplorationResponse
|
||||
|
||||
|
||||
class CliTests(unittest.TestCase):
|
||||
def test_power_meter_config_error_returns_controlled_exit_code(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary_directory:
|
||||
missing_config = Path(temporary_directory) / "missing.yaml"
|
||||
error_output = io.StringIO()
|
||||
with redirect_stderr(error_output):
|
||||
result = main([
|
||||
"run", "power-meter", "--config", str(missing_config), "--meter", "B2",
|
||||
"--start", "2026-10-01T10:00:00Z", "--end", "2026-10-01T10:10:00Z",
|
||||
])
|
||||
|
||||
self.assertEqual(result, 2)
|
||||
self.assertIn(
|
||||
"Config/startup error: Cannot read power-meter configuration", error_output.getvalue()
|
||||
)
|
||||
|
||||
@patch.dict(os.environ, {"ENLYZE_BASE_URL": "https://enlyze.example"}, clear=True)
|
||||
@patch("production_analytics.cli.__main__.ExplorationClient.get")
|
||||
def test_raw_prints_and_saves_sanitized_response(self, get_mock: object) -> None:
|
||||
|
||||
Reference in New Issue
Block a user