Skip to content

Commit 6a9f2e9

Browse files
committed
bps unit tests and precommit fixes
1 parent 844c284 commit 6a9f2e9

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

.github/workflows/precommit.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
pre-commit:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
11+
- uses: actions/checkout@v5
12+
- uses: actions/setup-python@v6
1313
with:
1414
python-version: "3.10"
1515
- name: Set up uv
16-
uses: astral-sh/setup-uv@v5
16+
uses: astral-sh/setup-uv@v7
1717
- name: Install dependencies
1818
run: |
1919
uv sync --all-groups

br.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def log_job_output(job_name: str, *, wait: bool, timeout: int | None) -> None:
261261
phase = get_pod_status(pod_name)
262262
if phase in ("Succeeded", "Failed"):
263263
print(f"Pod, {pod_name} finished with phase={phase}")
264-
end = time.monotonic()
264+
# end = time.monotonic()
265265
# for logging information
266-
elapsed = end - start
266+
# elapsed = end - start
267267
break
268268
if timeout and (time.monotonic() - start) > timeout:
269269
print(f"Timeout waiting for pod {pod_name} to complete")

tests/test_bps.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@
77
from bps import ListPodsCommand, summarize_gpu_pods
88

99

10-
def create_pod(name: str, namespace: str, node: str, phase: str, gpu_count: int) -> mock.Mock:
10+
def create_pod(
11+
name: str, namespace: str, node: str, phase: str, gpu_count: int
12+
) -> mock.Mock:
1113
"""Helper to create a properly structured mock pod object."""
1214
pod = mock.Mock()
13-
15+
1416
pod.model = mock.Mock()
1517
pod.model.metadata = mock.Mock()
1618
pod.model.metadata.name = name
1719
pod.model.metadata.namespace = namespace
18-
20+
1921
pod.model.status = mock.Mock()
2022
pod.model.status.phase = phase
21-
23+
2224
pod.model.spec = mock.Mock()
2325
pod.model.spec.nodeName = node
24-
26+
2527
container = mock.Mock()
2628
container.resources = mock.Mock()
27-
container.resources.requests = {"nvidia.com/gpu": gpu_count} if gpu_count > 0 else {}
28-
29+
container.resources.requests = (
30+
{"nvidia.com/gpu": gpu_count} if gpu_count > 0 else {}
31+
)
32+
2933
pod.model.spec.containers = [container]
30-
34+
3135
return pod
3236

3337

@@ -135,16 +139,19 @@ def test_multiple_pods_same_node(args: argparse.Namespace, capsys):
135139
assert "default/pod-1" in captured.out
136140
assert "default/pod-2" in captured.out
137141

142+
138143
def test_summarize_gpu_pods_empty():
139144
result = summarize_gpu_pods([], verbose=False)
140145
assert result == []
141146

147+
142148
def test_summarize_gpu_pods_with_gpu():
143149
pods = [create_pod("test-pod", "default", "node-a", "Running", 2)]
144150
result = summarize_gpu_pods(pods, verbose=False)
145151
assert len(result) == 1
146152
assert "node-a: BUSY 2 default/test-pod" in result[0]
147153

154+
148155
def test_summarize_gpu_pods_multiple_containers():
149156
# base pod with one GPU container
150157
pod = create_pod("multi-gpu-pod", "default", "node-a", "Running", 1)
@@ -166,7 +173,8 @@ def test_list_pods_openshift_exception(args: argparse.Namespace, capsys):
166173
with mock.patch("openshift_client.selector") as mock_selector:
167174
with mock.patch("openshift_client.timeout"):
168175
import openshift_client as oc
176+
169177
mock_selector.side_effect = oc.OpenShiftPythonException("Connection failed")
170-
178+
171179
with pytest.raises(SystemExit):
172-
ListPodsCommand.run(args)
180+
ListPodsCommand.run(args)

0 commit comments

Comments
 (0)