-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_gui_recursive.py
More file actions
82 lines (65 loc) · 2.46 KB
/
test_gui_recursive.py
File metadata and controls
82 lines (65 loc) · 2.46 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
"""
Test script to verify GUI recursive directory scanning works correctly.
"""
from pathlib import Path
import tempfile
from src.nuoyi.utils import find_documents
def test_gui_recursive_logic():
"""Test the logic that will be used in GUI for recursive scanning."""
print("=" * 60)
print("GUI Recursive Scanning Logic Test")
print("=" * 60)
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
# Create test directory structure
projects = tmpdir / "projects"
project_a = projects / "ProjectA"
project_b = projects / "ProjectB"
docs = project_a / "docs"
projects.mkdir(parents=True)
project_a.mkdir()
project_b.mkdir()
docs.mkdir()
# Create sample files
files_created = [
projects / "overview.pdf",
project_a / "spec.pdf",
project_a / "notes.docx",
docs / "manual.pdf",
project_b / "design.pdf",
]
for f in files_created:
f.touch()
print(f"\nCreated {len(files_created)} files in nested directories")
# Test non-recursive
print("\n--- Non-recursive scan (GUI checkbox unchecked) ---")
flat_files = find_documents(projects, recursive=False)
print(f"Files found: {len(flat_files)}")
for f in flat_files:
print(f" - {f.name}")
# Test recursive
print("\n--- Recursive scan (GUI checkbox checked) ---")
recursive_files = find_documents(projects, recursive=True)
print(f"Files found: {len(recursive_files)}")
for f in recursive_files:
rel_path = f.relative_to(projects)
print(f" - {rel_path}")
# Verify results
print("\n--- Verification ---")
assert len(flat_files) == 1, f"Expected 1 file in flat scan, got {len(flat_files)}"
assert len(recursive_files) == 5, (
f"Expected 5 files in recursive scan, got {len(recursive_files)}"
)
# Test path display logic
print("\n--- Path display in GUI table ---")
for f in recursive_files:
try:
rel_path = f.relative_to(projects)
display_name = str(rel_path)
except ValueError:
display_name = f.name
print(f" Table cell: {display_name}")
print("\n✅ All tests passed!")
print("=" * 60)
if __name__ == "__main__":
test_gui_recursive_logic()