Skip to content

Commit bfe79f8

Browse files
committed
style: fix ruff linting issues
- Apply ruff auto-fixes for 36 code style issues - Convert datetime.timezone.utc to datetime.UTC alias - Ensure code quality standards compliance
1 parent 94ad889 commit bfe79f8

6 files changed

Lines changed: 44 additions & 42 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ site/
7777
.mkdocs_cache/
7878

7979
PYPI_DISTRIBUTION_PLAN.md
80-
MockLoop_CLI*
80+
MockLoop_CLI*
81+
82+
.roo

src/mockloop_mcp/mcp_audit_logger.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sqlite3
1010
import time
1111
import uuid
12-
from datetime import datetime, timezone
12+
from datetime import datetime, timezone, UTC
1313
from pathlib import Path
1414
from typing import Any, Union
1515
import hashlib
@@ -312,7 +312,7 @@ def log_tool_execution(
312312
Unique entry ID for the logged event
313313
"""
314314
entry_id = str(uuid.uuid4())
315-
timestamp = datetime.now(timezone.utc).isoformat()
315+
timestamp = datetime.now(UTC).isoformat()
316316

317317
# Generate content hash if enabled
318318
content_hash = None
@@ -433,7 +433,7 @@ def log_resource_access(
433433
Unique entry ID for the logged event
434434
"""
435435
entry_id = str(uuid.uuid4())
436-
timestamp = datetime.now(timezone.utc).isoformat()
436+
timestamp = datetime.now(UTC).isoformat()
437437

438438
# Generate content hash if enabled
439439
content_hash = None
@@ -542,7 +542,7 @@ def log_context_operation(
542542
Unique entry ID for the logged event
543543
"""
544544
entry_id = str(uuid.uuid4())
545-
timestamp = datetime.now(timezone.utc).isoformat()
545+
timestamp = datetime.now(UTC).isoformat()
546546

547547
try:
548548
with sqlite3.connect(self.db_path) as conn:
@@ -624,7 +624,7 @@ def log_prompt_invocation(
624624
Unique entry ID for the logged event
625625
"""
626626
entry_id = str(uuid.uuid4())
627-
timestamp = datetime.now(timezone.utc).isoformat()
627+
timestamp = datetime.now(UTC).isoformat()
628628

629629
# Use generated_output if provided, otherwise use execution_result
630630
output_data = (
@@ -781,7 +781,7 @@ def cleanup_expired_logs(self) -> int:
781781
Number of deleted log entries
782782
"""
783783
try:
784-
current_time = datetime.now(timezone.utc).isoformat()
784+
current_time = datetime.now(UTC).isoformat()
785785

786786
with sqlite3.connect(self.db_path) as conn:
787787
cursor = conn.cursor()

src/mockloop_mcp/mcp_compliance.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import csv
1313
import json
1414
import sqlite3
15-
from datetime import datetime, timezone, timedelta
15+
from datetime import datetime, timezone, timedelta, UTC
1616
from pathlib import Path
1717
from typing import Any, Optional, Union
1818
from dataclasses import dataclass
@@ -164,9 +164,9 @@ def generate_compliance_report(
164164

165165
# Set default date range if not provided
166166
if not end_date:
167-
end_date = datetime.now(timezone.utc).isoformat()
167+
end_date = datetime.now(UTC).isoformat()
168168
if not start_date:
169-
start_date = (datetime.now(timezone.utc) - timedelta(days=30)).isoformat()
169+
start_date = (datetime.now(UTC) - timedelta(days=30)).isoformat()
170170

171171
# Query audit logs for the period
172172
audit_logs = self._query_audit_logs(start_date, end_date)
@@ -179,7 +179,7 @@ def generate_compliance_report(
179179
report_id=self._generate_report_id(),
180180
report_type=f"{regulation.value}_compliance",
181181
regulation=regulation.value,
182-
generated_at=datetime.now(timezone.utc).isoformat(),
182+
generated_at=datetime.now(UTC).isoformat(),
183183
period_start=start_date,
184184
period_end=end_date,
185185
total_operations=len(audit_logs),
@@ -357,7 +357,7 @@ def generate_data_lineage_report(
357357
"source_statistics": source_stats,
358358
"total_entries": len(lineage_map),
359359
"unique_sources": len(source_stats),
360-
"generated_at": datetime.now(timezone.utc).isoformat(),
360+
"generated_at": datetime.now(UTC).isoformat(),
361361
}
362362

363363
def check_retention_compliance(self) -> dict[str, Any]:
@@ -367,7 +367,7 @@ def check_retention_compliance(self) -> dict[str, Any]:
367367
Returns:
368368
Retention compliance report
369369
"""
370-
current_time = datetime.now(timezone.utc)
370+
current_time = datetime.now(UTC)
371371

372372
with sqlite3.connect(str(self.audit_db_path)) as conn:
373373
conn.row_factory = sqlite3.Row
@@ -434,7 +434,7 @@ def purge_expired_data(self, dry_run: bool = True) -> dict[str, Any]:
434434
Returns:
435435
Purge operation results
436436
"""
437-
current_time = datetime.now(timezone.utc)
437+
current_time = datetime.now(UTC)
438438

439439
with sqlite3.connect(str(self.audit_db_path)) as conn:
440440
conn.row_factory = sqlite3.Row
@@ -529,7 +529,7 @@ def generate_privacy_impact_assessment(
529529
"risk_analysis": risk_analysis,
530530
"recommendations": recommendations,
531531
"compliance_status": risk_analysis.get("overall_risk_level", "unknown"),
532-
"generated_at": datetime.now(timezone.utc).isoformat(),
532+
"generated_at": datetime.now(UTC).isoformat(),
533533
}
534534

535535
def _query_audit_logs(
@@ -634,7 +634,7 @@ def _analyze_compliance(
634634
"metadata": {
635635
"regulation": regulation.value,
636636
"total_logs_analyzed": len(audit_logs),
637-
"analysis_timestamp": datetime.now(timezone.utc).isoformat(),
637+
"analysis_timestamp": datetime.now(UTC).isoformat(),
638638
},
639639
}
640640

src/mockloop_mcp/mcp_resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import hashlib
2727
from functools import wraps
2828
from typing import Any, Optional
29-
from datetime import datetime, timezone
29+
from datetime import datetime, timezone, UTC
3030

3131
# Handle imports for different execution contexts
3232
if __package__ is None or __package__ == "":
@@ -43,7 +43,7 @@
4343
# Resource metadata and versioning
4444
RESOURCE_VERSION = "1.0.0"
4545
RESOURCE_SCHEMA_VERSION = "1.0"
46-
LAST_UPDATED = datetime.now(timezone.utc).isoformat()
46+
LAST_UPDATED = datetime.now(UTC).isoformat()
4747

4848
# Resource categories and their scenario packs
4949
SCENARIO_PACK_CATEGORIES = {
@@ -1496,5 +1496,5 @@ def get_resource_integrity_info(pack_data: dict[str, Any]) -> dict[str, Any]:
14961496
"is_valid": is_valid,
14971497
"validation_errors": errors,
14981498
"content_size": len(json.dumps(pack_data)),
1499-
"last_validated": datetime.now(timezone.utc).isoformat(),
1499+
"last_validated": datetime.now(UTC).isoformat(),
15001500
}

src/mockloop_mcp/mcp_tools.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import logging
2222
import time
2323
import uuid
24-
from datetime import datetime, timezone
24+
from datetime import datetime, timezone, UTC
2525
from functools import wraps
2626
from pathlib import Path
2727
from typing import Any, Optional, Union
@@ -874,7 +874,7 @@ async def run_test_iteration(
874874
# Record start time
875875
start_time = time.time()
876876
iteration_result["start_time"] = datetime.fromtimestamp(
877-
start_time, tz=timezone.utc
877+
start_time, tz=UTC
878878
).isoformat()
879879

880880
# Get initial metrics if monitoring is enabled
@@ -891,7 +891,7 @@ async def run_test_iteration(
891891
# Record end time
892892
end_time = time.time()
893893
iteration_result["end_time"] = datetime.fromtimestamp(
894-
end_time, tz=timezone.utc
894+
end_time, tz=UTC
895895
).isoformat()
896896

897897
# Collect final metrics
@@ -1114,7 +1114,7 @@ async def create_mcp_plugin(
11141114
"mode": mode,
11151115
"spec_source": spec_url_or_path,
11161116
"target_url": target_url,
1117-
"created_at": datetime.now(timezone.utc).isoformat(),
1117+
"created_at": datetime.now(UTC).isoformat(),
11181118
"plugin_config": {},
11191119
"mcp_config": {},
11201120
"mock_server_path": None,
@@ -1274,7 +1274,7 @@ async def create_mcp_plugin(
12741274
"mode": mode,
12751275
"spec_source": spec_url_or_path,
12761276
"error": f"Plugin creation failed: {e!s}",
1277-
"created_at": datetime.now(timezone.utc).isoformat(),
1277+
"created_at": datetime.now(UTC).isoformat(),
12781278
"plugin_config": {},
12791279
"mcp_config": {},
12801280
"mock_server_path": None,
@@ -1778,7 +1778,7 @@ def _generate_session_summary(session_data: dict[str, Any]) -> dict[str, Any]:
17781778
def _calculate_next_execution(schedule_config: dict[str, Any]) -> str:
17791779
"""Calculate next execution time."""
17801780
# Simplified implementation
1781-
return datetime.now(timezone.utc).isoformat()
1781+
return datetime.now(UTC).isoformat()
17821782

17831783

17841784
def _validate_test_suite(test_suite: dict[str, Any]) -> dict[str, bool]:
@@ -2246,7 +2246,7 @@ async def generate_test_report(
22462246
"report_id": str(uuid.uuid4()),
22472247
"report_format": report_format,
22482248
"output_format": output_format,
2249-
"generated_at": datetime.now(timezone.utc).isoformat(),
2249+
"generated_at": datetime.now(UTC).isoformat(),
22502250
"report_content": {},
22512251
"chart_data": None,
22522252
"export_data": None,
@@ -2299,7 +2299,7 @@ async def generate_test_report(
22992299
"report_format": report_format,
23002300
"output_format": output_format,
23012301
"error": f"Report generation failed: {e!s}",
2302-
"generated_at": datetime.now(timezone.utc).isoformat(),
2302+
"generated_at": datetime.now(UTC).isoformat(),
23032303
"report_content": {},
23042304
"chart_data": None,
23052305
"export_data": None,
@@ -2543,7 +2543,7 @@ async def create_test_session(
25432543
"status": "success",
25442544
"session_id": session_id,
25452545
"session_name": session_name,
2546-
"created_at": datetime.now(timezone.utc).isoformat(),
2546+
"created_at": datetime.now(UTC).isoformat(),
25472547
"test_plan": test_plan,
25482548
"session_config": session_config or {},
25492549
"session_state": "created",
@@ -2567,7 +2567,7 @@ async def create_test_session(
25672567
"session_id": None,
25682568
"session_name": session_name,
25692569
"error": f"Test session creation failed: {e!s}",
2570-
"created_at": datetime.now(timezone.utc).isoformat(),
2570+
"created_at": datetime.now(UTC).isoformat(),
25712571
"test_plan": {},
25722572
"session_config": {},
25732573
"session_state": "error",
@@ -2595,14 +2595,14 @@ async def end_test_session(
25952595
"status": "error",
25962596
"session_id": session_id,
25972597
"error": "Test session not found",
2598-
"ended_at": datetime.now(timezone.utc).isoformat(),
2598+
"ended_at": datetime.now(UTC).isoformat(),
25992599
"final_report": None,
26002600
"session_summary": {},
26012601
}
26022602

26032603
session_data = _active_test_sessions[session_id]
26042604
session_data["session_state"] = "completed"
2605-
session_data["ended_at"] = datetime.now(timezone.utc).isoformat()
2605+
session_data["ended_at"] = datetime.now(UTC).isoformat()
26062606

26072607
end_result = {
26082608
"status": "success",
@@ -2636,7 +2636,7 @@ async def end_test_session(
26362636
"status": "error",
26372637
"session_id": session_id,
26382638
"error": f"Test session completion failed: {e!s}",
2639-
"ended_at": datetime.now(timezone.utc).isoformat(),
2639+
"ended_at": datetime.now(UTC).isoformat(),
26402640
"final_report": None,
26412641
"session_summary": {},
26422642
}
@@ -2667,7 +2667,7 @@ async def schedule_test_suite(
26672667
"test_suite": test_suite,
26682668
"schedule_config": schedule_config,
26692669
"notification_config": notification_config or {},
2670-
"created_at": datetime.now(timezone.utc).isoformat(),
2670+
"created_at": datetime.now(UTC).isoformat(),
26712671
"next_execution": _calculate_next_execution(schedule_config),
26722672
"schedule_state": "active",
26732673
"validation_result": _validate_test_suite(test_suite),
@@ -2691,7 +2691,7 @@ async def schedule_test_suite(
26912691
"test_suite": {},
26922692
"schedule_config": {},
26932693
"notification_config": {},
2694-
"created_at": datetime.now(timezone.utc).isoformat(),
2694+
"created_at": datetime.now(UTC).isoformat(),
26952695
"next_execution": None,
26962696
"schedule_state": "error",
26972697
"validation_result": {"valid": False, "errors": []},
@@ -2722,7 +2722,7 @@ async def monitor_test_progress(
27222722
"progress": {},
27232723
"performance_data": {},
27242724
"alerts": [],
2725-
"monitoring_timestamp": datetime.now(timezone.utc).isoformat(),
2725+
"monitoring_timestamp": datetime.now(UTC).isoformat(),
27262726
}
27272727

27282728
session_data = _active_test_sessions[session_id]
@@ -2736,7 +2736,7 @@ async def monitor_test_progress(
27362736
"progress_percentage": _calculate_progress_percentage(progress),
27372737
"performance_data": {},
27382738
"alerts": [],
2739-
"monitoring_timestamp": datetime.now(timezone.utc).isoformat(),
2739+
"monitoring_timestamp": datetime.now(UTC).isoformat(),
27402740
}
27412741

27422742
# Include performance data if requested
@@ -2773,7 +2773,7 @@ async def monitor_test_progress(
27732773
"progress": {},
27742774
"performance_data": {},
27752775
"alerts": [],
2776-
"monitoring_timestamp": datetime.now(timezone.utc).isoformat(),
2776+
"monitoring_timestamp": datetime.now(UTC).isoformat(),
27772777
}
27782778

27792779

@@ -3099,7 +3099,7 @@ async def _register_mcp_plugin(plugin_config: PluginConfig) -> dict[str, Any]:
30993099
"status": "success",
31003100
"registered": True,
31013101
"plugin_id": plugin_config.mcp_server_name,
3102-
"registration_time": datetime.now(timezone.utc).isoformat(),
3102+
"registration_time": datetime.now(UTC).isoformat(),
31033103
"message": f"Plugin {plugin_config.plugin_name} registered successfully",
31043104
}
31053105

@@ -3111,7 +3111,7 @@ async def _register_mcp_plugin(plugin_config: PluginConfig) -> dict[str, Any]:
31113111
"status": "error",
31123112
"registered": False,
31133113
"error": str(e),
3114-
"registration_time": datetime.now(timezone.utc).isoformat(),
3114+
"registration_time": datetime.now(UTC).isoformat(),
31153115
}
31163116

31173117

tests/unit/test_mcp_audit_logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sqlite3
1313
import tempfile
1414
import unittest
15-
from datetime import datetime, timezone
15+
from datetime import datetime, timezone, UTC
1616
from pathlib import Path
1717
from unittest.mock import AsyncMock, MagicMock, patch
1818

@@ -287,7 +287,7 @@ def test_cleanup_expired_logs(self):
287287
cursor = conn.cursor()
288288

289289
# Insert a log entry that's already expired
290-
past_time = datetime.now(timezone.utc).replace(year=2020).isoformat()
290+
past_time = datetime.now(UTC).replace(year=2020).isoformat()
291291
cursor.execute(
292292
"""
293293
INSERT INTO mcp_audit_logs (
@@ -490,7 +490,7 @@ def test_purge_expired_data_dry_run(self):
490490
# First, create an expired entry
491491
with sqlite3.connect(str(self.db_path)) as conn:
492492
cursor = conn.cursor()
493-
past_time = datetime.now(timezone.utc).replace(year=2020).isoformat()
493+
past_time = datetime.now(UTC).replace(year=2020).isoformat()
494494
cursor.execute(
495495
"""
496496
INSERT INTO mcp_audit_logs (

0 commit comments

Comments
 (0)