/ dev / clint / tests / test_index.py
test_index.py
 1  from pathlib import Path
 2  from unittest.mock import patch
 3  
 4  from clint.index import SymbolIndex
 5  
 6  
 7  def test_symbol_index_build_basic(tmp_path: Path) -> None:
 8      mlflow_dir = tmp_path / "mlflow"
 9      mlflow_dir.mkdir()
10  
11      test_file = mlflow_dir / "test.py"
12      test_file.write_text("def test_function(): pass")
13  
14      mock_git_output = "mlflow/test.py\n"
15  
16      with (
17          patch("clint.index.get_repo_root", return_value=tmp_path) as mock_repo_root,
18          patch("subprocess.check_output", return_value=mock_git_output) as mock_check_output,
19      ):
20          index = SymbolIndex.build()
21          assert isinstance(index, SymbolIndex)
22          mock_repo_root.assert_called_once()
23          mock_check_output.assert_called_once()
24  
25  
26  def test_symbol_index_build_skips_missing_files(tmp_path: Path) -> None:
27      mlflow_dir = tmp_path / "mlflow"
28      mlflow_dir.mkdir()
29  
30      existing_file = mlflow_dir / "existing.py"
31      existing_file.write_text("def existing_function(): pass")
32  
33      mock_git_output = "mlflow/existing.py\nmlflow/deleted.py\n"
34  
35      with (
36          patch("clint.index.get_repo_root", return_value=tmp_path) as mock_repo_root,
37          patch("subprocess.check_output", return_value=mock_git_output) as mock_check_output,
38      ):
39          index = SymbolIndex.build()
40          assert isinstance(index, SymbolIndex)
41          mock_repo_root.assert_called_once()
42          mock_check_output.assert_called_once()