Skip to content

Commit 1f22117

Browse files
Fix linting issues after removing __init__.py files
- Add TRY002 ignore for test files (generic exceptions are fine in tests) - Add INP001 ignore globally (we use implicit namespace packages intentionally) - Fix auto-fixable linting issues (unnecessary else/elif, trailing whitespace) - Format code with ruff format
1 parent db6b814 commit 1f22117

2 files changed

Lines changed: 75 additions & 62 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ignore = [
105105
"UP035", # typing.Dict is deprecated - global consistency
106106
"RUF013", # PEP 484 prohibits implicit Optional - global consistency
107107
"W293", # blank line contains whitespace - should be handled by formatter
108+
"INP001", # implicit namespace package - we use implicit packages intentionally
108109
# Docstring formatting - global consistency
109110
"D203", # incorrect-blank-line-before-class
110111
"D205", # line-between-summary-and-description
@@ -127,6 +128,7 @@ ignore = [
127128
"B007", # loop control variable not used within loop body
128129
"ARG001", # unused function argument (test helpers need to match expected signatures)
129130
"ARG002", # unused method argument
131+
"TRY002", # create your own exception (generic exceptions are fine in tests)
130132
"D104", # missing docstring in public package
131133
]
132134

tests/test_clearml_mcp.py

Lines changed: 73 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ def mock_get_task(task_id):
136136
task.get_project_name.return_value = "Project A"
137137
task.data.created = "2024-01-01T00:00:00Z"
138138
return task
139-
else:
140-
task = Mock()
141-
task.id = "task_2"
142-
task.name = "Experiment 2"
143-
task.status = "running"
144-
task.get_project_name.return_value = "Project B"
145-
task.data.created = "2024-01-02T00:00:00Z"
146-
return task
139+
task = Mock()
140+
task.id = "task_2"
141+
task.name = "Experiment 2"
142+
task.status = "running"
143+
task.get_project_name.return_value = "Project B"
144+
task.data.created = "2024-01-02T00:00:00Z"
145+
return task
147146

148147
mock_task.get_task.side_effect = mock_get_task
149148

@@ -212,19 +211,18 @@ async def test_handles_individual_task_retrieval_failure(self, mock_task):
212211
"""list_tasks handles failures when retrieving individual tasks."""
213212
# Arrange: Query succeeds but individual task retrieval fails
214213
mock_task.query_tasks.return_value = ["task_1", "task_2"]
215-
214+
216215
def mock_get_task(task_id):
217216
if task_id == "task_1":
218217
raise Exception("Task access denied")
219-
else:
220-
task = Mock()
221-
task.id = "task_2"
222-
task.name = "Working Task"
223-
task.status = "completed"
224-
task.get_project_name.return_value = "Project"
225-
task.data.created = "2024-01-01T00:00:00Z"
226-
task.data.tags = []
227-
return task
218+
task = Mock()
219+
task.id = "task_2"
220+
task.name = "Working Task"
221+
task.status = "completed"
222+
task.get_project_name.return_value = "Project"
223+
task.data.created = "2024-01-01T00:00:00Z"
224+
task.data.tags = []
225+
return task
228226

229227
mock_task.get_task.side_effect = mock_get_task
230228

@@ -689,22 +687,22 @@ def mock_get_task(task_id):
689687
task.get_project_name.return_value = "ML Project"
690688
task.data.created = "2024-01-01T00:00:00Z"
691689
return task
692-
elif task_id == "task_2":
690+
if task_id == "task_2":
693691
task = Mock()
694692
task.id = "task_2"
695693
task.name = "Validation Experiment"
696694
task.status = "running"
697695
task.get_project_name.return_value = "ML Project"
698696
task.data.created = "2024-01-02T00:00:00Z"
699697
return task
700-
else: # task_3
701-
task = Mock()
702-
task.id = "task_3"
703-
task.name = "Data Processing"
704-
task.status = "completed"
705-
task.get_project_name.return_value = "ML Project"
706-
task.data.created = "2024-01-03T00:00:00Z"
707-
return task
698+
# task_3
699+
task = Mock()
700+
task.id = "task_3"
701+
task.name = "Data Processing"
702+
task.status = "completed"
703+
task.get_project_name.return_value = "ML Project"
704+
task.data.created = "2024-01-03T00:00:00Z"
705+
return task
708706

709707
mock_task.get_task.side_effect = mock_get_task
710708

@@ -726,14 +724,13 @@ async def test_find_experiment_handles_task_access_failure(self, mock_task):
726724
def mock_get_task(task_id):
727725
if task_id == "task_1":
728726
raise Exception("Task access denied")
729-
else:
730-
task = Mock()
731-
task.id = "task_2"
732-
task.name = "Accessible Experiment"
733-
task.status = "completed"
734-
task.get_project_name.return_value = "ML Project"
735-
task.data.created = "2024-01-02T00:00:00Z"
736-
return task
727+
task = Mock()
728+
task.id = "task_2"
729+
task.name = "Accessible Experiment"
730+
task.status = "completed"
731+
task.get_project_name.return_value = "ML Project"
732+
task.data.created = "2024-01-02T00:00:00Z"
733+
return task
737734

738735
mock_task.get_task.side_effect = mock_get_task
739736

@@ -823,10 +820,26 @@ async def test_calculates_project_statistics(self, mock_task):
823820
"""get_project_stats returns project statistics correctly."""
824821
# Arrange: Create mock tasks with different statuses
825822
tasks = []
826-
statuses = ["created", "created", "queued", "in_progress", "in_progress", "in_progress",
827-
"stopped", "published", "published", "published", "closed", "failed", "failed",
828-
"completed", "completed", "completed", "completed"]
829-
823+
statuses = [
824+
"created",
825+
"created",
826+
"queued",
827+
"in_progress",
828+
"in_progress",
829+
"in_progress",
830+
"stopped",
831+
"published",
832+
"published",
833+
"published",
834+
"closed",
835+
"failed",
836+
"failed",
837+
"completed",
838+
"completed",
839+
"completed",
840+
"completed",
841+
]
842+
830843
for i, status in enumerate(statuses):
831844
task = Mock()
832845
task.status = status
@@ -865,6 +878,7 @@ class TestTaskComparison:
865878
@patch("clearml_mcp.clearml_mcp.Task")
866879
async def test_compares_multiple_tasks_with_specific_metrics(self, mock_task):
867880
"""compare_tasks compares specified metrics across tasks."""
881+
868882
# Arrange
869883
def mock_get_task(task_id):
870884
task = Mock()
@@ -931,7 +945,7 @@ async def test_compare_tasks_handles_empty_metrics_data(self, mock_task):
931945
task.status = "completed"
932946
task.get_reported_scalars.return_value = {
933947
"loss": {"train": {"y": []}}, # Empty data
934-
"accuracy": {"train": None}, # None data
948+
"accuracy": {"train": None}, # None data
935949
}
936950

937951
mock_task.get_task.return_value = task
@@ -977,16 +991,15 @@ def mock_get_task(task_id):
977991
task.data.tags = ["training", "neural"]
978992
task.comment = "Deep learning experiment"
979993
return task
980-
else:
981-
task = Mock()
982-
task.id = "task_2"
983-
task.name = "Data Preprocessing"
984-
task.status = "completed"
985-
task.get_project_name.return_value = "ML Project"
986-
task.data.created = "2024-01-02T00:00:00Z"
987-
task.data.tags = ["preprocessing"]
988-
task.comment = "Clean and prepare data"
989-
return task
994+
task = Mock()
995+
task.id = "task_2"
996+
task.name = "Data Preprocessing"
997+
task.status = "completed"
998+
task.get_project_name.return_value = "ML Project"
999+
task.data.created = "2024-01-02T00:00:00Z"
1000+
task.data.tags = ["preprocessing"]
1001+
task.comment = "Clean and prepare data"
1002+
return task
9901003

9911004
mock_task.get_task.side_effect = mock_get_task
9921005

@@ -1068,16 +1081,15 @@ async def test_search_tasks_handles_individual_task_failures(self, mock_task):
10681081
def mock_get_task(task_id):
10691082
if task_id == "task_1":
10701083
raise Exception("Task access denied")
1071-
else:
1072-
task = Mock()
1073-
task.id = "task_2"
1074-
task.name = "Accessible Task"
1075-
task.status = "completed"
1076-
task.get_project_name.return_value = "ML Project"
1077-
task.data.created = "2024-01-02T00:00:00Z"
1078-
task.data.tags = ["accessible"]
1079-
task.comment = "This works"
1080-
return task
1084+
task = Mock()
1085+
task.id = "task_2"
1086+
task.name = "Accessible Task"
1087+
task.status = "completed"
1088+
task.get_project_name.return_value = "ML Project"
1089+
task.data.created = "2024-01-02T00:00:00Z"
1090+
task.data.tags = ["accessible"]
1091+
task.comment = "This works"
1092+
return task
10811093

10821094
mock_task.get_task.side_effect = mock_get_task
10831095

@@ -1117,7 +1129,7 @@ def mock_get_task(task_id):
11171129
task.get_project_name.return_value = "ML Project"
11181130
task.data.created = "2024-01-01T00:00:00Z"
11191131
task.data.tags = None # No tags
1120-
task.comment = None # No comment
1132+
task.comment = None # No comment
11211133
return task
11221134

11231135
mock_task.get_task.side_effect = mock_get_task
@@ -1148,4 +1160,3 @@ def test_main_module_execution(self):
11481160
"""Test that __name__ == '__main__' calls main()."""
11491161
# This is covered by importing and running the module
11501162
# The actual line is tested when the module is executed
1151-
pass

0 commit comments

Comments
 (0)