diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2b804b..67e86e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,6 +38,11 @@ jobs: run: | pytest tests/ -v --cov=. --cov-report=xml --cov-report=term-missing + - name: Generate .coverage file + if: matrix.python-version == '3.11' + run: | + coverage run -m pytest tests/ + - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -45,6 +50,7 @@ jobs: flags: unittests name: codecov-umbrella fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} - name: Generate coverage badge if: matrix.python-version == '3.11' @@ -94,4 +100,3 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # Exit-zero treats all errors as warnings flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - continue-on-error: true diff --git a/tests/README.md b/tests/README.md index 0a6177a..7ea701d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -105,30 +105,25 @@ tests/ ## Test Statistics -- **Total Tests**: 173 (+57 from initial 116) +- **Total Tests**: 173 tests (up from 116) - **Passing**: 173 (100%) - **Code Coverage**: 100% (up from 97%) - **Test Execution Time**: ~1.1 seconds ## Test Breakdown -- **Unit Tests**: 156 tests - - MentionDetector: 73 tests (including 45 parameterized) +- **Unit Tests**: 163 tests + - MentionDetector: 84 tests (including 45 parameterized) - Logger: 16 tests - ConversationMemory: 28 tests - PerplexityProvider: 22 tests - - Config: 27 tests + - Config: 29 tests -- **Integration Tests**: 9 tests +- **Integration Tests**: 10 tests - Full workflow testing - Component interaction - Error recovery scenarios -- **Parameterized Tests**: 45 tests - - Mention detection patterns - - Greeting detection - - Content extraction - ## Improvements from Initial Version ✅ **100% code coverage** (was 97%) diff --git a/tests/test_integration.py b/tests/test_integration.py index 61ec5bc..1ad9087 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -3,8 +3,7 @@ Integration tests for Eugen Bot Tests the full workflow and component integration """ import pytest -import asyncio -from unittest.mock import Mock, AsyncMock, patch, MagicMock +from unittest.mock import Mock, AsyncMock, patch from config import Config from memory import ConversationMemory from ai_provider import PerplexityProvider @@ -71,7 +70,6 @@ class TestFullWorkflow: """Test that conversation context is preserved across messages""" config = Config(env_file=str(mock_env_file), config_file=str(temp_dir / "config.json")) memory = ConversationMemory(data_dir=str(temp_dir / "conversations")) - ai = PerplexityProvider(api_key=config.perplexity_key) username = "testuser" @@ -175,7 +173,6 @@ class TestFullWorkflow: @pytest.mark.asyncio async def test_memory_limit_enforcement_in_workflow(self, temp_dir, mock_env_file): """Test that memory limits are enforced during conversation""" - config = Config(env_file=str(mock_env_file), config_file=str(temp_dir / "config.json")) memory = ConversationMemory( data_dir=str(temp_dir / "conversations"), max_messages=10 @@ -266,11 +263,12 @@ class TestComponentInteraction: # Create complete config complete_env = temp_dir / "complete.env" - complete_env.write_text("""TWITCH_OAUTH_TOKEN=oauth:test123 -TWITCH_CHANNEL=#testchannel -TWITCH_BOT_NICKNAME=TestBot -PERPLEXITY_API_KEY=pplx-test123 -""") + complete_env.write_text( + "TWITCH_OAUTH_TOKEN=oauth:test123\n" + "TWITCH_CHANNEL=#testchannel\n" + "TWITCH_BOT_NICKNAME=TestBot\n" + "PERPLEXITY_API_KEY=pplx-test123\n" + ) config2 = Config(env_file=str(complete_env), config_file=str(temp_dir / "config.json")) diff --git a/tests/test_utils.py b/tests/test_utils.py index c28cc40..d0a9fd9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,6 @@ Tests for utility classes: MentionDetector and Logger """ import pytest -from pathlib import Path import logging from utils import MentionDetector, Logger @@ -20,7 +19,7 @@ MENTION_TEST_CASES = [ ("Eugen. listen", "Eugen", True, "period format"), ("Hey Eugen how are you", "Eugen", True, "mention in middle"), ("Is Eugen online?", "Eugen", True, "mention as word"), - ("Eugene is different", "Eugen", False, "partial match should fail"), + ("Eugene is different", "Eugen", False, "name as substring of longer word should fail"), ("Eugenics is a topic", "Eugen", False, "false positive check"), ("Regular message", "Eugen", False, "no mention"), ("@kenearosmd hi", "kenearosmd", True, "long name at-mention"), @@ -436,18 +435,18 @@ class TestLogger: def test_logger_reuses_existing_handlers(self, temp_dir): """Test that logger doesn't create duplicate handlers""" - import logging - log_dir = temp_dir / "logs" - # Create first logger - logger1 = Logger(log_dir=str(log_dir), debug_mode=True) - handler_count_1 = len(logger1.main_logger.handlers) + # Create first logger instance to set up handlers + Logger(log_dir=str(log_dir), debug_mode=True) + main_logger_1 = logging.getLogger("eugen_main") + handler_count_1 = len(main_logger_1.handlers) - # Create second logger with same settings - should reuse handlers - logger2 = Logger(log_dir=str(log_dir), debug_mode=True) - handler_count_2 = len(logger2.main_logger.handlers) + # Create second logger with same settings - should not add handlers + Logger(log_dir=str(log_dir), debug_mode=True) + main_logger_2 = logging.getLogger("eugen_main") + handler_count_2 = len(main_logger_2.handlers) - # Should have same number of handlers (reused, not duplicated) + # Underlying logger should have the same number of handlers (reused, not duplicated) assert handler_count_1 == handler_count_2 assert handler_count_1 > 0 # But should have at least one handler