77from 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+
138143def test_summarize_gpu_pods_empty ():
139144 result = summarize_gpu_pods ([], verbose = False )
140145 assert result == []
141146
147+
142148def 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+
148155def 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