|
62 | 62 | NoChangesPlanError, |
63 | 63 | ) |
64 | 64 | from sqlmesh.utils.metaprogramming import Executable |
| 65 | +from sqlmesh.utils.windows import IS_WINDOWS, fix_windows_path |
65 | 66 | from tests.utils.test_helpers import use_terminal_console |
66 | 67 | from tests.utils.test_filesystem import create_temp_file |
67 | 68 |
|
@@ -700,6 +701,45 @@ def test_clear_caches(tmp_path: pathlib.Path): |
700 | 701 | assert not cache_dir.exists() |
701 | 702 |
|
702 | 703 |
|
| 704 | +def test_clear_caches_with_long_base_path(tmp_path: pathlib.Path): |
| 705 | + base_path = tmp_path / ("abcde" * 50) |
| 706 | + assert ( |
| 707 | + len(str(base_path.absolute())) > 260 |
| 708 | + ) # Paths longer than 260 chars trigger problems on Windows |
| 709 | + |
| 710 | + default_cache_dir = base_path / c.CACHE |
| 711 | + custom_cache_dir = base_path / ".test_cache" |
| 712 | + |
| 713 | + # note: we create the Context here so it doesnt get passed any "fixed" paths |
| 714 | + ctx = Context(config=Config(cache_dir=str(custom_cache_dir)), paths=base_path) |
| 715 | + |
| 716 | + if IS_WINDOWS: |
| 717 | + # fix these so we can use them in this test |
| 718 | + default_cache_dir = fix_windows_path(default_cache_dir) |
| 719 | + custom_cache_dir = fix_windows_path(custom_cache_dir) |
| 720 | + |
| 721 | + default_cache_dir.mkdir(parents=True) |
| 722 | + custom_cache_dir.mkdir(parents=True) |
| 723 | + |
| 724 | + default_cache_file = default_cache_dir / "cache.txt" |
| 725 | + custom_cache_file = custom_cache_dir / "cache.txt" |
| 726 | + |
| 727 | + default_cache_file.write_text("test") |
| 728 | + custom_cache_file.write_text("test") |
| 729 | + |
| 730 | + assert default_cache_file.exists() |
| 731 | + assert custom_cache_file.exists() |
| 732 | + assert default_cache_dir.exists() |
| 733 | + assert custom_cache_dir.exists() |
| 734 | + |
| 735 | + ctx.clear_caches() |
| 736 | + |
| 737 | + assert not default_cache_file.exists() |
| 738 | + assert not custom_cache_file.exists() |
| 739 | + assert not default_cache_dir.exists() |
| 740 | + assert not custom_cache_dir.exists() |
| 741 | + |
| 742 | + |
703 | 743 | def test_cache_path_configurations(tmp_path: pathlib.Path): |
704 | 744 | project_dir = tmp_path / "project" |
705 | 745 | project_dir.mkdir(parents=True) |
|
0 commit comments