mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-04-25 08:42:06 +00:00
Command tests: - tests/commands/: test_base_command, test_cmd_command, test_dice_command, test_hello_command, test_help_command, test_magic8_command, test_ping_command, test_roll_command - tests/test_bridge_bot_responses, test_channel_manager_logic, test_checkin_service, test_command_manager, test_command_prefix, test_config_merge, test_config_validation, test_db_manager, test_plugin_loader, test_profanity_filter, test_security_utils, test_service_plugin_loader, test_utils Integration and unit: - tests/integration/: test_path_graph_integration, test_path_resolution - tests/regression/: test_keyword_escapes - tests/unit/: test_mesh_graph, test_mesh_graph_edges, test_mesh_graph_multihop, test_mesh_graph_optimizations, test_mesh_graph_scoring, test_mesh_graph_validation, test_path_command_graph, test_path_command_graph_selection, test_path_command_multibyte Helpers: tests/conftest.py, tests/helpers.py
125 lines
4.2 KiB
Python
125 lines
4.2 KiB
Python
"""Tests for modules.commands.dice_command."""
|
|
|
|
|
|
import pytest
|
|
|
|
from modules.commands.dice_command import DiceCommand
|
|
from tests.conftest import mock_message
|
|
|
|
|
|
class TestParseDiceNotation:
|
|
"""Tests for parse_dice_notation()."""
|
|
|
|
def test_d20(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
sides, count, is_decade = cmd.parse_dice_notation("d20")
|
|
assert sides == 20
|
|
assert count == 1
|
|
assert is_decade is False
|
|
|
|
def test_2d6(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
sides, count, is_decade = cmd.parse_dice_notation("2d6")
|
|
assert sides == 6
|
|
assert count == 2
|
|
assert is_decade is False
|
|
|
|
def test_decade(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
sides, count, is_decade = cmd.parse_dice_notation("decade")
|
|
assert sides == 10
|
|
assert count == 1
|
|
assert is_decade is True
|
|
|
|
def test_direct_number_20(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
sides, count, is_decade = cmd.parse_dice_notation("20")
|
|
assert sides == 20
|
|
assert count == 1
|
|
|
|
def test_invalid_d7(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
sides, count, is_decade = cmd.parse_dice_notation("d7")
|
|
assert sides is None
|
|
assert count is None
|
|
|
|
|
|
class TestParseMixedDice:
|
|
"""Tests for parse_mixed_dice()."""
|
|
|
|
def test_d10_d6(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
result = cmd.parse_mixed_dice("d10 d6")
|
|
assert len(result) == 2
|
|
assert result[0] == (10, 1, False)
|
|
assert result[1] == (6, 1, False)
|
|
|
|
def test_2d6_d20(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
result = cmd.parse_mixed_dice("2d6 d20")
|
|
assert len(result) == 2
|
|
assert result[0] == (6, 2, False)
|
|
assert result[1] == (20, 1, False)
|
|
|
|
|
|
class TestRollDice:
|
|
"""Tests for roll_dice()."""
|
|
|
|
def test_decade_values_in_range(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
for _ in range(20):
|
|
results = cmd.roll_dice(10, 1, is_decade=True)
|
|
assert len(results) == 1
|
|
assert results[0] in (0, 10, 20, 30, 40, 50, 60, 70, 80, 90)
|
|
|
|
def test_standard_dice_range(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
results = cmd.roll_dice(6, 10)
|
|
assert len(results) == 10
|
|
for r in results:
|
|
assert 1 <= r <= 6
|
|
|
|
|
|
class TestFormatDiceResult:
|
|
"""Tests for format_dice_result()."""
|
|
|
|
def test_single_die(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
result = cmd.format_dice_result(6, 1, [4])
|
|
assert "4" in result and "6" in result
|
|
|
|
def test_decade_format(self, command_mock_bot):
|
|
cmd = DiceCommand(command_mock_bot)
|
|
result = cmd.format_dice_result(10, 1, [50], is_decade=True)
|
|
assert "50" in result
|
|
assert "decade" in result.lower()
|
|
|
|
|
|
class TestDiceExecute:
|
|
"""Tests for execute()."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_dice_defaults_to_d6(self, command_mock_bot):
|
|
command_mock_bot.config.add_section("Dice_Command")
|
|
command_mock_bot.config.set("Dice_Command", "enabled", "true")
|
|
cmd = DiceCommand(command_mock_bot)
|
|
msg = mock_message(content="dice", is_dm=True)
|
|
result = await cmd.execute(msg)
|
|
assert result is True
|
|
call_args = command_mock_bot.command_manager.send_response.call_args
|
|
assert call_args is not None
|
|
response = call_args[0][1]
|
|
assert "6" in response or "d6" in response or "🎲" in response
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_dice_invalid_returns_error(self, command_mock_bot):
|
|
command_mock_bot.config.add_section("Dice_Command")
|
|
command_mock_bot.config.set("Dice_Command", "enabled", "true")
|
|
cmd = DiceCommand(command_mock_bot)
|
|
msg = mock_message(content="dice invalid", is_dm=True)
|
|
result = await cmd.execute(msg)
|
|
assert result is True
|
|
call_args = command_mock_bot.command_manager.send_response.call_args
|
|
response = call_args[0][1]
|
|
assert "invalid" in response.lower() or "d4" in response or "d6" in response
|