| 1 |
from isort.utils import Trie |
| 2 |
|
| 3 |
|
| 4 |
def test_trie() -> None: |
| 5 |
trie_root = Trie("default", {"line_length": 70}) |
| 6 |
|
| 7 |
trie_root.insert("/temp/config1/.isort.cfg", {"line_length": 71}) |
| 8 |
trie_root.insert("/temp/config2/setup.cfg", {"line_length": 72}) |
| 9 |
trie_root.insert("/temp/config3/pyproject.toml", {"line_length": 73}) |
| 10 |
|
| 11 |
# Ensure that appropriate configs are resolved for files in different directories |
| 12 |
config1 = trie_root.search("/temp/config1/subdir/file1.py") |
| 13 |
assert config1[0] == "/temp/config1/.isort.cfg" |
| 14 |
assert config1[1] == {"line_length": 71} |
| 15 |
|
| 16 |
config1_2 = trie_root.search("/temp/config1/file1_2.py") |
| 17 |
assert config1_2[0] == "/temp/config1/.isort.cfg" |
| 18 |
assert config1_2[1] == {"line_length": 71} |
| 19 |
|
| 20 |
config2 = trie_root.search("/temp/config2/subdir/subsubdir/file2.py") |
| 21 |
assert config2[0] == "/temp/config2/setup.cfg" |
| 22 |
assert config2[1] == {"line_length": 72} |
| 23 |
|
| 24 |
config2_2 = trie_root.search("/temp/config2/subdir/file2_2.py") |
| 25 |
assert config2_2[0] == "/temp/config2/setup.cfg" |
| 26 |
assert config2_2[1] == {"line_length": 72} |
| 27 |
|
| 28 |
config3 = trie_root.search("/temp/config3/subdir/subsubdir/subsubsubdir/file3.py") |
| 29 |
assert config3[0] == "/temp/config3/pyproject.toml" |
| 30 |
assert config3[1] == {"line_length": 73} |
| 31 |
|
| 32 |
config3_2 = trie_root.search("/temp/config3/file3.py") |
| 33 |
assert config3_2[0] == "/temp/config3/pyproject.toml" |
| 34 |
assert config3_2[1] == {"line_length": 73} |
| 35 |
|
| 36 |
config_outside = trie_root.search("/temp/file.py") |
| 37 |
assert config_outside[0] == "default" |
| 38 |
assert config_outside[1] == {"line_length": 70} |