From d0a59b7bbba4a60ec7204fd3f4ddd2b0d21e1d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sun, 22 Dec 2024 06:04:19 +0100 Subject: [PATCH] Add test --- misc_test.py | 37 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 16 ++++++++++------ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 misc_test.py diff --git a/misc_test.py b/misc_test.py new file mode 100644 index 0000000..14feb0a --- /dev/null +++ b/misc_test.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from unittest.mock import Mock + +import pytest + +from misc import get_trigger_keywords + + +@pytest.fixture +def mock_bot() -> Mock: + """Create a mock bot instance. + + Returns: + A mock bot instance. + """ + return Mock() + + +def test_get_trigger_keywords_with_bot_user(mock_bot: Mock) -> None: + """Test getting trigger keywords with a bot user.""" + mock_bot.get_me.return_value.id = 123456789 + expected_keywords: list[str] = ["lovibot", "<@123456789>"] + + result: list[str] = get_trigger_keywords(mock_bot) + + assert result == expected_keywords + + +def test_get_trigger_keywords_without_bot_user(mock_bot: Mock) -> None: + """Test getting trigger keywords without a bot user.""" + mock_bot.get_me.return_value = None + expected_keywords: list[str] = ["lovibot", ""] + + result: list[str] = get_trigger_keywords(mock_bot) + + assert result == expected_keywords diff --git a/pyproject.toml b/pyproject.toml index 1eba91a..591d5dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,11 @@ dependencies = [ ] [dependency-groups] -dev = ["pytest-asyncio", "pytest", "ruff"] +dev = [ + "pytest-asyncio", + "pytest", + "ruff", +] [tool.ruff] # https://docs.astral.sh/ruff/linter/ @@ -54,18 +58,18 @@ lint.pydocstyle.convention = "google" # Add "from __future__ import annotations" to all files lint.isort.required-imports = ["from __future__ import annotations"] +lint.pycodestyle.ignore-overlong-task-comments = true + # Default is 88 characters line-length = 120 -lint.pycodestyle.ignore-overlong-task-comments = true - [tool.ruff.format] # https://docs.astral.sh/ruff/formatter/ docstring-code-format = true docstring-code-line-length = 20 [tool.ruff.lint.per-file-ignores] -"**/tests/**" = [ +"**/*_test.py" = [ "ARG", # Unused function args -> fixtures nevertheless are functionally relevant... "FBT", # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize() "PLR2004", # Magic value used in comparison, ... @@ -81,5 +85,5 @@ log_cli_level = "INFO" log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)" log_cli_date_format = "%Y-%m-%d %H:%M:%S" -# Only check /tests/ directory for tests. -testpaths = ["tests"] +# Only test files with the following suffixes. +python_files = "test_*.py *_test.py *_tests.py"