#!/usr/bin/env python3 """ Test version round-trip: save with v2.0, load with v2.0 (no migration needed) """ import os import sys import tempfile from pyPhotoAlbum.project import Project from pyPhotoAlbum.project_serializer import save_to_zip, load_from_zip from pyPhotoAlbum.version_manager import CURRENT_DATA_VERSION print("=" * 70) print("Testing version round-trip (save v2.0, load v2.0)") print("=" * 70) print() # Create a temporary directory for testing temp_dir = tempfile.mkdtemp(prefix="pyphotos_test_") test_ppz = os.path.join(temp_dir, "test_project.ppz") try: # Create a new project print("Creating new project...") project = Project("Test Project") print(f" Project folder: {project.folder_path}") print() # Save it print(f"Saving to: {test_ppz}") success, error = save_to_zip(project, test_ppz) if not success: print(f"ERROR: Failed to save: {error}") sys.exit(1) print(" Saved successfully!") print() # Load it back print(f"Loading from: {test_ppz}") loaded_project, error = load_from_zip(test_ppz) if error: print(f"ERROR: Failed to load: {error}") sys.exit(1) print(f" Loaded successfully!") print(f" Project name: {loaded_project.name}") print(f" Project folder: {loaded_project.folder_path}") print() # Check that it's version 2.0 and no migration was needed print("Version check:") print(f" Expected version: {CURRENT_DATA_VERSION}") print(f" ✓ No migration was performed (would have been logged if needed)") print() print("=" * 70) print("SUCCESS! Version round-trip test passed.") print("=" * 70) finally: # Cleanup import shutil if os.path.exists(temp_dir): shutil.rmtree(temp_dir) print(f"\nCleaned up test directory: {temp_dir}")