|
1 | | -import subprocess |
2 | | -import sys |
| 1 | +from unittest.mock import patch, MagicMock |
| 2 | +from fastvideo.training.runner import main |
| 3 | +import argparse |
3 | 4 |
|
4 | | -def test_runner_help(): |
5 | | - # Run the runner with --help to ensure it parses arguments correctly |
6 | | - # and doesn't have any syntax errors or missing imports. |
7 | | - result = subprocess.run( |
8 | | - [sys.executable, "-m", "fastvideo.training.runner", "--help"], |
9 | | - capture_output=True, |
10 | | - text=True |
11 | | - ) |
12 | | - |
13 | | - # Check if the process completed successfully |
14 | | - assert result.returncode == 0, f"Runner failed with exit code {result.returncode}.\nStderr: {result.stderr}" |
15 | | - |
16 | | - # Check if help output is printed |
17 | | - assert "--pipeline_class" in result.stdout |
18 | | - assert "--pipeline_module" in result.stdout |
| 5 | +def test_runner_invokes_correct_class(): |
| 6 | + with patch('fastvideo.training.runner.importlib.import_module') as mock_import_module: |
| 7 | + mock_module = MagicMock() |
| 8 | + mock_import_module.return_value = mock_module |
| 9 | + |
| 10 | + mock_pipeline_class = MagicMock() |
| 11 | + setattr(mock_module, "WanTrainingPipeline", mock_pipeline_class) |
| 12 | + |
| 13 | + mock_pipeline_instance = MagicMock() |
| 14 | + mock_pipeline_class.from_pretrained.return_value = mock_pipeline_instance |
| 15 | + |
| 16 | + args = argparse.Namespace( |
| 17 | + pipeline_module="fastvideo.training.wan_training_pipeline", |
| 18 | + pipeline_class="WanTrainingPipeline", |
| 19 | + pretrained_model_name_or_path="test_model" |
| 20 | + ) |
| 21 | + |
| 22 | + main(args) |
| 23 | + |
| 24 | + mock_import_module.assert_called_once_with("fastvideo.training.wan_training_pipeline") |
| 25 | + mock_pipeline_class.from_pretrained.assert_called_once_with("test_model", args=args) |
| 26 | + mock_pipeline_instance.train.assert_called_once() |
0 commit comments