-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
116 lines (92 loc) · 3.65 KB
/
test_setup.py
File metadata and controls
116 lines (92 loc) · 3.65 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
"""
Test script for TopSpin API wrapper.
This script verifies that the TopSpin API wrapper is correctly installed and configured.
"""
import sys
from pathlib import Path
def test_import():
"""Test that TopSpin API module can be imported."""
print("[Test 1] Testing TopSpin API import...")
try:
from topspin_api import TopSpinAPI
print(" [OK] TopSpinAPI module imported successfully")
return True
except ImportError as e:
print(f" [FAIL] Import failed: {e}")
return False
def test_initialization():
"""Test that TopSpin API can be initialized."""
print("\n[Test 2] Testing TopSpin API initialization...")
try:
from topspin_api import TopSpinAPI
api = TopSpinAPI(topspin_path="D:/topspin")
print(f" [OK] TopSpin API initialized")
# Try to get version - this requires TopSpin to be running
try:
version = api.get_version()
print(f" [OK] Version: {version}")
print(f" [OK] Installation: {api.get_installation_directory()}")
except Exception as e:
if "UNAVAILABLE" in str(e) or "connection refused" in str(e).lower():
print(f" [OK] TopSpin not running (expected)")
print(f" [INFO] Start TopSpin first to connect to running instance")
else:
raise
return True
except Exception as e:
print(f" [FAIL] Initialization failed: {e}")
return False
def test_example_pulse_sequence_exists():
"""Test that example pulse sequence file exists."""
print("\n[Test 3] Testing example pulse sequence file...")
pulse_path = Path("D:/topspin/examdata/Cyclosporine/1/pulseprogram")
if pulse_path.exists():
print(f" [OK] Example pulse sequence found: {pulse_path}")
return True
else:
print(f" [INFO] Example pulse sequence not found: {pulse_path}")
print(f" This is normal - TopSpin uses precompiled pulse programs (pulseprogram.precomp)")
print(f" Use TopSpin's edpul command to open the pulse sequence editor")
return True # This is expected, so pass the test
def test_dependencies():
"""Test that required dependencies are installed."""
print("\n[Test 4] Testing required dependencies...")
dependencies = ["numpy", "xarray", "matplotlib"]
all_ok = True
for dep in dependencies:
try:
__import__(dep)
print(f" [OK] {dep}")
except ImportError:
print(f" [SKIP] {dep} not installed (optional for basic functionality)")
all_ok = all_ok # Don't fail if optional deps are missing
return all_ok
def main():
"""Run all tests."""
print("="*70)
print("TopSpin API Wrapper - Installation Test")
print("="*70)
results = []
# Run tests
results.append(("Import", test_import()))
results.append(("Initialization", test_initialization()))
results.append(("Example File", test_example_pulse_sequence_exists()))
results.append(("Dependencies", test_dependencies()))
# Summary
print("\n" + "="*70)
print("Test Summary")
print("="*70)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "[PASS]" if result else "[FAIL]"
print(f" {test_name}: {status}")
print(f"\nResults: {passed}/{total} tests passed")
if passed == total:
print("\n[OK] All tests passed! TopSpin API wrapper is ready to use.")
return 0
else:
print("\n[FAIL] Some tests failed. Please fix the issues above.")
return 1
if __name__ == "__main__":
sys.exit(main())