-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_output_manager.py
More file actions
52 lines (40 loc) · 1.56 KB
/
Copy pathtest_output_manager.py
File metadata and controls
52 lines (40 loc) · 1.56 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
#!/usr/bin/env python3
"""Test script to verify the GradioOutputManager works correctly."""
import sys
import os
sys.path.append(os.path.dirname(__file__))
# Import our output manager
from app import GradioOutputManager, FEEDBACK_OUTPUTS
def test_output_manager():
"""Test the output manager functionality."""
print("Testing GradioOutputManager...")
# Create an output manager for feedback outputs
outputs = GradioOutputManager(FEEDBACK_OUTPUTS)
# Test setting individual values
outputs.set("recommendations", "test_recommendation")
outputs.set("chatbox", [{"role": "assistant", "content": "test"}])
# Test setting multiple values
outputs.set_multiple(
keep_btn="keep_value",
adjust_btn="adjust_value",
rec_index_state=5
)
# Get the tuple
result = outputs.get_tuple()
print(f"Output length: {len(result)}")
print(f"Expected length: {len(FEEDBACK_OUTPUTS)}")
print(f"Match: {len(result) == len(FEEDBACK_OUTPUTS)}")
# Check specific values
print(f"recommendations (index 0): {result[0]}")
print(f"keep_btn (index 1): {result[1]}")
print(f"chatbox (index 6): {result[6]}")
print(f"rec_index_state (index 4): {result[4]}")
# Test error handling
try:
outputs.set("invalid_output", "test")
print("ERROR: Should have raised ValueError for invalid output name")
except ValueError as e:
print(f"✅ Correctly caught error: {e}")
print("✅ All tests passed!")
if __name__ == "__main__":
test_output_manager()