File size: 4,073 Bytes
93ed7a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75bcdb3
 
93ed7a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
"""
Test script to verify README template replacement works correctly
"""

import os
import sys
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

def test_readme_template():
    """Test README template replacement"""
    print("πŸ” Testing README template replacement...")
    
    try:
        # Get template path (using trackio as example)
        templates_dir = project_root / "templates" / "spaces" / "trackio"
        readme_template_path = templates_dir / "README.md"
        
        if not readme_template_path.exists():
            print(f"❌ README template not found: {readme_template_path}")
            return False
        
        # Read template
        with open(readme_template_path, 'r', encoding='utf-8') as f:
            template_content = f.read()
        
        print(f"βœ… README template loaded ({len(template_content)} characters)")
        
        # Test placeholder replacement
        test_space_url = "https://huggingface.co/spaces/test-user/test-space"
        replaced_content = template_content.replace("{SPACE_URL}", test_space_url)
        
        if "{SPACE_URL}" in replaced_content:
            print("❌ Placeholder replacement failed")
            return False
        
        if test_space_url not in replaced_content:
            print("❌ Space URL not found in replaced content")
            return False
        
        print("βœ… Placeholder replacement works correctly")
        print(f"βœ… Space URL: {test_space_url}")
        
        return True
        
    except Exception as e:
        print(f"❌ README template test failed: {e}")
        return False

def test_deployment_readme():
    """Test that deployment script can use README template"""
    print("\nπŸ” Testing deployment script README usage...")
    
    try:
        from scripts.trackio_tonic.deploy_trackio_space import TrackioSpaceDeployer
        
        # Create a mock deployer
        deployer = TrackioSpaceDeployer("test-space", "test-user", "test-token")
        
        # Test that templates directory exists
        project_root = Path(__file__).parent
        templates_dir = project_root / "templates" / "spaces"
        readme_template_path = templates_dir / "README.md"
        
        if readme_template_path.exists():
            print(f"βœ… README template exists: {readme_template_path}")
            
            # Test reading template
            with open(readme_template_path, 'r', encoding='utf-8') as f:
                content = f.read()
                if "{SPACE_URL}" in content:
                    print("βœ… Template contains placeholder")
                else:
                    print("⚠️  Template missing placeholder")
            
            return True
        else:
            print(f"❌ README template missing: {readme_template_path}")
            return False
        
    except Exception as e:
        print(f"❌ Deployment README test failed: {e}")
        return False

def main():
    """Run all tests"""
    print("πŸš€ Testing README Template System")
    print("=" * 50)
    
    tests = [
        test_readme_template,
        test_deployment_readme
    ]
    
    passed = 0
    total = len(tests)
    
    for test in tests:
        if test():
            passed += 1
        else:
            print(f"❌ Test failed: {test.__name__}")
    
    print(f"\n{'='*50}")
    print(f"πŸ“Š Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! README template system is working correctly.")
        print("\nπŸš€ Template workflow:")
        print("1. README template is read from templates/spaces/README.md")
        print("2. {SPACE_URL} placeholder is replaced with actual space URL")
        print("3. Customized README is written to the space")
        return 0
    else:
        print("❌ Some tests failed. Please fix the issues before deployment.")
        return 1

if __name__ == "__main__":
    exit(main())