|
8 | 8 |
|
9 | 9 | from vec_inf.client._utils import ( |
10 | 10 | MODEL_READY_SIGNATURE, |
| 11 | + find_matching_dirs, |
11 | 12 | get_base_url, |
12 | 13 | is_server_running, |
13 | 14 | load_config, |
@@ -208,3 +209,135 @@ def test_load_config_invalid_user_model(tmp_path): |
208 | 209 | assert "validation error" in str(excinfo.value).lower() |
209 | 210 | assert "model_type" in str(excinfo.value) |
210 | 211 | 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 / "fam_a" |
| 217 | + fam_dir.mkdir() |
| 218 | + (fam_dir / "model_a.1").mkdir() |
| 219 | + (fam_dir / "model_b.2").mkdir() |
| 220 | + |
| 221 | + other_dir = tmp_path / "fam_b" |
| 222 | + other_dir.mkdir() |
| 223 | + (other_dir / "model_c.3").mkdir() |
| 224 | + |
| 225 | + matches = find_matching_dirs(log_dir=tmp_path, model_family="fam_a") |
| 226 | + assert len(matches) == 1 |
| 227 | + assert matches[0].name == "fam_a" |
| 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 / "fam_a" |
| 233 | + fam_a.mkdir() |
| 234 | + (fam_a / "target.1").mkdir() |
| 235 | + (fam_a / "other.2").mkdir() |
| 236 | + |
| 237 | + fam_b = tmp_path / "fam_b" |
| 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 / "model_a.10").mkdir() |
| 254 | + (fam_dir / "model_b.20").mkdir() |
| 255 | + (fam_dir / "model_c.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 "model_a.10" in result_names |
| 261 | + assert "model_b.20" not in result_names |
| 262 | + assert "model_c.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 / "fam_a" |
| 268 | + fam_dir.mkdir() |
| 269 | + (fam_dir / "model_a.1").mkdir() |
| 270 | + (fam_dir / "model_a.5").mkdir() |
| 271 | + (fam_dir / "model_a.100").mkdir() |
| 272 | + |
| 273 | + fam_dir = tmp_path / "fam_b" |
| 274 | + fam_dir.mkdir() |
| 275 | + (fam_dir / "model_b.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 "model_a.1" in result_names |
| 281 | + assert "model_a.5" in result_names |
| 282 | + assert "model_a.100" not in result_names |
| 283 | + assert "model_b.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 / "model_a.10").mkdir() |
| 291 | + (fam_dir / "model_a.20").mkdir() |
| 292 | + (fam_dir / "model_a.99").mkdir() |
| 293 | + (fam_dir / "model_a.150").mkdir() |
| 294 | + |
| 295 | + other_fam = tmp_path / "otherfam" |
| 296 | + other_fam.mkdir() |
| 297 | + (other_fam / "model_b.5").mkdir() |
| 298 | + (other_fam / "model_b.10").mkdir() |
| 299 | + (other_fam / "model_b.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 "model_a.10" in result_names |
| 310 | + assert "model_a.20" in result_names |
| 311 | + assert "model_a.99" in result_names |
| 312 | + assert "model_a.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 / "model_a.1").mkdir() |
| 321 | + (fam_dir / "model_a.50").mkdir() |
| 322 | + (fam_dir / "model_a.150").mkdir() |
| 323 | + (fam_dir / "model_b.40").mkdir() |
| 324 | + |
| 325 | + other_fam = tmp_path / "otherfam" |
| 326 | + other_fam.mkdir() |
| 327 | + (other_fam / "model_c.20").mkdir() |
| 328 | + |
| 329 | + matches = find_matching_dirs( |
| 330 | + log_dir=tmp_path, |
| 331 | + model_family="targetfam", |
| 332 | + model_name="model_a", |
| 333 | + before_job_id=100, |
| 334 | + ) |
| 335 | + |
| 336 | + result_names = [p.name for p in matches] |
| 337 | + |
| 338 | + assert "model_a.1" in result_names |
| 339 | + assert "model_a.50" in result_names |
| 340 | + assert "model_a.150" not in result_names |
| 341 | + assert "model_b.40" not in result_names |
| 342 | + assert all("model_b" not in p for p in result_names) |
| 343 | + assert all("otherfam" not in str(p) for p in matches) |
0 commit comments