| |
| """ |
| Verification script for Directory Structure Analysis Task |
| """ |
|
|
| import sys |
| from pathlib import Path |
| import os |
| import re |
|
|
| def get_test_directory() -> Path: |
| """Get the test directory from FILESYSTEM_TEST_DIR env var.""" |
| test_root = os.environ.get("FILESYSTEM_TEST_DIR") |
| if not test_root: |
| raise ValueError("FILESYSTEM_TEST_DIR environment variable is required") |
| return Path(test_root) |
|
|
| def verify_structure_analysis_file_exists(test_dir: Path) -> bool: |
| """Verify that the structure_analysis.txt file exists.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| if not analysis_file.exists(): |
| print("β File 'structure_analysis.txt' not found") |
| return False |
| |
| print("β
structure_analysis.txt file found") |
| return True |
|
|
| def verify_structure_analysis_file_readable(test_dir: Path) -> bool: |
| """Verify that the structure_analysis.txt file is readable.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| try: |
| content = analysis_file.read_text() |
| if not content.strip(): |
| print("β structure_analysis.txt file is empty") |
| return False |
| |
| print("β
structure_analysis.txt file is readable") |
| return True |
| |
| except Exception as e: |
| print(f"β Error reading structure_analysis.txt file: {e}") |
| return False |
|
|
| def verify_subtask1_file_statistics(test_dir: Path) -> bool: |
| """Verify subtask 1: File Statistics - files must be 69, folders must be 51, 58097 allows +-1000.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| try: |
| content = analysis_file.read_text() |
| |
| |
| file_count_match = re.search(r'total number of files:\s*(\d+)', content) |
| folder_count_match = re.search(r'total number of folders:\s*(\d+)', content) |
| size_match = re.search(r'total size of all files:\s*(\d+)', content) |
| |
| if not file_count_match or not folder_count_match or not size_match: |
| print("β Could not extract file statistics from structure_analysis.txt") |
| return False |
| |
| file_count = int(file_count_match.group(1)) |
| folder_count = int(folder_count_match.group(1)) |
| total_size = int(size_match.group(1)) |
| |
| print(f"π Found: files={file_count}, folders={folder_count}, size={total_size}") |
| |
| |
| if file_count != 69: |
| print(f"β File count must be 69, found: {file_count}") |
| return False |
| |
| |
| if folder_count != 51: |
| print(f"β Folder count must be 51, found: {folder_count}") |
| return False |
| |
| |
| expected_size = 58097 |
| size_tolerance = 1000 |
| if abs(total_size - expected_size) > size_tolerance: |
| print(f"β Total size ({total_size}) is not within acceptable range ({expected_size} Β± {size_tolerance})") |
| return False |
| |
| print(f"β
File statistics verified: files={file_count}, folders={folder_count}, size={total_size} (within tolerance)") |
| return True |
| |
| except Exception as e: |
| print(f"β Error verifying file statistics: {e}") |
| return False |
|
|
| def verify_subtask2_depth_analysis(test_dir: Path) -> bool: |
| """Verify subtask 2: Depth Analysis - depth must be 7, verify path exists.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| try: |
| content = analysis_file.read_text() |
| |
| |
| depth_match = re.search(r'depth:\s*(\d+)', content) |
| path_match = re.search(r'^([^\n]+)$', content, re.MULTILINE) |
| |
| if not depth_match: |
| print("β Could not extract depth from structure_analysis.txt") |
| return False |
| |
| depth = int(depth_match.group(1)) |
| |
| |
| if depth != 7: |
| print(f"β Depth must be 7, found: {depth}") |
| return False |
| |
| print(f"β
Depth verified: {depth}") |
| |
| |
| lines = content.split('\n') |
| path_line = None |
| for i, line in enumerate(lines): |
| if line.strip() == f"depth: {depth}": |
| if i + 1 < len(lines): |
| path_line = lines[i + 1].strip() |
| break |
| |
| if not path_line: |
| print("β Could not find path line after depth specification") |
| return False |
| |
| print(f"π Found path: {path_line}") |
| |
| |
| path_parts = path_line.split('/') |
| actual_depth = len(path_parts) |
| |
| if actual_depth != depth: |
| print(f"β Path depth mismatch: declared depth is {depth}, but path has {actual_depth} levels") |
| print(f" Path: {path_line}") |
| print(f" Path parts: {path_parts}") |
| return False |
| |
| print(f"β
Path depth verified: {actual_depth} levels") |
| |
| |
| expected_path = test_dir / path_line |
| if not expected_path.exists(): |
| print(f"β Path does not exist: {expected_path}") |
| return False |
| |
| if not expected_path.is_dir(): |
| print(f"β Path exists but is not a directory: {expected_path}") |
| return False |
| |
| print(f"β
Path verified and exists: {path_line}") |
| return True |
| |
| except Exception as e: |
| print(f"β Error verifying depth analysis: {e}") |
| return False |
|
|
| def verify_subtask3_file_type_classification(test_dir: Path) -> bool: |
| """Verify subtask 3: File Type Classification - 68 and 1 must be accurate.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| try: |
| content = analysis_file.read_text() |
| |
| |
| txt_match = re.search(r'txt:\s*(\d+)', content) |
| py_match = re.search(r'py:\s*(\d+)', content) |
| |
| if not txt_match or not py_match: |
| print("β Could not extract file type counts from structure_analysis.txt") |
| return False |
| |
| txt_count = int(txt_match.group(1)) |
| py_count = int(py_match.group(1)) |
| |
| print(f"π Found: txt={txt_count}, py={py_count}") |
| |
| |
| if txt_count != 68: |
| print(f"β txt count must be 68, found: {txt_count}") |
| return False |
| |
| |
| if py_count != 1: |
| print(f"β py count must be 1, found: {py_count}") |
| return False |
| |
| print(f"β
File type classification verified: txt={txt_count}, py={py_count}") |
| return True |
| |
| except Exception as e: |
| print(f"β Error verifying file type classification: {e}") |
| return False |
|
|
| def verify_file_format(test_dir: Path) -> bool: |
| """Verify that the structure_analysis.txt file has proper format.""" |
| analysis_file = test_dir / "structure_analysis.txt" |
| |
| try: |
| content = analysis_file.read_text() |
| lines = content.split('\n') |
| |
| |
| if len(lines) < 5: |
| print("β File seems too short to contain all required information") |
| return False |
| |
| |
| if not content.strip(): |
| print("β File is completely empty") |
| return False |
| |
| print("β
File format is acceptable") |
| return True |
| |
| except Exception as e: |
| print(f"β Error checking file format: {e}") |
| return False |
|
|
| def main(): |
| """Main verification function.""" |
| try: |
| test_dir = get_test_directory() |
| print(f"π Verifying Directory Structure Analysis Task in: {test_dir}") |
| |
| |
| verification_steps = [ |
| ("Structure Analysis File Exists", verify_structure_analysis_file_exists), |
| ("File is Readable", verify_structure_analysis_file_readable), |
| ("Subtask 1: File Statistics", verify_subtask1_file_statistics), |
| ("Subtask 2: Depth Analysis", verify_subtask2_depth_analysis), |
| ("Subtask 3: File Type Classification", verify_subtask3_file_type_classification), |
| ("File Format", verify_file_format), |
| ] |
| |
| |
| all_passed = True |
| for step_name, verify_func in verification_steps: |
| print(f"\n--- {step_name} ---") |
| if not verify_func(test_dir): |
| all_passed = False |
| |
| |
| print("\n" + "="*50) |
| if all_passed: |
| print("β
Directory Structure Analysis completed correctly!") |
| print("π Structure Analysis verification: PASS") |
| sys.exit(0) |
| else: |
| print("β Structure Analysis verification: FAIL") |
| sys.exit(1) |
| |
| except Exception as e: |
| print(f"β Verification failed with error: {e}") |
| sys.exit(1) |
|
|
| if __name__ == "__main__": |
| main() |