-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathtest_package_install.py
More file actions
211 lines (171 loc) · 5.35 KB
/
test_package_install.py
File metadata and controls
211 lines (171 loc) · 5.35 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python3
"""
Test script to verify package installation works correctly.
Run this after installing the package:
pip install -e ".[webui,llm]"
python test_package_install.py
"""
import sys
import os
import subprocess
import time
from pathlib import Path
def _cli_import_ok() -> bool:
"""Test that the CLI module can be imported."""
print("Testing CLI import...", end=" ")
try:
from refchecker.core.refchecker import main
print("✓ OK")
return True
except ImportError as e:
print(f"✗ FAILED: {e}")
return False
def _webui_import_ok() -> bool:
"""Test that the WebUI backend module can be imported."""
print("Testing WebUI backend import...", end=" ")
try:
from backend.cli import main
print("✓ OK")
return True
except ImportError as e:
print(f"✗ FAILED: {e}")
return False
def _backend_app_import_ok() -> bool:
"""Test that the FastAPI app can be imported."""
print("Testing FastAPI app import...", end=" ")
try:
from backend.main import app
print("✓ OK")
return True
except ImportError as e:
print(f"✗ FAILED: {e}")
return False
def _cli_command_ok() -> bool:
"""Test that the CLI command is accessible."""
print("Testing 'academic-refchecker --help'...", end=" ")
try:
result = subprocess.run(
[sys.executable, "-m", "refchecker", "--help"],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
print("✓ OK")
return True
else:
print(f"✗ FAILED: {result.stderr}")
return False
except Exception as e:
print(f"✗ FAILED: {e}")
return False
def _webui_command_ok() -> bool:
"""Test that the WebUI command is accessible."""
print("Testing 'refchecker-webui --help'...", end=" ")
try:
executable_dir = Path(sys.executable).resolve().parent
command = executable_dir / "refchecker-webui"
if command.exists():
args = [str(command), "--help"]
else:
args = [sys.executable, "-m", "backend", "--help"]
result = subprocess.run(
args,
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
print("✓ OK")
return True
else:
print(f"✗ FAILED: {result.stderr}")
return False
except Exception as e:
print(f"✗ FAILED: {e}")
return False
def _webui_server_starts_ok() -> bool:
"""Test that the WebUI backend server starts successfully."""
print("Testing WebUI server startup...", end=" ")
try:
import socket
import threading
# Check if port 8765 is available (use non-standard port for testing)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1', 8765))
sock.close()
if result == 0:
print("⚠ SKIPPED: port 8765 already in use")
return True
# Start server in background
proc = subprocess.Popen(
[sys.executable, "-m", "backend", "--port", "8765"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.path.dirname(os.path.abspath(__file__))
)
# Wait for server to start
time.sleep(3)
# Check if server is responding
try:
import urllib.request
response = urllib.request.urlopen("http://127.0.0.1:8765/api/health", timeout=5)
if response.status == 200:
print("✓ OK")
proc.terminate()
return True
except Exception as e:
pass
# Check if process is still running
if proc.poll() is None:
print("✓ OK (server started)")
proc.terminate()
return True
else:
stdout, stderr = proc.communicate()
print(f"✗ FAILED: server exited with {proc.returncode}")
print(f" stderr: {stderr.decode()[:200]}")
return False
except Exception as e:
print(f"✗ FAILED: {e}")
return False
def test_cli_import():
assert _cli_import_ok()
def test_webui_import():
assert _webui_import_ok()
def test_backend_app_import():
assert _backend_app_import_ok()
def test_cli_command():
assert _cli_command_ok()
def test_webui_command():
assert _webui_command_ok()
def test_webui_server_starts():
assert _webui_server_starts_ok()
def main():
print("=" * 60)
print("RefChecker Package Installation Test")
print("=" * 60)
print()
tests = [
_cli_import_ok,
_webui_import_ok,
_backend_app_import_ok,
_cli_command_ok,
_webui_command_ok,
_webui_server_starts_ok,
]
results = []
for test in tests:
results.append(test())
print()
print("=" * 60)
passed = sum(results)
total = len(results)
if passed == total:
print(f"All {total} tests passed! ✓")
return 0
else:
print(f"{passed}/{total} tests passed")
return 1
if __name__ == "__main__":
sys.exit(main())