-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic_functionality.py
More file actions
181 lines (150 loc) · 5.16 KB
/
test_basic_functionality.py
File metadata and controls
181 lines (150 loc) · 5.16 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
#!/usr/bin/env python3
"""
Basic functionality test for Cost Katana Python SDK
"""
import sys
from pathlib import Path
def test_imports():
"""Test that all modules can be imported"""
print("Testing imports...")
try:
import cost_katana
from cost_katana import (
configure, create_generative_model, CostKatanaClient
)
from cost_katana.config import Config
from cost_katana.exceptions import CostKatanaError
from cost_katana.models import GenerativeModel, ChatSession
print("✓ All imports successful")
return True
except ImportError as e:
print(f"✗ Import failed: {e}")
return False
def test_config():
"""Test configuration functionality"""
print("\nTesting configuration...")
try:
from cost_katana.config import Config
# Test default config
config = Config()
print(f"✓ Default config created: {config.default_model}")
# Test config from file
config_path = Path("cost_katana_config.json")
if config_path.exists():
config = Config.from_file(str(config_path))
print(f"✓ Config loaded from file: {config.default_model}")
# Test model mapping
model_id = config.get_model_mapping("nova-lite")
print(f"✓ Model mapping works: nova-lite -> {model_id}")
return True
except Exception as e:
print(f"✗ Config test failed: {e}")
return False
def test_client():
"""Test client functionality"""
print("\nTesting client...")
try:
from cost_katana.client import CostKatanaClient
# Test client creation (without API key)
try:
client = CostKatanaClient()
print("✗ Client should require API key")
return False
except Exception as e:
print(f"✓ Client properly validates API key: {type(e).__name__}")
return True
except Exception as e:
print(f"✗ Client test failed: {e}")
return False
def test_models():
"""Test model classes"""
print("\nTesting model classes...")
try:
from cost_katana.models import GenerativeModel, ChatSession, GenerationConfig, UsageMetadata
# Test GenerationConfig
config = GenerationConfig(temperature=0.5, max_output_tokens=1000)
print(f"✓ GenerationConfig created: temp={config.temperature}")
# Test UsageMetadata
metadata = UsageMetadata(
prompt_tokens=100,
completion_tokens=50,
total_tokens=150,
cost=0.001,
latency=1.5,
model="test-model"
)
print(f"✓ UsageMetadata created: cost=${metadata.cost}")
return True
except Exception as e:
print(f"✗ Models test failed: {e}")
return False
def test_cli():
"""Test CLI functionality"""
print("\nTesting CLI...")
try:
import subprocess
import sys
# Test CLI help
result = subprocess.run([
sys.executable, "-m", "cost_katana.cli", "--help"
], capture_output=True, text=True)
if result.returncode == 0:
print("✓ CLI help command works")
else:
print(f"✗ CLI help failed: {result.stderr}")
return False
# Test CLI init (skip in non-interactive mode)
print("✓ CLI init command works (skipped in test mode)")
return True
except Exception as e:
print(f"✗ CLI test failed: {e}")
return False
def test_examples():
"""Test example usage patterns"""
print("\nTesting example usage...")
try:
import cost_katana
# Test basic configuration
print("✓ Basic import successful")
# Test model creation (without actual API call)
try:
# This should fail without proper configuration
model = cost_katana.create_generative_model("nova-lite")
print("✗ Should require configuration")
return False
except Exception as e:
print(f"✓ Properly requires configuration: {type(e).__name__}")
return True
except Exception as e:
print(f"✗ Examples test failed: {e}")
return False
def main():
"""Run all tests"""
print("Cost Katana Python SDK - Basic Functionality Test")
print("=" * 50)
tests = [
test_imports,
test_config,
test_client,
test_models,
test_cli,
test_examples,
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
except Exception as e:
print(f"✗ Test {test.__name__} crashed: {e}")
print("\n" + "=" * 50)
print(f"Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! The SDK is ready to use.")
return 0
else:
print("❌ Some tests failed. Please check the implementation.")
return 1
if __name__ == "__main__":
sys.exit(main())