-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_final_verification.py
More file actions
161 lines (128 loc) · 5.22 KB
/
test_final_verification.py
File metadata and controls
161 lines (128 loc) · 5.22 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""
Standalone verification test for directory structure preservation.
"""
from pathlib import Path
import tempfile
import os
def get_output_path(input_file, input_dir, output_dir, recursive=False, suffix="_md"):
"""Calculate output path preserving directory structure."""
if not recursive:
return output_dir / f"{input_file.stem}.md"
try:
rel_path = input_file.relative_to(input_dir)
except ValueError:
return output_dir / f"{input_file.stem}.md"
output_parts = []
for part in rel_path.parts[:-1]:
output_parts.append(f"{part}{suffix}")
output_parts.append(f"{input_file.stem}.md")
return output_dir / Path(*output_parts)
def create_output_directories(files, input_dir, output_dir, recursive=False, suffix="_md"):
"""Create output directories preserving input structure."""
if not recursive:
output_dir.mkdir(parents=True, exist_ok=True)
return
for file in files:
output_path = get_output_path(file, input_dir, output_dir, recursive, suffix)
output_path.parent.mkdir(parents=True, exist_ok=True)
def main():
print("=" * 70)
print("Directory Structure Preservation - End-to-End Test")
print("=" * 70)
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
input_dir = tmpdir / "input"
output_dir = tmpdir / "output"
# Create test structure
(input_dir / "projects" / "ProjectA" / "docs").mkdir(parents=True)
(input_dir / "projects" / "ProjectB" / "reports").mkdir(parents=True)
# Create test files
files = [
input_dir / "overview.pdf",
input_dir / "projects" / "ProjectA" / "spec.pdf",
input_dir / "projects" / "ProjectA" / "notes.docx",
input_dir / "projects" / "ProjectA" / "docs" / "manual.pdf",
input_dir / "projects" / "ProjectB" / "design.pdf",
input_dir / "projects" / "ProjectB" / "reports" / "quarterly.docx",
]
for f in files:
f.touch()
print("\n✓ Input structure created")
print("\nInput files:")
for f in files:
print(f" {f.relative_to(input_dir)}")
# Create output directories
create_output_directories(files, input_dir, output_dir, recursive=True)
print("\n✓ Output directories created")
print("\nOutput directory structure:")
for root, dirs, filenames in os.walk(output_dir):
root_path = Path(root)
level = root_path.relative_to(output_dir)
# Print directory name
if str(level) != ".":
indent = " " * len(level.parts)
print(f"{indent}{root_path.name}/")
# Print files
for filename in filenames:
indent = " " * (len(level.parts) + 1)
print(f"{indent}{filename}")
# Verify structure
print("\n" + "=" * 70)
print("Verification")
print("=" * 70)
expected_structure = {
"overview.md",
"projects_md/ProjectA_md/spec.md",
"projects_md/ProjectA_md/notes.md",
"projects_md/ProjectA_md/docs_md/manual.md",
"projects_md/ProjectB_md/design.md",
"projects_md/ProjectB_md/reports_md/quarterly.md",
}
# Check each file
all_correct = True
for f in files:
out_path = get_output_path(f, input_dir, output_dir, recursive=True)
rel_output = out_path.relative_to(output_dir)
expected = str(rel_output)
# Verify _md suffix in all directory components
has_md_suffix = all(
part.endswith("_md") or part.endswith(".md") for part in rel_output.parts
)
status = "✓" if has_md_suffix else "✗"
print(f" {status} {str(f.relative_to(input_dir)):45s} -> {rel_output}")
if not has_md_suffix:
all_correct = False
print(f" ERROR: Missing _md suffix!")
# Verify file would be in correct location
expected_path = output_dir / expected
if str(rel_output) not in expected_structure:
print(f" ERROR: Unexpected path!")
all_correct = False
# Verify directories exist
print("\nDirectory verification:")
expected_dirs = [
"projects_md",
"projects_md/ProjectA_md",
"projects_md/ProjectB_md",
"projects_md/ProjectA_md/docs_md",
"projects_md/ProjectB_md/reports_md",
]
for dir_name in expected_dirs:
dir_path = output_dir / dir_name
exists = dir_path.exists() and dir_path.is_dir()
status = "✓" if exists else "✗"
print(f" {status} {dir_name}")
if not exists:
all_correct = False
print("\n" + "=" * 70)
if all_correct:
print("✓ SUCCESS: All directory structures preserved with _md suffix!")
return 0
else:
print("✗ FAIL: Directory structure preservation has issues!")
return 1
print("=" * 70)
if __name__ == "__main__":
import sys
sys.exit(main())