Add test
This commit is contained in:
37
misc_test.py
Normal file
37
misc_test.py
Normal file
@ -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
|
@ -12,7 +12,11 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = ["pytest-asyncio", "pytest", "ruff"]
|
dev = [
|
||||||
|
"pytest-asyncio",
|
||||||
|
"pytest",
|
||||||
|
"ruff",
|
||||||
|
]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
# https://docs.astral.sh/ruff/linter/
|
# https://docs.astral.sh/ruff/linter/
|
||||||
@ -54,18 +58,18 @@ lint.pydocstyle.convention = "google"
|
|||||||
# Add "from __future__ import annotations" to all files
|
# Add "from __future__ import annotations" to all files
|
||||||
lint.isort.required-imports = ["from __future__ import annotations"]
|
lint.isort.required-imports = ["from __future__ import annotations"]
|
||||||
|
|
||||||
|
lint.pycodestyle.ignore-overlong-task-comments = true
|
||||||
|
|
||||||
# Default is 88 characters
|
# Default is 88 characters
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
lint.pycodestyle.ignore-overlong-task-comments = true
|
|
||||||
|
|
||||||
[tool.ruff.format]
|
[tool.ruff.format]
|
||||||
# https://docs.astral.sh/ruff/formatter/
|
# https://docs.astral.sh/ruff/formatter/
|
||||||
docstring-code-format = true
|
docstring-code-format = true
|
||||||
docstring-code-line-length = 20
|
docstring-code-line-length = 20
|
||||||
|
|
||||||
[tool.ruff.lint.per-file-ignores]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
"**/tests/**" = [
|
"**/*_test.py" = [
|
||||||
"ARG", # Unused function args -> fixtures nevertheless are functionally relevant...
|
"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()
|
"FBT", # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize()
|
||||||
"PLR2004", # Magic value used in comparison, ...
|
"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_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
|
||||||
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
# Only check /tests/ directory for tests.
|
# Only test files with the following suffixes.
|
||||||
testpaths = ["tests"]
|
python_files = "test_*.py *_test.py *_tests.py"
|
||||||
|
Reference in New Issue
Block a user