Skip to content

Commit 379552f

Browse files
committed
lint
1 parent 9682db2 commit 379552f

1 file changed

Lines changed: 41 additions & 25 deletions

File tree

tests/test_modal.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
import subprocess
3-
import pytest
43
from pathlib import Path
54

5+
import pytest
6+
7+
from libkernelbot.consts import GPU_TO_SM, ModalGPU, SubmissionMode
68
from libkernelbot.launchers import ModalLauncher
7-
from libkernelbot.consts import SubmissionMode, GPU_TO_SM, ModalGPU
8-
from libkernelbot.task import make_task_definition, build_task_config
99
from libkernelbot.report import RunProgressReporter
10+
from libkernelbot.task import build_task_config, make_task_definition
1011

1112

1213
class MockProgressReporter(RunProgressReporter):
@@ -42,7 +43,7 @@ def modal_deployment(project_root: Path):
4243
cwd=project_root / "src" / "runners",
4344
capture_output=True,
4445
text=True,
45-
timeout=600 # 10 minute timeout in case image needs to be built (can be very slow)
46+
timeout=600, # 10 minute timeout in case image needs to be built (can be very slow)
4647
)
4748

4849
if result.returncode != 0:
@@ -53,23 +54,32 @@ def modal_deployment(project_root: Path):
5354
cwd=project_root / "src" / "runners",
5455
capture_output=True,
5556
text=True,
56-
timeout=30
57+
timeout=30,
5758
)
5859
if result.returncode != 0:
59-
pytest.fail(f"Modal environment `{modal_env}` not available, and failed to create: {result.stderr}")
60+
pytest.fail(
61+
f"Modal environment `{modal_env}` not available, "
62+
f"and failed to create: {result.stderr}"
63+
)
6064
else:
6165
# try again, now that the env exists.
6266
result = subprocess.run(
6367
["modal", "deploy", "--env", modal_env, "modal_runner_archs.py"],
6468
cwd=project_root / "src" / "runners",
6569
capture_output=True,
6670
text=True,
67-
timeout=600
71+
timeout=600,
6872
)
6973
if result.returncode != 0:
70-
pytest.fail(f"Modal deploy failed:\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}")
74+
pytest.fail(
75+
f"Modal deploy failed:\n"
76+
f"STDOUT:\n{result.stdout}\n"
77+
f"STDERR:\n{result.stderr}"
78+
)
7179
else:
72-
pytest.fail(f"Modal deploy failed:\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}")
80+
pytest.fail(
81+
f"Modal deploy failed:\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"
82+
)
7383

7484
print(f"✅ Modal deployment to '{modal_env}' completed successfully")
7585
print(f"Deploy output: {result.stdout}")
@@ -87,15 +97,21 @@ def modal_deployment(project_root: Path):
8797
del os.environ["MODAL_ENVIRONMENT"]
8898

8999
except subprocess.TimeoutExpired as e:
90-
pytest.fail(f"Modal deploy timed out after 5 minutes:\nstdout: {e.stdout}, stderr:{e.stderr}")
100+
pytest.fail(
101+
f"Modal deploy timed out after 5 minutes:\nstdout: {e.stdout}, stderr:{e.stderr}"
102+
)
91103
except Exception as e:
92104
pytest.fail(f"Modal deploy failed with exception: {e}")
93105

94106

95107
@pytest.mark.integration
96108
@pytest.mark.asyncio
97-
@pytest.mark.parametrize("gpu_type", [ModalGPU.T4, ModalGPU.L4, ModalGPU.A100, ModalGPU.H100, ModalGPU.B200])
98-
async def test_modal_launcher_python_script(modal_deployment, project_root: Path, gpu_type: ModalGPU):
109+
@pytest.mark.parametrize(
110+
"gpu_type", [ModalGPU.T4, ModalGPU.L4, ModalGPU.A100, ModalGPU.H100, ModalGPU.B200]
111+
)
112+
async def test_modal_launcher_python_script(
113+
modal_deployment, project_root: Path, gpu_type: ModalGPU
114+
):
99115
"""
100116
Test ModalLauncher with a real Python script using examples/identity_py.
101117
"""
@@ -117,7 +133,7 @@ async def test_modal_launcher_python_script(modal_deployment, project_root: Path
117133
task=task_definition.task,
118134
submission_content=submission_content,
119135
arch=GPU_TO_SM[gpu_type.name],
120-
mode=SubmissionMode.TEST
136+
mode=SubmissionMode.TEST,
121137
)
122138

123139
result = await launcher.run_submission(config, gpu_type, reporter)
@@ -133,8 +149,8 @@ async def test_modal_launcher_python_script(modal_deployment, project_root: Path
133149
assert result.system.torch.startswith("2.7") # update when the image changes
134150

135151
# Test run structure
136-
assert 'test' in result.runs
137-
test_run = result.runs['test']
152+
assert "test" in result.runs
153+
test_run = result.runs["test"]
138154

139155
# For Python runs, compilation is None
140156
assert test_run.compilation is None
@@ -148,29 +164,29 @@ async def test_modal_launcher_python_script(modal_deployment, project_root: Path
148164
assert test_run.run.duration > 0
149165

150166
# Test need to succeed
151-
assert test_run.run.result['check'] == 'pass'
152-
test_count = int(test_run.run.result['test-count'])
167+
assert test_run.run.result["check"] == "pass"
168+
test_count = int(test_run.run.result["test-count"])
153169
assert test_count == 5
154170
for i in range(test_count):
155-
assert test_run.run.result[f'test.{i}.status'] == 'pass'
156-
assert 'size:' in test_run.run.result[f'test.{i}.spec']
157-
assert 'seed:' in test_run.run.result[f'test.{i}.spec']
171+
assert test_run.run.result[f"test.{i}.status"] == "pass"
172+
assert "size:" in test_run.run.result[f"test.{i}.spec"]
173+
assert "seed:" in test_run.run.result[f"test.{i}.spec"]
158174

159175
# sanity check for timings
160176
assert test_run.start < test_run.end
161177

162178
# check messages
163-
assert reporter.messages == ['⏳ Waiting for Modal run to finish...']
164-
assert reporter.updates == ['✅ Waiting for modal run to finish... Done']
179+
assert reporter.messages == ["⏳ Waiting for Modal run to finish..."]
180+
assert reporter.updates == ["✅ Waiting for modal run to finish... Done"]
165181

166182

167183
@pytest.mark.integration
168184
@pytest.mark.asyncio
169185
@pytest.mark.parametrize("script", ["cheat-fd.py", "cheat-input.py", "cheat-rng.py"])
170186
async def test_modal_launcher_failing_script(modal_deployment, project_root: Path, script: str):
171187
"""
172-
Test ModalLauncher with a real Python scripts that are designed to be wrong.
173-
"""
188+
Test ModalLauncher with a real Python scripts that are designed to be wrong.
189+
"""
174190
launcher = ModalLauncher(add_include_dirs=[])
175191
reporter = MockProgressReporter("progress")
176192
gpu_type = ModalGPU.T4
@@ -198,4 +214,4 @@ async def test_modal_launcher_failing_script(modal_deployment, project_root: Pat
198214
# Basic structure and success
199215
assert result.success, f"Expected successful run, got: {result.error}"
200216
assert result.error == ""
201-
assert result.runs['test'].run.passed is False or result.runs['benchmark'].run.passed is False
217+
assert result.runs["test"].run.passed is False or result.runs["benchmark"].run.passed is False

0 commit comments

Comments
 (0)