Skip to content

Commit a2cd56c

Browse files
committed
Update test_plugins.py
1 parent 3c8ce02 commit a2cd56c

File tree

1 file changed

+58
-50
lines changed

1 file changed

+58
-50
lines changed

tests/test_plugins.py

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,102 @@
33
Test plugin functionality
44
"""
55

6-
import pytest
76
import sys
87
import os
8+
import importlib
9+
10+
# Try to import pytest, but don't fail if it's not available
11+
try:
12+
import pytest
13+
except ImportError:
14+
pytest = None
15+
916
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1017

11-
from optillm.plugins import load_plugin, is_plugin_approach
12-
from optillm.plugins.memory_plugin import should_enable_memory
18+
from optillm import plugin_approaches, load_plugins
1319

1420

15-
def test_plugin_loading():
16-
"""Test loading plugins"""
17-
# Test loading a known plugin
18-
plugin = load_plugin("memory")
19-
assert plugin is not None
20-
assert hasattr(plugin, 'run')
21+
def test_plugin_module_imports():
22+
"""Test that plugin modules can be imported"""
23+
plugin_modules = [
24+
'optillm.plugins.memory_plugin',
25+
'optillm.plugins.readurls_plugin',
26+
'optillm.plugins.privacy_plugin',
27+
'optillm.plugins.genselect_plugin',
28+
'optillm.plugins.majority_voting_plugin'
29+
]
2130

22-
# Test loading non-existent plugin returns None
23-
plugin = load_plugin("nonexistent")
24-
assert plugin is None
31+
for module_name in plugin_modules:
32+
try:
33+
module = importlib.import_module(module_name)
34+
assert hasattr(module, 'run'), f"{module_name} missing 'run' function"
35+
assert hasattr(module, 'SLUG'), f"{module_name} missing 'SLUG' attribute"
36+
except ImportError as e:
37+
if pytest:
38+
pytest.fail(f"Failed to import {module_name}: {e}")
39+
else:
40+
raise AssertionError(f"Failed to import {module_name}: {e}")
2541

2642

27-
def test_is_plugin_approach():
28-
"""Test plugin approach detection"""
29-
# Known plugins
30-
assert is_plugin_approach("memory") == True
31-
assert is_plugin_approach("readurls") == True
32-
assert is_plugin_approach("privacy") == True
43+
def test_plugin_approach_detection():
44+
"""Test plugin approach detection after loading"""
45+
# Load plugins first
46+
load_plugins()
3347

34-
# Non-plugins
35-
assert is_plugin_approach("mcts") == False
36-
assert is_plugin_approach("bon") == False
37-
assert is_plugin_approach("nonexistent") == False
48+
# Check if known plugins are loaded
49+
expected_plugins = ["memory", "readurls", "privacy"]
50+
for plugin_name in expected_plugins:
51+
assert plugin_name in plugin_approaches, f"Plugin {plugin_name} not loaded"
3852

3953

40-
def test_memory_plugin_detection():
41-
"""Test memory plugin auto-detection"""
42-
# Test with context length exceeding threshold
43-
long_context = "x" * 500000 # 500k chars
44-
assert should_enable_memory(long_context) == True
45-
46-
# Test with short context
47-
short_context = "Hello world"
48-
assert should_enable_memory(short_context) == False
49-
50-
# Test with explicit false in config
51-
assert should_enable_memory(long_context, {"memory": False}) == False
52-
53-
# Test with explicit true in config
54-
assert should_enable_memory(short_context, {"memory": True}) == True
54+
def test_memory_plugin_structure():
55+
"""Test memory plugin has required structure"""
56+
import optillm.plugins.memory_plugin as plugin
57+
assert hasattr(plugin, 'run')
58+
assert hasattr(plugin, 'SLUG')
59+
assert plugin.SLUG == "memory"
60+
assert hasattr(plugin, 'Memory') # Check for Memory class
5561

5662

5763
def test_genselect_plugin():
58-
"""Test genselect plugin exists"""
59-
plugin = load_plugin("genselect")
60-
assert plugin is not None
64+
"""Test genselect plugin module"""
65+
import optillm.plugins.genselect_plugin as plugin
6166
assert hasattr(plugin, 'run')
67+
assert hasattr(plugin, 'SLUG')
6268
assert hasattr(plugin, 'DEFAULT_NUM_CANDIDATES')
69+
assert plugin.SLUG == "genselect"
6370

6471

6572
def test_majority_voting_plugin():
66-
"""Test majority voting plugin"""
67-
plugin = load_plugin("majority_voting")
68-
assert plugin is not None
73+
"""Test majority voting plugin module"""
74+
import optillm.plugins.majority_voting_plugin as plugin
6975
assert hasattr(plugin, 'run')
76+
assert hasattr(plugin, 'SLUG')
7077
assert hasattr(plugin, 'extract_answer')
7178
assert hasattr(plugin, 'normalize_answer')
79+
assert plugin.SLUG == "majority_voting"
7280

7381

7482
if __name__ == "__main__":
7583
print("Running plugin tests...")
7684

7785
try:
78-
test_plugin_loading()
79-
print("✅ Plugin loading test passed")
86+
test_plugin_module_imports()
87+
print("✅ Plugin module imports test passed")
8088
except Exception as e:
81-
print(f"❌ Plugin loading test failed: {e}")
89+
print(f"❌ Plugin module imports test failed: {e}")
8290

8391
try:
84-
test_is_plugin_approach()
92+
test_plugin_approach_detection()
8593
print("✅ Plugin approach detection test passed")
8694
except Exception as e:
8795
print(f"❌ Plugin approach detection test failed: {e}")
8896

8997
try:
90-
test_memory_plugin_detection()
91-
print("✅ Memory plugin detection test passed")
98+
test_memory_plugin_structure()
99+
print("✅ Memory plugin structure test passed")
92100
except Exception as e:
93-
print(f"❌ Memory plugin detection test failed: {e}")
101+
print(f"❌ Memory plugin structure test failed: {e}")
94102

95103
try:
96104
test_genselect_plugin()

0 commit comments

Comments
 (0)