diff --git a/README.md b/README.md index 6d73e1c..e7274c2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ An open-source framework for building general AI agents +[![codecov](https://codecov.io/gh/LearnHD/OpenManus/branch/main/graph/badge.svg)](https://codecov.io/gh/LearnHD/OpenManus) + ## Features - Modular architecture for easy extension @@ -9,6 +11,7 @@ An open-source framework for building general AI agents - FastAPI backend with React frontend - Comprehensive test suite - CI/CD pipeline with GitHub Actions +- Code coverage tracking with Codecov ## Installation diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..3ea896d --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,48 @@ +import pytest +from unittest.mock import patch, MagicMock +import sys +import os +import signal +from main import start_backend, start_frontend, stop_servers, cleanup, signal_handler + +def test_start_backend(): + with patch('subprocess.Popen') as mock_popen: + mock_process = MagicMock() + mock_popen.return_value = mock_process + + assert start_backend() == True + mock_popen.assert_called_once() + +def test_start_frontend(): + with patch('subprocess.Popen') as mock_popen, \ + patch('os.chdir') as mock_chdir: + mock_process = MagicMock() + mock_popen.return_value = mock_process + + assert start_frontend() == True + mock_popen.assert_called_once() + assert mock_chdir.call_count == 2 + +def test_stop_servers(): + with patch('main.cleanup') as mock_cleanup: + assert stop_servers() == True + mock_cleanup.assert_called_once() + +def test_cleanup(): + with patch('main.backend_process') as mock_backend, \ + patch('main.frontend_process') as mock_frontend: + mock_backend.terminate = MagicMock() + mock_frontend.terminate = MagicMock() + + cleanup() + + mock_backend.terminate.assert_called_once() + mock_frontend.terminate.assert_called_once() + +def test_signal_handler(): + with patch('main.cleanup') as mock_cleanup, \ + patch('sys.exit') as mock_exit: + signal_handler(signal.SIGTERM, None) + + mock_cleanup.assert_called_once() + mock_exit.assert_called_once_with(0) \ No newline at end of file