HumanLikeness / tests /test_main_backend.py
Xufeng Duan
Upload 66 files
63a1401
raw
history blame
2.05 kB
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()