Skip to content

Commit 87bd3e4

Browse files
committed
fix test linter
1 parent e728967 commit 87bd3e4

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

torchx/schedulers/test/slurm_scheduler_test.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
# pyre-strict
88

99
import datetime
10-
from importlib import resources
1110
import json
1211
import os
1312
import subprocess
1413
import tempfile
1514
import unittest
1615
from contextlib import contextmanager
16+
from importlib import resources
1717
from typing import Generator
1818
from unittest.mock import call, MagicMock, patch
1919

@@ -1052,54 +1052,55 @@ def test_no_gpu_resources(self) -> None:
10521052

10531053
def test_describe_squeue_handles_none_job_resources(self):
10541054
"""Test that describe handles job_resources=None without crashing (i.e. for SLURM 24.11.5)."""
1055-
1055+
10561056
# Mock SLURM 24.11.5 response with job_resources=None
10571057
mock_job_data = {
1058-
"jobs": [{
1059-
"name": "test-job-0",
1060-
"job_state": ["PENDING"],
1061-
"job_resources": None, # This was causing the crash
1062-
"nodes": "",
1063-
"scheduled_nodes": "",
1064-
"command": "/bin/echo",
1065-
"current_working_directory": "/tmp"
1066-
}]
1058+
"jobs": [
1059+
{
1060+
"name": "test-job-0",
1061+
"job_state": ["PENDING"],
1062+
"job_resources": None, # This was causing the crash
1063+
"nodes": "",
1064+
"scheduled_nodes": "",
1065+
"command": "/bin/echo",
1066+
"current_working_directory": "/tmp",
1067+
}
1068+
]
10671069
}
1068-
1069-
with patch('subprocess.check_output') as mock_subprocess:
1070+
1071+
with patch("subprocess.check_output") as mock_subprocess:
10701072
mock_subprocess.return_value = json.dumps(mock_job_data)
1071-
1073+
10721074
scheduler = SlurmScheduler("test")
10731075
result = scheduler._describe_squeue("123")
1074-
1076+
10751077
# Should not crash and should return a valid response
10761078
assert result is not None
10771079
assert result.app_id == "123"
10781080
assert result.state == AppState.PENDING
10791081

1080-
10811082
def test_describe_sacct_handles_dot_separated_job_ids(self):
10821083
"""Test that _describe_sacct handles job IDs with '.' separators (not just '+')."""
10831084
sacct_output = """JobID|JobName|Partition|Account|AllocCPUS|State|ExitCode
10841085
89|mesh0-0|all|root|8|CANCELLED by 2166|0:0
10851086
89.batch|batch||root|8|CANCELLED|0:15
10861087
89.0|process_allocator||root|8|CANCELLED|0:15
10871088
"""
1088-
1089-
with patch('subprocess.check_output') as mock_subprocess:
1089+
1090+
with patch("subprocess.check_output") as mock_subprocess:
10901091
mock_subprocess.return_value = sacct_output
1091-
1092+
10921093
scheduler = SlurmScheduler("test")
10931094
result = scheduler._describe_sacct("89")
10941095
print("result: ", result)
1095-
1096+
10961097
# Should process only the main job "89", not the sub-jobs
10971098
assert result is not None
10981099
assert result.app_id == "89"
10991100
assert result.state == AppState.CANCELLED
11001101
assert result.msg == "CANCELLED by 2166"
1101-
1102+
11021103
# Should have one role "mesh0" with one replica "0"
11031104
assert len(result.roles) == 1
11041105
assert result.roles[0].name == "mesh0"
1105-
assert result.roles[0].num_replicas == 1
1106+
assert result.roles[0].num_replicas == 1

0 commit comments

Comments
 (0)