22Test suite for artifacts functionality
33"""
44
5+ import asyncio
56import os
67import tempfile
78import unittest
@@ -135,6 +136,13 @@ class TestEvaluatorArtifacts(unittest.TestCase):
135136 """Test artifact handling in the evaluator"""
136137
137138 def setUp (self ):
139+ # Set up event loop for async operations in tests
140+ try :
141+ self .loop = asyncio .get_event_loop ()
142+ except RuntimeError :
143+ self .loop = asyncio .new_event_loop ()
144+ asyncio .set_event_loop (self .loop )
145+
138146 # Create a mock evaluation file
139147 self .temp_eval_file = tempfile .NamedTemporaryFile (mode = "w" , suffix = ".py" , delete = False )
140148 self .temp_eval_file .write (
@@ -150,10 +158,18 @@ def evaluate(program_path):
150158
151159 def tearDown (self ):
152160 os .unlink (self .temp_eval_file .name )
161+ # Clean up event loop if we created one
162+ if hasattr (self , "loop" ) and self .loop and not self .loop .is_closed ():
163+ # Cancel any pending tasks
164+ pending = asyncio .all_tasks (self .loop )
165+ for task in pending :
166+ task .cancel ()
167+ # Run the loop briefly to let cancellations process
168+ if pending :
169+ self .loop .run_until_complete (asyncio .gather (* pending , return_exceptions = True ))
153170
154171 def test_evaluate_program_backward_compatibility (self ):
155172 """Test that old evaluators still work unchanged"""
156- import asyncio
157173
158174 async def run_test ():
159175 result = await self .evaluator .evaluate_program ("print('test')" , "test_id" )
@@ -206,7 +222,7 @@ def test_render_artifacts_all_items(self):
206222 """Test that all artifacts are included using .items() without prioritization"""
207223 artifacts = {
208224 "stderr" : "error message" ,
209- "stdout" : "output message" ,
225+ "stdout" : "output message" ,
210226 "traceback" : "stack trace" ,
211227 "other" : "other data" ,
212228 }
@@ -216,7 +232,7 @@ def test_render_artifacts_all_items(self):
216232 # All artifacts should be present (no prioritization)
217233 for key in artifacts .keys ():
218234 self .assertIn (key , rendered )
219-
235+
220236 # Check that all content is included
221237 for value in artifacts .values ():
222238 self .assertIn (value , rendered )
0 commit comments