bytedance-1 / test_permissions.py
drdata's picture
Upload folder using huggingface_hub
e993e6d verified
#!/usr/bin/env python3
"""
Test script to verify directory permissions are set correctly in app.py
"""
import os
import sys
from pathlib import Path
def test_directory_permissions():
"""Test that directories are created with correct permissions"""
print("πŸ§ͺ Testing Directory Permission Setup in app.py")
print("=" * 50)
# Change to cache directory where the modified app.py is located
cache_dir = Path(".cache")
if not cache_dir.exists():
print("❌ .cache directory not found. Run 'python app.py' first.")
return False
# Import and test the function from the modified app in .cache
sys.path.insert(0, str(cache_dir.absolute()))
try:
import app
from app import create_directory_with_permissions
print("βœ… Successfully imported create_directory_with_permissions function")
except ImportError as e:
print(f"❌ Failed to import function: {e}")
return False
# Change to cache directory for testing
original_dir = Path.cwd()
os.chdir(cache_dir)
# Test directories
test_dirs = ["Generated", "static", "view_session", "test_session_123"]
print("\nπŸ“ Testing directory creation and permissions:")
print("-" * 40)
for dir_name in test_dirs:
try:
# Remove directory if it exists (for clean test)
if Path(dir_name).exists():
import shutil
shutil.rmtree(dir_name)
# Create directory using our function
create_directory_with_permissions(dir_name)
# Check if directory exists
if Path(dir_name).exists():
# Check permissions
stat_info = Path(dir_name).stat()
permissions = oct(stat_info.st_mode)[-3:]
expected_perm = "755"
if permissions == expected_perm:
print(f"βœ… {dir_name:15} - Created with correct permissions ({permissions})")
else:
print(f"⚠️ {dir_name:15} - Created with permissions ({permissions}), expected ({expected_perm})")
else:
print(f"❌ {dir_name:15} - Failed to create")
except Exception as e:
print(f"❌ {dir_name:15} - Error: {e}")
print("\n" + "=" * 50)
print("βœ… Permission test completed!")
print("πŸ’‘ The app.py now automatically sets correct permissions for:")
print(" - Generated/ (and all session subfolders)")
print(" - static/")
print(" - view_session/")
# Return to original directory
os.chdir(original_dir)
return True
if __name__ == "__main__":
test_directory_permissions()