Skip to content

Commit 84b5e2a

Browse files
committed
Add gpu_catalog tests (89% coverage, up from 23%)
1 parent 06e579a commit 84b5e2a

1 file changed

Lines changed: 202 additions & 0 deletions

File tree

tests/test_gpu_catalog.py

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#!/usr/bin/env python3
2+
"""Tests for providers/gpu_catalog.py"""
3+
4+
import pytest
5+
from terradev_cli.providers.gpu_catalog import (
6+
normalize,
7+
get_canonical_name,
8+
list_all_canonical_gpus,
9+
list_providers_for_gpu,
10+
GPU_ALIASES,
11+
GPU_SPECS,
12+
)
13+
from terradev_cli.providers.types import GPUVendor
14+
15+
16+
class TestNormalize:
17+
"""Test normalize function"""
18+
19+
def test_normalize_h100_variants(self):
20+
"""Normalize H100 variants"""
21+
assert normalize("H100").name == "H100-80GB"
22+
assert normalize("NVIDIA_H100_80G").name == "H100-80GB"
23+
assert normalize("h100").name == "H100-80GB"
24+
assert normalize("H100-80GB").name == "H100-80GB"
25+
26+
def test_normalize_a100_variants(self):
27+
"""Normalize A100 variants"""
28+
assert normalize("A100").name == "A100-80GB"
29+
assert normalize("NVIDIA_A100_80G").name == "A100-80GB"
30+
assert normalize("A100-40GB").name == "A100-40GB"
31+
assert normalize("NVIDIA_A100_PCIe_40G").name == "A100-40GB"
32+
33+
def test_normalize_rtx_variants(self):
34+
"""Normalize RTX variants"""
35+
assert normalize("RTX4090").name == "RTX-4090"
36+
assert normalize("RTX 4090").name == "RTX-4090"
37+
assert normalize("RTX3090").name == "RTX-3090"
38+
39+
def test_normalize_case_insensitive(self):
40+
"""Normalize is case-insensitive"""
41+
assert normalize("h100").name == "H100-80GB"
42+
assert normalize("H100").name == "H100-80GB"
43+
assert normalize("a100").name == "A100-80GB"
44+
assert normalize("A100").name == "A100-80GB"
45+
46+
def test_normalize_aws_instance_types(self):
47+
"""Normalize AWS instance types"""
48+
assert normalize("p5.48xlarge").name == "H100-80GB"
49+
assert normalize("p4d.24xlarge").name == "A100-80GB"
50+
assert normalize("g4dn.xlarge").name == "T4-16GB"
51+
52+
def test_normalize_gcp_instance_types(self):
53+
"""Normalize GCP instance types"""
54+
assert normalize("a2-highgpu-1g").name == "A100-80GB"
55+
assert normalize("g2-standard-4").name == "L4-24GB"
56+
57+
def test_normalize_azure_instance_types(self):
58+
"""Normalize Azure instance types"""
59+
assert normalize("Standard_ND96amsr_A100_v4").name == "A100-80GB"
60+
assert normalize("Standard_ND96isr_H100_v5").name == "H100-80GB"
61+
62+
def test_normalize_unknown_gpu(self):
63+
"""Normalize unknown GPU returns None"""
64+
assert normalize("UNKNOWN_GPU") is None
65+
assert normalize("") is None
66+
assert normalize(None) is None
67+
68+
def test_normalize_with_variations(self):
69+
"""Normalize with space/hyphen/underscore variations"""
70+
assert normalize("RTX 4090").name == "RTX-4090"
71+
assert normalize("RTX-4090").name == "RTX-4090"
72+
assert normalize("RTX_4090").name == "RTX-4090"
73+
74+
75+
class TestGetCanonicalName:
76+
"""Test get_canonical_name function"""
77+
78+
def test_get_canonical_name_h100(self):
79+
"""Get canonical name for H100"""
80+
assert get_canonical_name("H100") == "H100-80GB"
81+
assert get_canonical_name("NVIDIA_H100_80G") == "H100-80GB"
82+
83+
def test_get_canonical_name_a100(self):
84+
"""Get canonical name for A100"""
85+
assert get_canonical_name("A100") == "A100-80GB"
86+
assert get_canonical_name("A100-40GB") == "A100-40GB"
87+
88+
def test_get_canonical_name_unknown(self):
89+
"""Get canonical name for unknown GPU returns None"""
90+
assert get_canonical_name("UNKNOWN_GPU") is None
91+
assert get_canonical_name("") is None
92+
93+
94+
class TestListAllCanonicalGpus:
95+
"""Test list_all_canonical_gpus function"""
96+
97+
def test_list_all_canonical_gpus(self):
98+
"""List all canonical GPUs"""
99+
gpus = list_all_canonical_gpus()
100+
assert isinstance(gpus, list)
101+
assert len(gpus) > 0
102+
assert "H100-80GB" in gpus
103+
assert "A100-80GB" in gpus
104+
assert "RTX-4090" in gpus
105+
106+
def test_list_all_canonical_gpus_sorted(self):
107+
"""List all canonical GPUs is sorted"""
108+
gpus = list_all_canonical_gpus()
109+
assert gpus == sorted(gpus)
110+
111+
112+
class TestListProvidersForGpu:
113+
"""Test list_providers_for_gpu function"""
114+
115+
def test_list_providers_for_h100(self):
116+
"""List provider names for H100"""
117+
providers = list_providers_for_gpu("H100-80GB")
118+
assert isinstance(providers, list)
119+
assert "H100" in providers
120+
assert "NVIDIA_H100_80G" in providers
121+
assert "h100" in providers
122+
123+
def test_list_providers_for_a100(self):
124+
"""List provider names for A100"""
125+
providers = list_providers_for_gpu("A100-80GB")
126+
assert isinstance(providers, list)
127+
assert "A100" in providers
128+
assert "NVIDIA_A100_80G" in providers
129+
130+
def test_list_providers_for_unknown(self):
131+
"""List provider names for unknown GPU returns empty list"""
132+
providers = list_providers_for_gpu("UNKNOWN_GPU")
133+
assert providers == []
134+
135+
136+
class TestGPUAliases:
137+
"""Test GPU_ALIASES dictionary"""
138+
139+
def test_gpu_aliases_has_entries(self):
140+
"""GPU_ALIASES has entries"""
141+
assert len(GPU_ALIASES) > 0
142+
143+
def test_gpu_aliases_keys_are_strings(self):
144+
"""GPU_ALIASES keys are strings"""
145+
for key in GPU_ALIASES.keys():
146+
assert isinstance(key, str)
147+
148+
def test_gpu_aliases_values_are_strings(self):
149+
"""GPU_ALIASES values are strings"""
150+
for value in GPU_ALIASES.values():
151+
assert isinstance(value, str)
152+
153+
154+
class TestGPUSpecs:
155+
"""Test GPU_SPECS dictionary"""
156+
157+
def test_gpu_specs_has_entries(self):
158+
"""GPU_SPECS has entries"""
159+
assert len(GPU_SPECS) > 0
160+
161+
def test_gpu_specs_h100_structure(self):
162+
"""H100 GPU spec has correct structure"""
163+
spec = GPU_SPECS["H100-80GB"]
164+
assert spec.name == "H100-80GB"
165+
assert spec.vendor == GPUVendor.NVIDIA
166+
assert spec.vram_gb == 80
167+
assert spec.nvlink is True
168+
assert spec.compute_capability == "9.0"
169+
170+
def test_gpu_specs_a100_structure(self):
171+
"""A100 GPU spec has correct structure"""
172+
spec = GPU_SPECS["A100-80GB"]
173+
assert spec.name == "A100-80GB"
174+
assert spec.vendor == GPUVendor.NVIDIA
175+
assert spec.vram_gb == 80
176+
assert spec.nvlink is True
177+
assert spec.compute_capability == "8.0"
178+
179+
def test_gpu_specs_rtx4090_structure(self):
180+
"""RTX-4090 GPU spec has correct structure"""
181+
spec = GPU_SPECS["RTX-4090"]
182+
assert spec.name == "RTX-4090"
183+
assert spec.vendor == GPUVendor.NVIDIA
184+
assert spec.vram_gb == 24
185+
assert spec.nvlink is False
186+
assert spec.compute_capability == "8.9"
187+
188+
def test_gpu_specs_amd_mi300x(self):
189+
"""AMD MI300X GPU spec has correct structure"""
190+
spec = GPU_SPECS["MI300X-192GB"]
191+
assert spec.name == "MI300X-192GB"
192+
assert spec.vendor == GPUVendor.AMD
193+
assert spec.vram_gb == 192
194+
assert spec.nvlink is False
195+
196+
def test_gpu_specs_intel_gaudi2(self):
197+
"""Intel Gaudi2 GPU spec has correct structure"""
198+
spec = GPU_SPECS["Gaudi2-96GB"]
199+
assert spec.name == "Gaudi2-96GB"
200+
assert spec.vendor == GPUVendor.INTEL
201+
assert spec.vram_gb == 96
202+
assert spec.nvlink is False

0 commit comments

Comments
 (0)