-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_installation.py
More file actions
154 lines (121 loc) · 4.27 KB
/
test_installation.py
File metadata and controls
154 lines (121 loc) · 4.27 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
"""
End-to-end test script for demopy_gb_jj package installation and functionality.
This script tests:
1. Package installation from PyPI
2. Rust extension functionality (if available)
3. Python fallback functionality
4. Version consistency
5. All exported functions
"""
import subprocess
import sys
import tempfile
import os
from pathlib import Path
def run_command(cmd, description):
"""Run a command and return success status."""
print(f"🔄 {description}...")
try:
result = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
print(f"✅ {description} - SUCCESS")
if result.stdout.strip():
print(f" Output: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} - FAILED")
print(f" Error: {e.stderr.strip() if e.stderr else str(e)}")
return False
def test_package_functionality():
"""Test the package functionality."""
test_code = '''
import demopy
print("=== PACKAGE FUNCTIONALITY TEST ===")
# Test version
print(f"Version: {demopy.__version__}")
# Test all functions
print(f"hello(): {demopy.hello()}")
print(f"add(2, 3): {demopy.add(2, 3)}")
print(f"multiply(2.5, 4.0): {demopy.multiply(2.5, 4.0)}")
print(f"sum_list([1,2,3,4,5]): {demopy.sum_list([1,2,3,4,5])}")
print(f"reverse_string('Hello World'): {demopy.reverse_string('Hello World')}")
# Test __all__ exports
print(f"Exported functions: {demopy.__all__}")
# Detect if using Rust extension or Python fallback
hello_msg = demopy.hello()
if "Rust edition" in hello_msg:
print("✅ Using Rust extension")
elif "Python fallback" in hello_msg:
print("✅ Using Python fallback")
else:
print("⚠️ Unknown backend")
print("=== ALL TESTS PASSED ===")
'''
return run_command(f'python -c "{test_code}"', "Test package functionality")
def test_fallback_mechanism():
"""Test that fallback works when Rust extension is unavailable."""
fallback_test = '''
import sys
import builtins
# Mock import error for Rust extension
original_import = builtins.__import__
def mock_import(name, *args, **kwargs):
if "demopy_gb_jj._rust" in name:
raise ImportError("Mocked import error for testing")
return original_import(name, *args, **kwargs)
builtins.__import__ = mock_import
# Now import demopy - should use fallback
import demopy
print("=== FALLBACK MECHANISM TEST ===")
hello_msg = demopy.hello()
print(f"hello(): {hello_msg}")
if "Python fallback" in hello_msg:
print("✅ Fallback mechanism working correctly")
# Test all fallback functions
print(f"add(5, 7): {demopy.add(5, 7)}")
print(f"multiply(3.0, 2.5): {demopy.multiply(3.0, 2.5)}")
print(f"sum_list([10,20,30]): {demopy.sum_list([10,20,30])}")
print(f"reverse_string('Fallback'): {demopy.reverse_string('Fallback')}")
print("✅ All fallback functions working")
else:
print("❌ Fallback mechanism not working")
sys.exit(1)
print("=== FALLBACK TEST PASSED ===")
'''
return run_command(f'python -c "{fallback_test}"', "Test fallback mechanism")
def main():
"""Main test function."""
print("🚀 Starting End-to-End Package Testing")
print("=" * 50)
# Test 1: Install package from PyPI
success = run_command(
"pip install --upgrade demopy_gb_jj",
"Install package from PyPI"
)
if not success:
print("❌ Package installation failed. Check if it's published to PyPI.")
return False
# Test 2: Test package functionality
if not test_package_functionality():
return False
# Test 3: Test fallback mechanism
if not test_fallback_mechanism():
return False
# Test 4: Verify version consistency
success = run_command(
'python -c "import demopy; print(f\'Package version: {demopy.__version__}\')"',
"Verify version consistency"
)
if not success:
return False
print("\n" + "=" * 50)
print("🎉 ALL END-TO-END TESTS PASSED!")
print("✅ Package installation successful")
print("✅ Rust extension or fallback working")
print("✅ All functions operational")
print("✅ Version consistency verified")
print("=" * 50)
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)