-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tree_view_cli.py
More file actions
82 lines (73 loc) · 2.89 KB
/
test_tree_view_cli.py
File metadata and controls
82 lines (73 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pytest
import tempfile
import os
from pathlib import Path
from tree_view_cli import DirectoryTreeGenerator
@pytest.fixture
def temp_directory():
with tempfile.TemporaryDirectory() as tmpdirname:
yield Path(tmpdirname)
def create_file_structure(root):
(root / "dir1" / "subdir1").mkdir(parents=True)
(root / "dir1" / "subdir2").mkdir(parents=True)
(root / "dir1" / "file1.txt").touch()
(root / "dir1" / "subdir1" / "file2.txt").touch()
(root / "dir1" / "subdir2" / "file3.txt").touch()
def test_basic_structure(temp_directory, capsys):
create_file_structure(temp_directory)
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "dir1" in captured.out
assert "subdir1" in captured.out
assert "subdir2" in captured.out
assert "file1.txt" in captured.out
assert "file2.txt" in captured.out
assert "file3.txt" in captured.out
def test_max_depth(temp_directory, capsys):
create_file_structure(temp_directory)
tree_gen = DirectoryTreeGenerator(temp_directory, max_depth=1)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "dir1" in captured.out
assert "subdir1" not in captured.out
assert "file2.txt" not in captured.out
def test_gitignore_file(temp_directory, capsys):
create_file_structure(temp_directory)
with open(temp_directory / ".gitignore", "w") as f:
f.write("**/file1.txt\n")
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "file1.txt" not in captured.out
assert "file2.txt" in captured.out
def test_gitignore_directory(temp_directory, capsys):
create_file_structure(temp_directory)
with open(temp_directory / ".gitignore", "w") as f:
f.write("dir1/\n")
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "dir1" not in captured.out
def test_gitignore_subdirectory(temp_directory, capsys):
create_file_structure(temp_directory)
with open(temp_directory / ".gitignore", "w") as f:
f.write("**/subdir1\n")
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "subdir1" not in captured.out
assert "subdir2" in captured.out
def test_empty_directory(temp_directory, capsys):
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert captured.out.strip() == temp_directory.name + "/"
def test_git_directory_excluded(temp_directory, capsys):
create_file_structure(temp_directory)
(temp_directory / ".git").mkdir()
tree_gen = DirectoryTreeGenerator(temp_directory)
tree_gen.generate_tree()
captured = capsys.readouterr()
assert "dir1" in captured.out
assert ".git" not in captured.out