File size: 2,051 Bytes
63a1401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import unittest
from unittest.mock import patch

import main_backend
import src.backend.manage_requests as manage_requests


class TestMainBackend(unittest.TestCase):

    @patch('src.backend.manage_requests.check_completed_evals')
    @patch('src.backend.manage_requests.get_eval_requests')
    @patch('src.backend.sort_queue.sort_models_by_priority')
    @patch('src.backend.manage_requests.set_eval_request')
    @patch('src.backend.run_eval_suite.run_evaluation')
    def test_run_auto_eval_with_pending_requests(self, mock_run_evaluation, mock_set_eval_request,
                            mock_sort_models_by_priority, mock_get_eval_requests,
                            mock_check_completed_evals):
        mock_sort_models_by_priority.return_value = [manage_requests.EvalRequest(
            model="test_model",
            private=True,
            status="PENDING",
            json_filepath="test_filepath",
            weight_type="test_weight_type",
            precision="test_precision",
            base_model="test_base_model",
            revision="test_revision",
        )]

        main_backend.run_auto_eval()

        # Assertions
        mock_check_completed_evals.assert_called()
        mock_get_eval_requests.assert_called()
        mock_sort_models_by_priority.assert_called()
        mock_set_eval_request.assert_called()
        mock_run_evaluation.assert_called()

    @patch('builtins.print')
    @patch('src.backend.manage_requests.check_completed_evals')
    @patch('src.backend.manage_requests.get_eval_requests')
    def test_run_auto_eval_with_no_pending_requests(self, mock_get_eval_requests,
                                                    mock_check_completed_evals, mock_print):
        mock_get_eval_requests.return_value = []

        main_backend.run_auto_eval()

        # Assertions
        mock_check_completed_evals.assert_called()
        mock_get_eval_requests.assert_called()
        mock_print.assert_any_call("No eval requests found. Exiting.")


if __name__ == "__main__":
    unittest.main()