|
44 | 44 | from black import re_compile_maybe_verbose as compile_pattern |
45 | 45 | from black.cache import FileData, get_cache_dir, get_cache_file |
46 | 46 | from black.debug import DebugVisitor |
| 47 | +from black.mode import Mode, Preview |
47 | 48 | from black.output import color_diff, diff |
48 | 49 | from black.report import Report |
49 | 50 |
|
@@ -2065,6 +2066,30 @@ def test_get_cache_dir( |
2065 | 2066 | monkeypatch.setenv("BLACK_CACHE_DIR", str(workspace2)) |
2066 | 2067 | assert get_cache_dir().parent == workspace2 |
2067 | 2068 |
|
| 2069 | + def test_cache_file_length(self) -> None: |
| 2070 | + cases = [ |
| 2071 | + DEFAULT_MODE, |
| 2072 | + # all of the target versions |
| 2073 | + Mode(target_versions=set(TargetVersion)), |
| 2074 | + # all of the features |
| 2075 | + Mode(enabled_features=set(Preview)), |
| 2076 | + # all of the magics |
| 2077 | + Mode(python_cell_magics={f"magic{i}" for i in range(500)}), |
| 2078 | + # all of the things |
| 2079 | + Mode( |
| 2080 | + target_versions=set(TargetVersion), |
| 2081 | + enabled_features=set(Preview), |
| 2082 | + python_cell_magics={f"magic{i}" for i in range(500)}, |
| 2083 | + ), |
| 2084 | + ] |
| 2085 | + for case in cases: |
| 2086 | + cache_file = get_cache_file(case) |
| 2087 | + # Some common file systems enforce a maximum path length |
| 2088 | + # of 143 (issue #4174). We can't do anything if the directory |
| 2089 | + # path is too long, but ensure the name of the cache file itself |
| 2090 | + # doesn't get too crazy. |
| 2091 | + assert len(cache_file.name) <= 96 |
| 2092 | + |
2068 | 2093 | def test_cache_broken_file(self) -> None: |
2069 | 2094 | mode = DEFAULT_MODE |
2070 | 2095 | with cache_dir() as workspace: |
|
0 commit comments