35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Verification test for dir_analyzer.py"""
|
|
import subprocess
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def _check(cond, msg):
|
|
"""A failure path `-O` cannot compile away (Q63: assert-only files exit 0 under -O)."""
|
|
if not cond:
|
|
raise RuntimeError(msg)
|
|
|
|
|
|
# Test JSON mode
|
|
result = subprocess.run(['python3', 'dir_analyzer.py', '/etc', '--json'],
|
|
capture_output=True, text=True, cwd=Path(__file__).resolve().parents[2] / 'wizard-work' / 'spark')
|
|
data = json.loads(result.stdout)
|
|
|
|
_check('total_files' in data, "Missing total_files")
|
|
_check('total_size_bytes' in data, "Missing total_size_bytes")
|
|
_check(data['total_files'] > 0, "Should find files in /etc")
|
|
_check(data['total_size_bytes'] > 0, "Should have size > 0")
|
|
|
|
print(f"JSON mode: PASS - {data['total_files']} files, {data['total_size_bytes']} bytes")
|
|
|
|
# Test text mode
|
|
result2 = subprocess.run(['python3', 'dir_analyzer.py', '/tmp'],
|
|
capture_output=True, text=True, cwd=Path(__file__).resolve().parents[2] / 'wizard-work' / 'spark')
|
|
_check('Total files:' in result2.stdout, "Should show file count")
|
|
_check('Total size:' in result2.stdout, "Should show size")
|
|
|
|
print("Text mode: PASS")
|
|
print("All verification tests passed")
|