#!/usr/bin/env python3 """ Test script to verify update_version.py only updates the project version. This script creates a test pyproject.toml with multiple version fields and verifies that only the [project] section version is updated. """ import os import sys import tempfile from pathlib import Path # Add scripts directory to path so we can import update_version sys.path.insert(0, str(Path(__file__).parent.parent / "scripts")) from update_version import update_pyproject_version def test_selective_version_update(): """Test that only the project version is updated, not other version fields.""" test_content = """[project] name = "test" version = "1.0.0" description = "Test project" [tool.pytest.ini_options] minversion = "8.0" [tool.ruff] target-version = "py313" [other] version = "2.0.0" some_version = "3.0.0" """ expected_content = """[project] name = "test" version = "1.5.0" description = "Test project" [tool.pytest.ini_options] minversion = "8.0" [tool.ruff] target-version = "py313" [other] version = "2.0.0" some_version = "3.0.0" """ # Create temporary file with tempfile.NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f: f.write(test_content) temp_path = Path(f.name) try: # Update the version result = update_pyproject_version(temp_path, "1.5.0") # Check that update was successful assert result, "Version update should succeed" # Read the updated content with open(temp_path, encoding="utf-8") as f: updated_content = f.read() # Verify the content matches expectations assert updated_content == expected_content, ( f"Content doesn't match expectations.\n" f"Expected:\n{expected_content}\n" f"Got:\n{updated_content}" ) print("✅ Test passed: Only [project] version was updated") print(" - Project version: 1.0.0 → 1.5.0") print(" - minversion: 8.0 (unchanged)") print(" - target-version: py313 (unchanged)") print(" - Other versions: unchanged") finally: # Clean up os.unlink(temp_path) if __name__ == "__main__": test_selective_version_update()