File size: 1,061 Bytes
5f02c05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import importlib.util
from pathlib import Path

spec = importlib.util.spec_from_file_location("kaggle_train", Path("scripts/kaggle_train.py"))
kt = importlib.util.module_from_spec(spec)
spec.loader.exec_module(kt)


def test_find_dir_with_marker_any_mount_layout(tmp_path):
    for layout in ("hades-corpus-v1", "datasets/selbymashiki/hades-corpus-v1"):
        root = tmp_path / layout.replace("/", "_")
        target = root / layout / "processed"
        target.mkdir(parents=True)
        (target / "manifest.json").write_text("{}")
        assert kt.find_dir_with(root, "manifest.json") == target


def test_find_dir_with_missing_returns_none(tmp_path):
    assert kt.find_dir_with(tmp_path, "manifest.json") is None


def test_latest_checkpoints_are_collected(tmp_path):
    (tmp_path / "a").mkdir()
    for name in ("step_0000100.pt", "step_0000200.pt", "best.pt", "step_0000300.tmp"):
        (tmp_path / "a" / name).write_bytes(b"x")
    assert sorted(p.name for p in kt.checkpoint_files(tmp_path)) == ["best.pt", "step_0000100.pt", "step_0000200.pt"]