Skip to content

Commit 28401a2

Browse files
committed
tests added for find_matching_dirs.
1 parent 7106024 commit 28401a2

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

tests/vec_inf/client/test_utils.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from vec_inf.client._utils import (
1010
MODEL_READY_SIGNATURE,
11+
find_matching_dirs,
1112
get_base_url,
1213
is_server_running,
1314
load_config,
@@ -208,3 +209,135 @@ def test_load_config_invalid_user_model(tmp_path):
208209
assert "validation error" in str(excinfo.value).lower()
209210
assert "model_type" in str(excinfo.value)
210211
assert "num_gpus" in str(excinfo.value)
212+
213+
214+
def test_find_matching_dirs_only_model_family(tmp_path):
215+
"""Return model_family directory when only model_family is provided."""
216+
fam_dir = tmp_path / "famA"
217+
fam_dir.mkdir()
218+
(fam_dir / "modelA.1").mkdir()
219+
(fam_dir / "modelB.2").mkdir()
220+
221+
other_dir = tmp_path / "famB"
222+
other_dir.mkdir()
223+
(other_dir / "modelC.3").mkdir()
224+
225+
matches = find_matching_dirs(log_dir=tmp_path, model_family="famA")
226+
assert len(matches) == 1
227+
assert matches[0].name == "famA"
228+
229+
230+
def test_find_matching_dirs_only_model_name(tmp_path):
231+
"""Return directories matching when only model_name is provided."""
232+
fam_a = tmp_path / "famA"
233+
fam_a.mkdir()
234+
(fam_a / "target.1").mkdir()
235+
(fam_a / "other.2").mkdir()
236+
237+
fam_b = tmp_path / "famB"
238+
fam_b.mkdir()
239+
(fam_b / "different.3").mkdir()
240+
241+
matches = find_matching_dirs(log_dir=tmp_path, model_name="target")
242+
result_names = [p.name for p in matches]
243+
244+
assert "target.1" in result_names
245+
assert "other.2" not in result_names
246+
assert "different.3" not in result_names
247+
248+
249+
def test_find_matching_dirs_only_job_id(tmp_path):
250+
"""Return directories matching exact job_id."""
251+
fam_dir = tmp_path / "fam"
252+
fam_dir.mkdir()
253+
(fam_dir / "modelA.10").mkdir()
254+
(fam_dir / "modelB.20").mkdir()
255+
(fam_dir / "modelC.30").mkdir()
256+
257+
matches = find_matching_dirs(log_dir=tmp_path, job_id=10)
258+
result_names = [p.name for p in matches]
259+
260+
assert "modelA.10" in result_names
261+
assert "modelB.20" not in result_names
262+
assert "modelC.30" not in result_names
263+
264+
265+
def test_find_matching_dirs_only_before_job_id(tmp_path):
266+
"""Return directories with job_id < before_job_id."""
267+
fam_dir = tmp_path / "famA"
268+
fam_dir.mkdir()
269+
(fam_dir / "modelA.1").mkdir()
270+
(fam_dir / "modelA.5").mkdir()
271+
(fam_dir / "modelA.100").mkdir()
272+
273+
fam_dir = tmp_path / "famB"
274+
fam_dir.mkdir()
275+
(fam_dir / "modelB.30").mkdir()
276+
277+
matches = find_matching_dirs(log_dir=tmp_path, before_job_id=50)
278+
result_names = [p.name for p in matches]
279+
280+
assert "modelA.1" in result_names
281+
assert "modelA.5" in result_names
282+
assert "modelA.100" not in result_names
283+
assert "modelB.30" in result_names
284+
285+
286+
def test_find_matching_dirs_family_and_before_job_id(tmp_path):
287+
"""Return directories under a given family with job IDs less than before_job_id."""
288+
fam_dir = tmp_path / "targetfam"
289+
fam_dir.mkdir()
290+
(fam_dir / "modelA.10").mkdir()
291+
(fam_dir / "modelA.20").mkdir()
292+
(fam_dir / "modelA.99").mkdir()
293+
(fam_dir / "modelA.150").mkdir()
294+
295+
other_fam = tmp_path / "otherfam"
296+
other_fam.mkdir()
297+
(other_fam / "modelB.5").mkdir()
298+
(other_fam / "modelB.10").mkdir()
299+
(other_fam / "modelB.100").mkdir()
300+
301+
matches = find_matching_dirs(
302+
log_dir=tmp_path,
303+
model_family="targetfam",
304+
before_job_id=100,
305+
)
306+
307+
result_names = [p.name for p in matches]
308+
309+
assert "modelA.10" in result_names
310+
assert "modelA.20" in result_names
311+
assert "modelA.99" in result_names
312+
assert "modelA.150" not in result_names
313+
assert all("otherfam" not in str(p) for p in matches)
314+
315+
316+
def test_find_matching_dirs_with_family_model_name_and_before_job_id(tmp_path):
317+
"""Return matching dirs with model_family, model_name, and before_job_id filters."""
318+
fam_dir = tmp_path / "targetfam"
319+
fam_dir.mkdir()
320+
(fam_dir / "modelA.1").mkdir()
321+
(fam_dir / "modelA.50").mkdir()
322+
(fam_dir / "modelA.150").mkdir()
323+
(fam_dir / "modelB.40").mkdir()
324+
325+
other_fam = tmp_path / "otherfam"
326+
other_fam.mkdir()
327+
(other_fam / "modelC.20").mkdir()
328+
329+
matches = find_matching_dirs(
330+
log_dir=tmp_path,
331+
model_family="targetfam",
332+
model_name="modelA",
333+
before_job_id=100,
334+
)
335+
336+
result_names = [p.name for p in matches]
337+
338+
assert "modelA.1" in result_names
339+
assert "modelA.50" in result_names
340+
assert "modelA.150" not in result_names
341+
assert "modelB.40" not in result_names
342+
assert all("modelB" not in p for p in result_names)
343+
assert all("otherfam" not in str(p) for p in matches)

0 commit comments

Comments
 (0)