mud/tests/test_reload.py
Jared Miller 9c480f8d47
Remove duplicate mock_writer/mock_reader fixtures
Removed identical local copies from 45 test files. These fixtures
are already defined in conftest.py.
2026-02-16 15:29:21 -05:00

99 lines
2.9 KiB
Python

"""Tests for the reload command."""
from pathlib import Path
import pytest
from mudlib.combat import commands as combat_commands
from mudlib.combat.moves import load_moves
from mudlib.commands.reload import cmd_reload
from mudlib.player import Player, players
@pytest.fixture(autouse=True)
def clear_state():
"""Clear players before and after each test."""
players.clear()
yield
players.clear()
@pytest.fixture
def player(mock_reader, mock_writer):
"""Create a test player."""
p = Player(name="Tester", x=0, y=0, reader=mock_reader, writer=mock_writer)
players[p.name] = p
return p
@pytest.fixture
def moves():
"""Load combat moves from content directory."""
content_dir = Path(__file__).parent.parent / "content" / "combat"
return load_moves(content_dir)
@pytest.fixture(autouse=True)
def inject_moves(moves):
"""Inject loaded moves into combat commands module."""
combat_commands.combat_moves = moves
# Set the combat content dir so reload can find files
combat_commands.combat_content_dir = (
Path(__file__).parent.parent / "content" / "combat"
)
yield
combat_commands.combat_moves = {}
combat_commands.combat_content_dir = None
@pytest.mark.asyncio
async def test_reload_no_args(player, mock_writer):
"""Test reload command with no arguments shows usage."""
await cmd_reload(player, "")
assert mock_writer.write.called
written_text = mock_writer.write.call_args[0][0]
assert "Usage: reload <name>" in written_text
@pytest.mark.asyncio
async def test_reload_nonexistent(player, mock_writer):
"""Test reload command with nonexistent content."""
await cmd_reload(player, "nonexistent_file_xyz")
assert mock_writer.write.called
written_text = mock_writer.write.call_args[0][0]
assert "No content found with name: nonexistent_file_xyz" in written_text
@pytest.mark.asyncio
async def test_reload_combat_move(player, mock_writer):
"""Test reloading a combat move TOML."""
# Reload roundhouse (simple move)
await cmd_reload(player, "roundhouse")
# Verify success message
assert mock_writer.write.called
written_text = mock_writer.write.call_args[0][0]
assert "Reloaded combat move: roundhouse" in written_text
# Verify it's in the combat_moves dict
from mudlib.combat.commands import combat_moves
assert "roundhouse" in combat_moves
@pytest.mark.asyncio
async def test_reload_variant_move(player, mock_writer):
"""Test reloading a variant combat move (e.g. punch)."""
# Reload punch
await cmd_reload(player, "punch")
# Verify success message
assert mock_writer.write.called
written_text = mock_writer.write.call_args[0][0]
assert "Reloaded combat move: punch" in written_text
# Verify variants are in combat_moves
from mudlib.combat.commands import combat_moves
assert "punch left" in combat_moves
assert "punch right" in combat_moves