fix: Standardize isort command in CI workflows
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 37s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m16s
Integration Tests / integration-tests (push) Failing after 58s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 12s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m42s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 46s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 47s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m53s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 45s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 28s

### Summary of Changes
- Updated the `isort` command in both CI workflows to include the `--profile black` option for consistent code formatting.
- Refactored function definitions in service adapters to improve readability by consolidating parameters into single lines.

### Expected Results
- Enhanced consistency in code formatting checks across CI workflows, ensuring adherence to the Black style guide.
- Improved readability and maintainability of function definitions in service adapters.
This commit is contained in:
GSRN
2025-09-15 21:16:37 +02:00
parent 8c37bff103
commit 4dc2f147ec
8 changed files with 44 additions and 47 deletions

View File

@@ -217,16 +217,12 @@ async def get_ha_entities():
HAEntity(
entity_id="sensor.cpu_usage",
state="45.2",
attributes=HAAttributes(
unit_of_measurement="%", friendly_name="CPU Usage"
),
attributes=HAAttributes(unit_of_measurement="%", friendly_name="CPU Usage"),
),
HAEntity(
entity_id="sensor.memory_usage",
state="2.1",
attributes=HAAttributes(
unit_of_measurement="GB", friendly_name="Memory Usage"
),
attributes=HAAttributes(unit_of_measurement="GB", friendly_name="Memory Usage"),
),
]
)
@@ -340,11 +336,7 @@ async def publish_event(event_data: EventData, background_tasks: BackgroundTasks
},
tags=["Events"],
)
async def get_events(
limit: int = Query(
100, ge=1, le=1000, description="Maximum number of events to retrieve"
)
):
async def get_events(limit: int = Query(100, ge=1, le=1000, description="Maximum number of events to retrieve")):
"""Get recent events from the Redis message bus"""
try:
events = redis_client.lrange("events", 0, limit - 1)
@@ -386,9 +378,7 @@ async def get_ha_entity(entity_id: str = Path(..., description="Entity ID")):
return HAEntity(
entity_id=entity_id,
state="unknown",
attributes=HAAttributes(
unit_of_measurement="", friendly_name=f"Entity {entity_id}"
),
attributes=HAAttributes(unit_of_measurement="", friendly_name=f"Entity {entity_id}"),
)

View File

@@ -0,0 +1,28 @@
[tool.black]
line-length = 150
target-version = ['py311']
include = '\.pyi?$'
extend-exclude = '''
/(
# directories
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| build
| dist
)/
'''
[tool.isort]
profile = "black"
line_length = 150
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
known_first_party = ["models", "routes", "services"]
known_third_party = ["fastapi", "pytest", "pydantic"]

View File

@@ -49,11 +49,7 @@ async def publish_event(event_data: EventData, background_tasks: BackgroundTasks
},
tags=["Events"],
)
async def get_events(
limit: int = Query(
100, ge=1, le=1000, description="Maximum number of events to retrieve"
)
):
async def get_events(limit: int = Query(100, ge=1, le=1000, description="Maximum number of events to retrieve")):
"""Get recent events from the Redis message bus"""
try:
events = redis_client.lrange("events", 0, limit - 1)

View File

@@ -32,16 +32,12 @@ async def get_ha_entities():
HAEntity(
entity_id="sensor.cpu_usage",
state="45.2",
attributes=HAAttributes(
unit_of_measurement="%", friendly_name="CPU Usage"
),
attributes=HAAttributes(unit_of_measurement="%", friendly_name="CPU Usage"),
),
HAEntity(
entity_id="sensor.memory_usage",
state="2.1",
attributes=HAAttributes(
unit_of_measurement="GB", friendly_name="Memory Usage"
),
attributes=HAAttributes(unit_of_measurement="GB", friendly_name="Memory Usage"),
),
]
)
@@ -72,7 +68,5 @@ async def get_ha_entity(entity_id: str = Path(..., description="Entity ID")):
return HAEntity(
entity_id=entity_id,
state="unknown",
attributes=HAAttributes(
unit_of_measurement="", friendly_name=f"Entity {entity_id}"
),
attributes=HAAttributes(unit_of_measurement="", friendly_name=f"Entity {entity_id}"),
)

View File

@@ -72,9 +72,7 @@ class TestHomeAssistantRoutes:
async def test_get_entities_connection_error(self, mock_client_class):
"""Test handling of connection errors"""
# Mock connection error
mock_client_class.return_value.__aenter__.side_effect = Exception(
"Connection failed"
)
mock_client_class.return_value.__aenter__.side_effect = Exception("Connection failed")
response = client.get("/home-assistant/entities")
assert response.status_code == 500

View File

@@ -6,8 +6,7 @@ from datetime import datetime
import pytest
from models.schemas import (EventData, FrigateEvent, HAAttributes, HAEntity,
HealthResponse, RootResponse, ServiceStatus)
from models.schemas import EventData, FrigateEvent, HAAttributes, HAEntity, HealthResponse, RootResponse, ServiceStatus
class TestServiceStatus:
@@ -15,9 +14,7 @@ class TestServiceStatus:
def test_service_status_creation(self):
"""Test creating a ServiceStatus instance"""
service = ServiceStatus(
enabled=True, url="http://example.com", status="healthy"
)
service = ServiceStatus(enabled=True, url="http://example.com", status="healthy")
assert service.enabled is True
assert service.url == "http://example.com"
assert service.status == "healthy"
@@ -25,9 +22,7 @@ class TestServiceStatus:
def test_service_status_validation(self):
"""Test ServiceStatus validation"""
# Valid data
service = ServiceStatus(
enabled=False, url="https://api.example.com", status="unhealthy"
)
service = ServiceStatus(enabled=False, url="https://api.example.com", status="unhealthy")
assert service.enabled is False
def test_service_status_required_fields(self):
@@ -41,9 +36,7 @@ class TestHAAttributes:
def test_ha_attributes_creation(self):
"""Test creating HAAttributes instance"""
attrs = HAAttributes(
unit_of_measurement="°C", friendly_name="Living Room Temperature"
)
attrs = HAAttributes(unit_of_measurement="°C", friendly_name="Living Room Temperature")
assert attrs.unit_of_measurement == "°C"
assert attrs.friendly_name == "Living Room Temperature"
@@ -60,9 +53,7 @@ class TestHAEntity:
def test_ha_entity_creation(self):
"""Test creating HAEntity instance"""
attributes = HAAttributes(unit_of_measurement="°C", friendly_name="Temperature")
entity = HAEntity(
entity_id="sensor.temperature", state="22.5", attributes=attributes
)
entity = HAEntity(entity_id="sensor.temperature", state="22.5", attributes=attributes)
assert entity.entity_id == "sensor.temperature"
assert entity.state == "22.5"
assert entity.attributes.unit_of_measurement == "°C"