Quazim0t0 commited on
Commit
76b31b6
·
verified ·
1 Parent(s): 6a89e1d

Delete test_app.py

Browse files
Files changed (1) hide show
  1. test_app.py +0 -237
test_app.py DELETED
@@ -1,237 +0,0 @@
1
- """
2
- Test script for Dynamic Highscores application.
3
-
4
- This script tests the key functionality of the Dynamic Highscores application
5
- to ensure everything works as expected before deployment.
6
- """
7
-
8
- import os
9
- import unittest
10
- import tempfile
11
- import sqlite3
12
- from unittest.mock import MagicMock, patch
13
-
14
- # Import components to test
15
- from database_schema import DynamicHighscoresDB
16
- from auth import HuggingFaceAuth
17
- from benchmark_selection import BenchmarkSelector
18
- from evaluation_queue import EvaluationQueue
19
- from leaderboard import Leaderboard
20
-
21
- class TestDynamicHighscores(unittest.TestCase):
22
- """Test cases for Dynamic Highscores application."""
23
-
24
- def setUp(self):
25
- """Set up test environment."""
26
- # Create temporary database
27
- self.db_fd, self.db_path = tempfile.mkstemp()
28
- self.db = DynamicHighscoresDB(self.db_path)
29
-
30
- # Mock auth manager
31
- self.auth_manager = HuggingFaceAuth(self.db)
32
-
33
- # Mock components
34
- self.benchmark_selector = BenchmarkSelector(self.db, self.auth_manager)
35
- self.evaluation_queue = EvaluationQueue(self.db, self.auth_manager)
36
- self.leaderboard = Leaderboard(self.db)
37
-
38
- def tearDown(self):
39
- """Clean up test environment."""
40
- os.close(self.db_fd)
41
- os.unlink(self.db_path)
42
-
43
- def test_database_schema(self):
44
- """Test database schema creation."""
45
- # Check if tables were created
46
- conn = sqlite3.connect(self.db_path)
47
- cursor = conn.cursor()
48
-
49
- # Get list of tables
50
- cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
51
- tables = cursor.fetchall()
52
- table_names = [table[0] for table in tables]
53
-
54
- # Check if all expected tables exist
55
- expected_tables = ['users', 'benchmarks', 'models', 'evaluations', 'queue']
56
- for table in expected_tables:
57
- self.assertIn(table, table_names)
58
-
59
- conn.close()
60
-
61
- def test_user_management(self):
62
- """Test user management functionality."""
63
- # Add a test user
64
- user_id = self.db.add_user("test_user", "test_hf_id", False)
65
- self.assertIsNotNone(user_id)
66
-
67
- # Add an admin user
68
- admin_id = self.db.add_user("admin_user", "admin_hf_id", True)
69
- self.assertIsNotNone(admin_id)
70
-
71
- # Test submission limits
72
- self.assertTrue(self.db.can_submit_today(user_id))
73
- self.db.update_submission_date(user_id)
74
- self.assertFalse(self.db.can_submit_today(user_id))
75
-
76
- # Admin should always be able to submit
77
- self.assertTrue(self.db.can_submit_today(admin_id))
78
-
79
- def test_benchmark_management(self):
80
- """Test benchmark management functionality."""
81
- # Add a test benchmark
82
- benchmark_id = self.db.add_benchmark(
83
- name="Test Benchmark",
84
- dataset_id="test/dataset",
85
- description="Test description",
86
- metrics={"accuracy": 1.0}
87
- )
88
- self.assertIsNotNone(benchmark_id)
89
-
90
- # Get benchmarks
91
- benchmarks = self.db.get_benchmarks()
92
- self.assertEqual(len(benchmarks), 1)
93
- self.assertEqual(benchmarks[0]["name"], "Test Benchmark")
94
-
95
- def test_model_management(self):
96
- """Test model management functionality."""
97
- # Add a test user
98
- user_id = self.db.add_user("test_user", "test_hf_id", False)
99
-
100
- # Add a test model
101
- model_id = self.db.add_model(
102
- name="Test Model",
103
- hf_model_id="test/model",
104
- user_id=user_id,
105
- tag="Reasoning",
106
- parameters="7B",
107
- description="Test model description"
108
- )
109
- self.assertIsNotNone(model_id)
110
-
111
- # Get models
112
- models = self.db.get_models()
113
- self.assertEqual(len(models), 1)
114
- self.assertEqual(models[0]["name"], "Test Model")
115
-
116
- # Get models by tag
117
- models = self.db.get_models(tag="Reasoning")
118
- self.assertEqual(len(models), 1)
119
- self.assertEqual(models[0]["tag"], "Reasoning")
120
-
121
- def test_evaluation_management(self):
122
- """Test evaluation management functionality."""
123
- # Add a test user
124
- user_id = self.db.add_user("test_user", "test_hf_id", False)
125
-
126
- # Add a test model
127
- model_id = self.db.add_model(
128
- name="Test Model",
129
- hf_model_id="test/model",
130
- user_id=user_id,
131
- tag="Reasoning"
132
- )
133
-
134
- # Add a test benchmark
135
- benchmark_id = self.db.add_benchmark(
136
- name="Test Benchmark",
137
- dataset_id="test/dataset"
138
- )
139
-
140
- # Add a test evaluation
141
- evaluation_id = self.db.add_evaluation(
142
- model_id=model_id,
143
- benchmark_id=benchmark_id
144
- )
145
- self.assertIsNotNone(evaluation_id)
146
-
147
- # Update evaluation status
148
- self.db.update_evaluation_status(
149
- evaluation_id=evaluation_id,
150
- status="running"
151
- )
152
-
153
- # Get next in queue
154
- next_eval = self.db.get_next_in_queue()
155
- self.assertIsNotNone(next_eval)
156
- self.assertEqual(next_eval["evaluation_id"], evaluation_id)
157
-
158
- # Complete evaluation
159
- self.db.update_evaluation_status(
160
- evaluation_id=evaluation_id,
161
- status="completed",
162
- results={"accuracy": 0.85},
163
- score=85.0
164
- )
165
-
166
- # Get evaluation results
167
- results = self.db.get_evaluation_results()
168
- self.assertEqual(len(results), 1)
169
- self.assertEqual(results[0]["score"], 85.0)
170
-
171
- def test_leaderboard(self):
172
- """Test leaderboard functionality."""
173
- # Add test data
174
- user_id = self.db.add_user("test_user", "test_hf_id", False)
175
-
176
- # Add models with different tags
177
- model1_id = self.db.add_model(
178
- name="Model 1",
179
- hf_model_id="test/model1",
180
- user_id=user_id,
181
- tag="Reasoning"
182
- )
183
-
184
- model2_id = self.db.add_model(
185
- name="Model 2",
186
- hf_model_id="test/model2",
187
- user_id=user_id,
188
- tag="Coding"
189
- )
190
-
191
- # Add a benchmark
192
- benchmark_id = self.db.add_benchmark(
193
- name="Test Benchmark",
194
- dataset_id="test/dataset"
195
- )
196
-
197
- # Add evaluations
198
- eval1_id = self.db.add_evaluation(
199
- model_id=model1_id,
200
- benchmark_id=benchmark_id
201
- )
202
-
203
- eval2_id = self.db.add_evaluation(
204
- model_id=model2_id,
205
- benchmark_id=benchmark_id
206
- )
207
-
208
- # Complete evaluations
209
- self.db.update_evaluation_status(
210
- evaluation_id=eval1_id,
211
- status="completed",
212
- results={"accuracy": 0.9},
213
- score=90.0
214
- )
215
-
216
- self.db.update_evaluation_status(
217
- evaluation_id=eval2_id,
218
- status="completed",
219
- results={"accuracy": 0.8},
220
- score=80.0
221
- )
222
-
223
- # Get leaderboard data
224
- df = self.leaderboard.get_leaderboard_data()
225
- self.assertEqual(len(df), 2)
226
-
227
- # Test filtering by tag
228
- df_reasoning = self.leaderboard.get_leaderboard_data(tag="Reasoning")
229
- self.assertEqual(len(df_reasoning), 1)
230
- self.assertEqual(df_reasoning.iloc[0]["score"], 90.0)
231
-
232
- df_coding = self.leaderboard.get_leaderboard_data(tag="Coding")
233
- self.assertEqual(len(df_coding), 1)
234
- self.assertEqual(df_coding.iloc[0]["score"], 80.0)
235
-
236
- if __name__ == "__main__":
237
- unittest.main()