File size: 1,192 Bytes
e530698
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Tests for checkpoint discovery helper in the CLI."""

from pathlib import Path

from skydiscover.cli import _find_latest_checkpoint


def test_returns_highest_iteration(tmp_path: Path):
    checkpoint_dir = tmp_path / "checkpoints"
    checkpoint_dir.mkdir()

    (checkpoint_dir / "checkpoint_2").mkdir()
    (checkpoint_dir / "checkpoint_10").mkdir()
    (checkpoint_dir / "checkpoint_1").mkdir()

    latest = _find_latest_checkpoint(str(checkpoint_dir))
    assert latest == str(checkpoint_dir / "checkpoint_10")


def test_ignores_non_numeric_dirs(tmp_path: Path):
    checkpoint_dir = tmp_path / "checkpoints"
    checkpoint_dir.mkdir()

    (checkpoint_dir / "latest").mkdir()
    (checkpoint_dir / "checkpoint_old").mkdir()
    (checkpoint_dir / "checkpoint_3").mkdir()

    latest = _find_latest_checkpoint(str(checkpoint_dir))
    assert latest == str(checkpoint_dir / "checkpoint_3")


def test_returns_none_without_valid_checkpoints(tmp_path: Path):
    checkpoint_dir = tmp_path / "checkpoints"
    checkpoint_dir.mkdir()

    (checkpoint_dir / "latest").mkdir()
    (checkpoint_dir / "checkpoint_old").mkdir()

    assert _find_latest_checkpoint(str(checkpoint_dir)) is None