MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/openevolve / TestAPIFunctions

Class TestAPIFunctions

tests/test_api.py:22–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22class TestAPIFunctions(unittest.TestCase):
23
24 def setUp(self):
25 self.temp_dir = tempfile.mkdtemp()
26
27 def tearDown(self):
28 import shutil
29 shutil.rmtree(self.temp_dir, ignore_errors=True)
30
31 def test_evolution_result_class(self):
32 """Test EvolutionResult dataclass"""
33 result = EvolutionResult(
34 best_program=None,
35 best_score=0.85,
36 best_code="def test(): pass",
37 metrics={"score": 0.85, "runtime": 1.2},
38 output_dir="/tmp/test"
39 )
40
41 self.assertEqual(result.best_score, 0.85)
42 self.assertEqual(result.best_code, "def test(): pass")
43 self.assertIn("0.8500", str(result))
44
45 def test_prepare_program_from_file(self):
46 """Test _prepare_program with existing file"""
47 program_file = os.path.join(self.temp_dir, "test_program.py")
48 with open(program_file, 'w') as f:
49 f.write("def test(): return 42")
50
51 temp_files = []
52 result = _prepare_program(program_file, self.temp_dir, temp_files)
53
54 self.assertEqual(result, program_file)
55 self.assertEqual(len(temp_files), 0)
56
57 def test_prepare_program_from_string(self):
58 """Test _prepare_program with code string"""
59 code = "def test(): return 42"
60 temp_files = []
61
62 result = _prepare_program(code, self.temp_dir, temp_files)
63
64 self.assertTrue(os.path.exists(result))
65 self.assertEqual(len(temp_files), 1)
66
67 with open(result, 'r') as f:
68 content = f.read()
69 self.assertIn("EVOLVE-BLOCK-START", content)
70 self.assertIn("EVOLVE-BLOCK-END", content)
71 self.assertIn("def test(): return 42", content)
72
73 def test_prepare_program_from_list(self):
74 """Test _prepare_program with list of lines"""
75 lines = ["def test():", " return 42"]
76 temp_files = []
77
78 result = _prepare_program(lines, self.temp_dir, temp_files)
79

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected