-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_connection.py
More file actions
81 lines (63 loc) · 2.62 KB
/
test_connection.py
File metadata and controls
81 lines (63 loc) · 2.62 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
#!/usr/bin/env python3
"""
Test script for SAS to Snowflake SQL Converter
This script helps debug API connection issues and test the converter functionality.
"""
import os
import logging
from convert import SASConverter
def load_env_file(env_path: str = '.env') -> None:
"""Load environment variables from a .env file."""
if os.path.exists(env_path):
with open(env_path, 'r') as file:
for line in file:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, value = line.split('=', 1)
os.environ[key.strip()] = value.strip()
def main():
"""Test the converter with detailed logging."""
# Setup verbose logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Load .env file and get API key
load_env_file()
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
logger.error("❌ GEMINI_API_KEY not found in environment or .env file")
print("\nTo fix this:")
print("1. Create a .env file: cp env.example .env")
print("2. Add your API key to .env file")
print("3. Get API key from: https://makersuite.google.com/app/apikey")
return
logger.info(f"🔑 API key found (length: {len(api_key)} characters)")
# Test API key format
if not api_key.startswith('AI'):
logger.warning("⚠️ API key doesn't start with 'AI' - this might be invalid")
try:
# Initialize converter
logger.info("🚀 Initializing SAS converter...")
converter = SASConverter(api_key)
# Test API connection
logger.info("🧪 Testing API connection...")
if converter.test_api_connection():
logger.info("✅ API connection successful!")
# Try a simple conversion
logger.info("🔄 Testing simple conversion...")
test_sas = "DATA test; SET input; RUN;"
result = converter._make_gemini_request(test_sas)
if result:
logger.info("✅ Simple conversion successful!")
logger.info(f"📝 Result: {result[:100]}...")
else:
logger.error("❌ Simple conversion failed")
else:
logger.error("❌ API connection failed")
except Exception as e:
logger.error(f"💥 Error during testing: {e}")
logger.debug(f"Exception type: {type(e).__name__}")
if __name__ == '__main__':
main()