-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_setup.py
More file actions
131 lines (117 loc) · 4.06 KB
/
test_setup.py
File metadata and controls
131 lines (117 loc) · 4.06 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
import os
from dotenv import load_dotenv
from playwright.sync_api import sync_playwright
import praw
import tweepy
from transformers import AutoTokenizer, AutoModelForTokenClassification
def test_environment_variables():
"""Test if all required environment variables are set"""
required_vars = [
'REDDIT_CLIENT_ID',
'REDDIT_CLIENT_SECRET',
'REDDIT_USER_AGENT',
'TWITTER_BEARER_TOKEN',
'TWITTER_API_KEY',
'TWITTER_API_SECRET',
'TWITTER_ACCESS_TOKEN',
'TWITTER_ACCESS_TOKEN_SECRET'
]
missing_vars = []
for var in required_vars:
if not os.getenv(var):
missing_vars.append(var)
if missing_vars:
print("❌ Missing environment variables:", missing_vars)
return False
print("✅ All environment variables are set")
return True
def test_playwright():
"""Test if Playwright is working"""
try:
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context()
page = context.new_page()
page.goto('https://www.amazon.com')
title = page.title()
browser.close()
print("✅ Playwright is working")
return True
except Exception as e:
print(f"❌ Playwright test failed: {str(e)}")
return False
def test_reddit_api():
"""Test if Reddit API is working"""
try:
reddit = praw.Reddit(
client_id=os.getenv('REDDIT_CLIENT_ID'),
client_secret=os.getenv('REDDIT_CLIENT_SECRET'),
user_agent=os.getenv('REDDIT_USER_AGENT')
)
# Try to get a subreddit
subreddit = reddit.subreddit('test')
print("✅ Reddit API is working")
return True
except Exception as e:
print(f"❌ Reddit API test failed: {str(e)}")
return False
def test_twitter_api():
"""Test if Twitter API is working"""
try:
client = tweepy.Client(
bearer_token=os.getenv('TWITTER_BEARER_TOKEN'),
consumer_key=os.getenv('TWITTER_API_KEY'),
consumer_secret=os.getenv('TWITTER_API_SECRET'),
access_token=os.getenv('TWITTER_ACCESS_TOKEN'),
access_token_secret=os.getenv('TWITTER_ACCESS_TOKEN_SECRET')
)
# Try to get a tweet
client.get_tweet('1234567890')
print("✅ Twitter API is working")
return True
except Exception as e:
print(f"❌ Twitter API test failed: {str(e)}")
return False
def test_bert_model():
"""Test if BERT model can be loaded"""
try:
model_name = "dbmdz/bert-large-cased-finetuned-conll03-english"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
print("✅ BERT model loaded successfully")
return True
except Exception as e:
print(f"❌ BERT model test failed: {str(e)}")
return False
def main():
"""Run all tests"""
print("Starting setup verification...")
# Load environment variables
load_dotenv()
# Run tests
tests = [
("Environment Variables", test_environment_variables),
("Playwright", test_playwright),
("Reddit API", test_reddit_api),
("Twitter API", test_twitter_api),
("BERT Model", test_bert_model)
]
results = []
for test_name, test_func in tests:
print(f"\nTesting {test_name}...")
result = test_func()
results.append((test_name, result))
# Print summary
print("\n=== Test Summary ===")
all_passed = True
for test_name, result in results:
status = "✅ PASSED" if result else "❌ FAILED"
print(f"{test_name}: {status}")
if not result:
all_passed = False
if all_passed:
print("\n🎉 All tests passed! The setup is complete and working correctly.")
else:
print("\n⚠️ Some tests failed. Please check the errors above and fix the issues.")
if __name__ == "__main__":
main()