File size: 2,400 Bytes
fcca8c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Base test class for CLI commands."""

from pathlib import Path
from unittest.mock import patch

from axolotl.cli.main import cli


class BaseCliTest:
    """Base class for CLI command tests."""

    def _test_cli_validation(self, cli_runner, command: str):
        """Test CLI validation for a command.

        Args:
            cli_runner: CLI runner fixture
            command: Command to test (train/evaluate)
        """
        # Test missing config file
        result = cli_runner.invoke(cli, [command, "--no-accelerate"])
        assert result.exit_code != 0

        # Test non-existent config file
        result = cli_runner.invoke(cli, [command, "nonexistent.yml", "--no-accelerate"])
        assert result.exit_code != 0
        assert "Error: Invalid value for 'CONFIG'" in result.output

    def _test_basic_execution(
        self, cli_runner, tmp_path: Path, valid_test_config: str, command: str
    ):
        """Test basic execution with accelerate.

        Args:
            cli_runner: CLI runner fixture
            tmp_path: Temporary path fixture
            valid_test_config: Valid config fixture
            command: Command to test (train/evaluate)
        """
        config_path = tmp_path / "config.yml"
        config_path.write_text(valid_test_config)

        with patch("subprocess.run") as mock:
            result = cli_runner.invoke(cli, [command, str(config_path)])

            assert mock.called
            assert mock.call_args.args[0] == [
                "accelerate",
                "launch",
                "-m",
                f"axolotl.cli.{command}",
                str(config_path),
                "--debug-num-examples",
                "0",
            ]
            assert mock.call_args.kwargs == {"check": True}
            assert result.exit_code == 0

    def _test_cli_overrides(self, tmp_path: Path, valid_test_config: str):
        """Test CLI argument overrides.

        Args:
            tmp_path: Temporary path fixture
            valid_test_config: Valid config fixture
            command: Command to test (train/evaluate)
        """
        config_path = tmp_path / "config.yml"
        output_dir = tmp_path / "model-out"

        test_config = valid_test_config.replace(
            "output_dir: model-out", f"output_dir: {output_dir}"
        )
        config_path.write_text(test_config)
        return config_path