Refactor all test classes into evennia.utils.test_resources. Update docs.

This commit is contained in:
Griatch 2022-01-21 00:17:24 +01:00
parent 7912351e01
commit bbf45af2dd
28 changed files with 528 additions and 588 deletions

View file

@ -3,7 +3,7 @@ Building menu tests.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . building_menu import BuildingMenu, CmdNoMatch
@ -12,7 +12,7 @@ class Submenu(BuildingMenu):
self.add_choice("title", key="t", attr="key")
class TestBuildingMenu(EvenniaCommandTest):
class TestBuildingMenu(BaseEvenniaCommandTest):
def setUp(self):
super(TestBuildingMenu, self).setUp()
self.menu = BuildingMenu(caller=self.char1, obj=self.room1, title="test")

View file

@ -3,11 +3,11 @@ Test email login.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import email_login
class TestEmailLogin(EvenniaCommandTest):
class TestEmailLogin(BaseEvenniaCommandTest):
def test_connect(self):
self.call(
email_login.CmdUnconnectedConnect(),

View file

@ -7,7 +7,7 @@ from textwrap import dedent
from django.conf import settings
from evennia import ScriptDB
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.objects.objects import ExitCommand
from evennia.utils import ansi, utils
from evennia.utils.create import create_object, create_script
@ -246,7 +246,7 @@ class TestEventHandler(BaseEvenniaTest):
self.assertEqual(self.room1.callbacks.all(), {})
class TestCmdCallback(EvenniaCommandTest):
class TestCmdCallback(BaseEvenniaCommandTest):
"""Test the @callback command."""
@ -425,7 +425,7 @@ class TestCmdCallback(EvenniaCommandTest):
self.assertEqual(callback.valid, True)
class TestDefaultCallbacks(EvenniaCommandTest):
class TestDefaultCallbacks(BaseEvenniaCommandTest):
"""Test the default callbacks."""

View file

@ -3,10 +3,10 @@ Test menu_login
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import menu_login
class TestMenuLogin(EvenniaCommandTest):
class TestMenuLogin(BaseEvenniaCommandTest):
def test_cmdunloggedlook(self):
self.call(menu_login.CmdUnloggedinLook(), "", "======")

View file

@ -3,11 +3,11 @@ Legacy Mux comms tests (extracted from 0.9.5)
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import mux_comms_cmds as comms
class TestLegacyMuxComms(EvenniaCommandTest):
class TestLegacyMuxComms(BaseEvenniaCommandTest):
"""
Test the legacy comms contrib.
"""

View file

@ -3,7 +3,7 @@ Test of the Unixcommand.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from .unixcommand import UnixCommand
@ -30,7 +30,7 @@ class CmdDummy(UnixCommand):
self.msg("{} * {} = {}".format(nb1, nb2, result))
class TestUnixCommand(EvenniaCommandTest):
class TestUnixCommand(BaseEvenniaCommandTest):
def test_success(self):
"""See the command parsing succeed."""
self.call(CmdDummy(), "5 10", "5 * 10 = 50")

View file

@ -5,7 +5,7 @@ Unit tests for the Evscaperoom
import inspect
import pkgutil
from os import path
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia import InterruptCommand
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils import mod_import
@ -15,7 +15,7 @@ from . import objects
from . import utils
class TestEvscaperoomCommands(EvenniaCommandTest):
class TestEvscaperoomCommands(BaseEvenniaCommandTest):
def setUp(self):
super().setUp()
self.room1 = utils.create_evscaperoom_object("evscaperoom.room.EvscapeRoom", key="Testroom")

View file

@ -3,12 +3,12 @@ Test the contrib barter system
"""
from mock import Mock
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from . import barter
class TestBarter(EvenniaCommandTest):
class TestBarter(BaseEvenniaCommandTest):
def setUp(self):
super().setUp()
self.tradeitem1 = create_object(key="TradeItem1", location=self.char1)

View file

@ -3,14 +3,14 @@ Testing clothing contrib
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from evennia.objects.objects import DefaultRoom
from evennia.utils.test_resources import BaseEvenniaTest
from . import clothing
class TestClothingCmd(EvenniaCommandTest):
class TestClothingCmd(BaseEvenniaCommandTest):
def test_clothingcommands(self):
wearer = create_object(clothing.ClothedCharacter, key="Wearer")
friend = create_object(clothing.ClothedCharacter, key="Friend")

View file

@ -6,7 +6,7 @@ Unit tests for the crafting system contrib.
from unittest import mock
from django.test import override_settings
from django.core.exceptions import ObjectDoesNotExist
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.test_resources import BaseEvenniaTestCase
from evennia.utils.create import create_object
from . import crafting, example_recipes
@ -655,7 +655,7 @@ class TestCraftSword(BaseEvenniaTestCase):
@mock.patch("evennia.contrib.game_systems.crafting.crafting._load_recipes", new=mock.MagicMock())
@mock.patch("evennia.contrib.game_systems.crafting.crafting._RECIPE_CLASSES", new={"testrecipe": _MockRecipe})
@override_settings(CRAFT_RECIPE_MODULES=[])
class TestCraftCommand(EvenniaCommandTest):
class TestCraftCommand(BaseEvenniaCommandTest):
"""Test the crafting command"""
def setUp(self):

View file

@ -4,13 +4,13 @@ Test gendersub contrib.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from mock import patch
from . import gendersub
class TestGenderSub(EvenniaCommandTest):
class TestGenderSub(BaseEvenniaCommandTest):
def test_setgender(self):
self.call(gendersub.SetGender(), "male", "Your gender was set to male.")
self.call(gendersub.SetGender(), "ambiguous", "Your gender was set to ambiguous.")

View file

@ -3,11 +3,11 @@ Test mail contrib
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import mail
class TestMail(EvenniaCommandTest):
class TestMail(BaseEvenniaCommandTest):
def test_mail(self):
self.call(mail.CmdMail(), "2", "'2' is not a valid mail id.", caller=self.account)
self.call(mail.CmdMail(), "test", "'test' is not a valid mail id.", caller=self.account)

View file

@ -3,11 +3,11 @@ Test multidescer contrib.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import multidescer
class TestMultidescer(EvenniaCommandTest):
class TestMultidescer(BaseEvenniaCommandTest):
def test_cmdmultidesc(self):
self.call(multidescer.CmdMultiDesc(), "/list", "Stored descs:\ncaller:")
self.call(

View file

@ -9,12 +9,12 @@ import re
import itertools
from mock import Mock
from evennia.utils import search
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from . import puzzles
class TestPuzzles(EvenniaCommandTest):
class TestPuzzles(BaseEvenniaCommandTest):
def setUp(self):
super(TestPuzzles, self).setUp()
self.steel = create_object(self.object_typeclass, key="steel", location=self.char1.location)

View file

@ -4,14 +4,14 @@ Turnbattle tests.
"""
from mock import patch, MagicMock
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.objects.objects import DefaultRoom
from . import tb_basic, tb_equip, tb_range, tb_items, tb_magic
class TestTurnBattleBasicCmd(EvenniaCommandTest):
class TestTurnBattleBasicCmd(BaseEvenniaCommandTest):
# Test basic combat commands
def test_turnbattlecmd(self):
@ -22,7 +22,7 @@ class TestTurnBattleBasicCmd(EvenniaCommandTest):
self.call(tb_basic.CmdRest(), "", "Char rests to recover HP.")
class TestTurnBattleEquipCmd(EvenniaCommandTest):
class TestTurnBattleEquipCmd(BaseEvenniaCommandTest):
def setUp(self):
super(TestTurnBattleEquipCmd, self).setUp()
self.testweapon = create_object(tb_equip.TBEWeapon, key="test weapon")
@ -45,7 +45,7 @@ class TestTurnBattleEquipCmd(EvenniaCommandTest):
self.call(tb_equip.CmdRest(), "", "Char rests to recover HP.")
class TestTurnBattleRangeCmd(EvenniaCommandTest):
class TestTurnBattleRangeCmd(BaseEvenniaCommandTest):
# Test range commands
def test_turnbattlerangecmd(self):
# Start with range module specific commands.
@ -61,7 +61,7 @@ class TestTurnBattleRangeCmd(EvenniaCommandTest):
self.call(tb_range.CmdRest(), "", "Char rests to recover HP.")
class TestTurnBattleItemsCmd(EvenniaCommandTest):
class TestTurnBattleItemsCmd(BaseEvenniaCommandTest):
def setUp(self):
super(TestTurnBattleItemsCmd, self).setUp()
self.testitem = create_object(key="test item")
@ -78,7 +78,7 @@ class TestTurnBattleItemsCmd(EvenniaCommandTest):
self.call(tb_items.CmdRest(), "", "Char rests to recover HP.")
class TestTurnBattleMagicCmd(EvenniaCommandTest):
class TestTurnBattleMagicCmd(BaseEvenniaCommandTest):
# Test magic commands
def test_turnbattlemagiccmd(self):

View file

@ -6,7 +6,7 @@ Testing of ExtendedRoom contrib
import datetime
from mock import patch, Mock
from django.conf import settings
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.objects.objects import DefaultRoom
from . import extended_room
@ -24,7 +24,7 @@ class ForceUTCDatetime(datetime.datetime):
@patch("evennia.contrib.grid.extended_room.extended_room.datetime.datetime", ForceUTCDatetime)
# mock gametime to return April 9, 2064, at 21:06 (spring evening)
@patch("evennia.utils.gametime.gametime", new=Mock(return_value=2975000766))
class TestExtendedRoom(EvenniaCommandTest):
class TestExtendedRoom(BaseEvenniaCommandTest):
room_typeclass = extended_room.ExtendedRoom
DETAIL_DESC = "A test detail."
SPRING_DESC = "A spring description."

View file

@ -3,7 +3,7 @@ Test map builder.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import mapbuilder
# -*- coding: utf-8 -*-
@ -187,7 +187,7 @@ EXAMPLE2_LEGEND = {
}
class TestMapBuilder(EvenniaCommandTest):
class TestMapBuilder(BaseEvenniaCommandTest):
def test_cmdmapbuilder(self):
self.call(
mapbuilder.CmdMapBuilder(),

View file

@ -4,11 +4,11 @@ Tests of simpledoor.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from . import simpledoor
class TestSimpleDoor(EvenniaCommandTest):
class TestSimpleDoor(BaseEvenniaCommandTest):
def test_cmdopen(self):
self.call(
simpledoor.CmdOpen(),

View file

@ -4,7 +4,7 @@ Slow exit tests.
"""
from mock import Mock, patch
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from . import slow_exit
@ -16,7 +16,7 @@ def _cancellable_mockdelay(time, callback, *args, **kwargs):
return Mock()
class TestSlowExit(EvenniaCommandTest):
class TestSlowExit(BaseEvenniaCommandTest):
@patch("evennia.utils.delay", _cancellable_mockdelay)
def test_exit(self):
exi = create_object(

View file

@ -3,13 +3,13 @@ Testing of TestDice.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from mock import patch
from . import dice
@patch("evennia.contrib.rpg.dice.dice.randint", return_value=5)
class TestDice(EvenniaCommandTest):
class TestDice(BaseEvenniaCommandTest):
def test_roll_dice(self, mocked_randint):
self.assertEqual(dice.roll_dice(6, 6, modifier=("+", 4)), mocked_randint() * 6 + 4)
self.assertEqual(dice.roll_dice(6, 6, conditional=("<", 35)), True)

View file

@ -4,7 +4,7 @@ Tests for RP system
"""
import time
from anything import Anything
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia import create_object
@ -278,7 +278,7 @@ class TestRPSystem(BaseEvenniaTest):
self.assertEqual(result, (Anything, self.speaker, self.speaker.key))
class TestRPSystemCommands(EvenniaCommandTest):
class TestRPSystemCommands(BaseEvenniaCommandTest):
def setUp(self):
super().setUp()
self.char1.swap_typeclass(rpsystem.ContribRPCharacter)

View file

@ -2,12 +2,12 @@
Tutorial - talking NPC tests.
"""
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from . import talking_npc
class TestTalkingNPC(EvenniaCommandTest):
class TestTalkingNPC(BaseEvenniaCommandTest):
def test_talkingnpc(self):
npc = create_object(talking_npc.TalkingNPC, key="npctalker", location=self.room1)
self.call(talking_npc.CmdTalk(), "", "(You walk up and talk to Char.)")

View file

@ -6,7 +6,7 @@ Test tutorial_world/mob
from mock import patch
from twisted.trial.unittest import TestCase as TwistedTestCase
from twisted.internet.base import DelayedCall
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.commands.default.tests import BaseEvenniaCommandTest
from evennia.utils.create import create_object
from evennia.utils.test_resources import BaseEvenniaTest, mockdelay, mockdeferLater
from . import mob, objects as tutobjects, rooms as tutrooms
@ -30,7 +30,7 @@ class TestTutorialWorldMob(BaseEvenniaTest):
DelayedCall.debug = True
class TestTutorialWorldObjects(TwistedTestCase, EvenniaCommandTest):
class TestTutorialWorldObjects(TwistedTestCase, BaseEvenniaCommandTest):
def test_tutorialobj(self):
obj1 = create_object(tutobjects.TutorialObject, key="tutobj")
obj1.reset()
@ -129,7 +129,7 @@ class TestTutorialWorldObjects(TwistedTestCase, EvenniaCommandTest):
self.call(tutobjects.CmdGetWeapon(), "", "You find Rusty sword.", obj=rack)
class TestTutorialWorldRooms(EvenniaCommandTest):
class TestTutorialWorldRooms(BaseEvenniaCommandTest):
def test_cmdtutorial(self):
room = create_object(tutrooms.TutorialRoom, key="tutroom")
self.char1.location = room