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
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:
@@ -103,7 +103,7 @@ jobs:
|
|||||||
- name: Run code formatting check
|
- name: Run code formatting check
|
||||||
run: |
|
run: |
|
||||||
black --check .
|
black --check .
|
||||||
isort --check-only .
|
isort --check-only --profile black .
|
||||||
|
|
||||||
- name: Run linting
|
- name: Run linting
|
||||||
run: flake8 . --count --max-complexity=10 --max-line-length=150
|
run: flake8 . --count --max-complexity=10 --max-line-length=150
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ jobs:
|
|||||||
- name: Run code formatting check
|
- name: Run code formatting check
|
||||||
run: |
|
run: |
|
||||||
black --check --diff .
|
black --check --diff .
|
||||||
isort --check-only --diff .
|
isort --check-only --diff --profile black .
|
||||||
|
|
||||||
- name: Run linting
|
- name: Run linting
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -217,16 +217,12 @@ async def get_ha_entities():
|
|||||||
HAEntity(
|
HAEntity(
|
||||||
entity_id="sensor.cpu_usage",
|
entity_id="sensor.cpu_usage",
|
||||||
state="45.2",
|
state="45.2",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="%", friendly_name="CPU Usage"),
|
||||||
unit_of_measurement="%", friendly_name="CPU Usage"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
HAEntity(
|
HAEntity(
|
||||||
entity_id="sensor.memory_usage",
|
entity_id="sensor.memory_usage",
|
||||||
state="2.1",
|
state="2.1",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="GB", friendly_name="Memory Usage"),
|
||||||
unit_of_measurement="GB", friendly_name="Memory Usage"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -340,11 +336,7 @@ async def publish_event(event_data: EventData, background_tasks: BackgroundTasks
|
|||||||
},
|
},
|
||||||
tags=["Events"],
|
tags=["Events"],
|
||||||
)
|
)
|
||||||
async def get_events(
|
async def get_events(limit: int = Query(100, ge=1, le=1000, description="Maximum number of events to retrieve")):
|
||||||
limit: int = Query(
|
|
||||||
100, ge=1, le=1000, description="Maximum number of events to retrieve"
|
|
||||||
)
|
|
||||||
):
|
|
||||||
"""Get recent events from the Redis message bus"""
|
"""Get recent events from the Redis message bus"""
|
||||||
try:
|
try:
|
||||||
events = redis_client.lrange("events", 0, limit - 1)
|
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(
|
return HAEntity(
|
||||||
entity_id=entity_id,
|
entity_id=entity_id,
|
||||||
state="unknown",
|
state="unknown",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="", friendly_name=f"Entity {entity_id}"),
|
||||||
unit_of_measurement="", friendly_name=f"Entity {entity_id}"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
28
services/service-adapters/pyproject.toml
Normal file
28
services/service-adapters/pyproject.toml
Normal 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"]
|
||||||
@@ -49,11 +49,7 @@ async def publish_event(event_data: EventData, background_tasks: BackgroundTasks
|
|||||||
},
|
},
|
||||||
tags=["Events"],
|
tags=["Events"],
|
||||||
)
|
)
|
||||||
async def get_events(
|
async def get_events(limit: int = Query(100, ge=1, le=1000, description="Maximum number of events to retrieve")):
|
||||||
limit: int = Query(
|
|
||||||
100, ge=1, le=1000, description="Maximum number of events to retrieve"
|
|
||||||
)
|
|
||||||
):
|
|
||||||
"""Get recent events from the Redis message bus"""
|
"""Get recent events from the Redis message bus"""
|
||||||
try:
|
try:
|
||||||
events = redis_client.lrange("events", 0, limit - 1)
|
events = redis_client.lrange("events", 0, limit - 1)
|
||||||
|
|||||||
@@ -32,16 +32,12 @@ async def get_ha_entities():
|
|||||||
HAEntity(
|
HAEntity(
|
||||||
entity_id="sensor.cpu_usage",
|
entity_id="sensor.cpu_usage",
|
||||||
state="45.2",
|
state="45.2",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="%", friendly_name="CPU Usage"),
|
||||||
unit_of_measurement="%", friendly_name="CPU Usage"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
HAEntity(
|
HAEntity(
|
||||||
entity_id="sensor.memory_usage",
|
entity_id="sensor.memory_usage",
|
||||||
state="2.1",
|
state="2.1",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="GB", friendly_name="Memory Usage"),
|
||||||
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(
|
return HAEntity(
|
||||||
entity_id=entity_id,
|
entity_id=entity_id,
|
||||||
state="unknown",
|
state="unknown",
|
||||||
attributes=HAAttributes(
|
attributes=HAAttributes(unit_of_measurement="", friendly_name=f"Entity {entity_id}"),
|
||||||
unit_of_measurement="", friendly_name=f"Entity {entity_id}"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ class TestHomeAssistantRoutes:
|
|||||||
async def test_get_entities_connection_error(self, mock_client_class):
|
async def test_get_entities_connection_error(self, mock_client_class):
|
||||||
"""Test handling of connection errors"""
|
"""Test handling of connection errors"""
|
||||||
# Mock connection error
|
# Mock connection error
|
||||||
mock_client_class.return_value.__aenter__.side_effect = Exception(
|
mock_client_class.return_value.__aenter__.side_effect = Exception("Connection failed")
|
||||||
"Connection failed"
|
|
||||||
)
|
|
||||||
|
|
||||||
response = client.get("/home-assistant/entities")
|
response = client.get("/home-assistant/entities")
|
||||||
assert response.status_code == 500
|
assert response.status_code == 500
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from models.schemas import (EventData, FrigateEvent, HAAttributes, HAEntity,
|
from models.schemas import EventData, FrigateEvent, HAAttributes, HAEntity, HealthResponse, RootResponse, ServiceStatus
|
||||||
HealthResponse, RootResponse, ServiceStatus)
|
|
||||||
|
|
||||||
|
|
||||||
class TestServiceStatus:
|
class TestServiceStatus:
|
||||||
@@ -15,9 +14,7 @@ class TestServiceStatus:
|
|||||||
|
|
||||||
def test_service_status_creation(self):
|
def test_service_status_creation(self):
|
||||||
"""Test creating a ServiceStatus instance"""
|
"""Test creating a ServiceStatus instance"""
|
||||||
service = ServiceStatus(
|
service = ServiceStatus(enabled=True, url="http://example.com", status="healthy")
|
||||||
enabled=True, url="http://example.com", status="healthy"
|
|
||||||
)
|
|
||||||
assert service.enabled is True
|
assert service.enabled is True
|
||||||
assert service.url == "http://example.com"
|
assert service.url == "http://example.com"
|
||||||
assert service.status == "healthy"
|
assert service.status == "healthy"
|
||||||
@@ -25,9 +22,7 @@ class TestServiceStatus:
|
|||||||
def test_service_status_validation(self):
|
def test_service_status_validation(self):
|
||||||
"""Test ServiceStatus validation"""
|
"""Test ServiceStatus validation"""
|
||||||
# Valid data
|
# Valid data
|
||||||
service = ServiceStatus(
|
service = ServiceStatus(enabled=False, url="https://api.example.com", status="unhealthy")
|
||||||
enabled=False, url="https://api.example.com", status="unhealthy"
|
|
||||||
)
|
|
||||||
assert service.enabled is False
|
assert service.enabled is False
|
||||||
|
|
||||||
def test_service_status_required_fields(self):
|
def test_service_status_required_fields(self):
|
||||||
@@ -41,9 +36,7 @@ class TestHAAttributes:
|
|||||||
|
|
||||||
def test_ha_attributes_creation(self):
|
def test_ha_attributes_creation(self):
|
||||||
"""Test creating HAAttributes instance"""
|
"""Test creating HAAttributes instance"""
|
||||||
attrs = HAAttributes(
|
attrs = HAAttributes(unit_of_measurement="°C", friendly_name="Living Room Temperature")
|
||||||
unit_of_measurement="°C", friendly_name="Living Room Temperature"
|
|
||||||
)
|
|
||||||
assert attrs.unit_of_measurement == "°C"
|
assert attrs.unit_of_measurement == "°C"
|
||||||
assert attrs.friendly_name == "Living Room Temperature"
|
assert attrs.friendly_name == "Living Room Temperature"
|
||||||
|
|
||||||
@@ -60,9 +53,7 @@ class TestHAEntity:
|
|||||||
def test_ha_entity_creation(self):
|
def test_ha_entity_creation(self):
|
||||||
"""Test creating HAEntity instance"""
|
"""Test creating HAEntity instance"""
|
||||||
attributes = HAAttributes(unit_of_measurement="°C", friendly_name="Temperature")
|
attributes = HAAttributes(unit_of_measurement="°C", friendly_name="Temperature")
|
||||||
entity = HAEntity(
|
entity = HAEntity(entity_id="sensor.temperature", state="22.5", attributes=attributes)
|
||||||
entity_id="sensor.temperature", state="22.5", attributes=attributes
|
|
||||||
)
|
|
||||||
assert entity.entity_id == "sensor.temperature"
|
assert entity.entity_id == "sensor.temperature"
|
||||||
assert entity.state == "22.5"
|
assert entity.state == "22.5"
|
||||||
assert entity.attributes.unit_of_measurement == "°C"
|
assert entity.attributes.unit_of_measurement == "°C"
|
||||||
|
|||||||
Reference in New Issue
Block a user