Clean up all test suites

This commit is contained in:
Griatch 2022-01-07 16:12:12 +01:00
parent 0f3b96886c
commit 19f920b6d4
41 changed files with 237 additions and 169 deletions

View file

@ -114,9 +114,10 @@ definition of the `EvenniaTest` class in
```python
# in a test module
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
class TestObject(EvenniaTest):
class TestObject(BaseEvenniaTest):
def test_object_search(self):
# char1 and char2 are both created in room1
self.assertEqual(self.char1.search(self.char2.key), self.char2)
@ -173,26 +174,26 @@ testing#503435) is currently untested! Please report your findings.
from django.conf import settings
import django
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
OLD_DEFAULT_SETTINGS = settings.INSTALLED_APPS
DEFAULT_SETTINGS = dict(
INSTALLED_APPS=(
'contrib.mycontrib.tests',
),
),
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3"
}
},
}
},
SILENCED_SYSTEM_CHECKS=["1_7.W001"],
)
)
class TestMyModel(EvenniaTest):
class TestMyModel(BaseEvenniaTest):
def setUp(self):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
settings.configure(**DEFAULT_SETTINGS)
django.setup()
from django.core.management import call_command
@ -212,7 +213,7 @@ class TestMyModel(EvenniaTest):
# test cases below ...
def test_case(self):
# test case here
# test case here
```
### A note on adding new tests

View file

@ -7,7 +7,7 @@ from unittest import TestCase
from django.test import override_settings
from evennia.accounts.accounts import AccountSessionHandler
from evennia.accounts.accounts import DefaultAccount, DefaultGuest
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils import create
from evennia.utils.utils import uses_database
@ -64,7 +64,7 @@ class TestAccountSessionHandler(TestCase):
@override_settings(GUEST_ENABLED=True, GUEST_LIST=["bruce_wayne"])
class TestDefaultGuest(EvenniaTest):
class TestDefaultGuest(BaseEvenniaTest):
"Check DefaultGuest class"
ip = "212.216.134.22"
@ -114,7 +114,7 @@ class TestDefaultGuest(EvenniaTest):
self.char1.delete.assert_called()
class TestDefaultAccountAuth(EvenniaTest):
class TestDefaultAccountAuth(BaseEvenniaTest):
def setUp(self):
super(TestDefaultAccountAuth, self).setUp()
@ -358,7 +358,7 @@ class TestDefaultAccount(TestCase):
self.assertIsNone(obj.at_post_puppet.call_args)
class TestAccountPuppetDeletion(EvenniaTest):
class TestAccountPuppetDeletion(BaseEvenniaTest):
@override_settings(MULTISESSION_MODE=2)
def test_puppet_deletion(self):
# Check for existing chars
@ -379,7 +379,7 @@ class TestAccountPuppetDeletion(EvenniaTest):
)
class TestDefaultAccountEv(EvenniaTest):
class TestDefaultAccountEv(BaseEvenniaTest):
"""
Testing using the EvenniaTest parent

View file

@ -23,7 +23,7 @@ from unittest.mock import patch, Mock, MagicMock
from evennia import DefaultRoom, DefaultExit, ObjectDB
from evennia.commands.default.cmdset_character import CharacterCmdSet
from evennia.utils.test_resources import EvenniaTest, LocalEvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTest
from evennia.commands.default import (
help as help_module,
general,
@ -309,14 +309,24 @@ class CommandTestMixin:
return returned_msgs
class EvenniaCommandTest(EvenniaTest, CommandTestMixin):
@patch("evennia.commands.account.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.admin.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.batchprocess.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.building.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.comms.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.general.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.help.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.syscommands.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.system.COMMAND_DEFAULT_CLASS", MuxCommand)
@patch("evennia.commands.unloggedin.COMMAND_DEFAULT_CLASS", MuxCommand)
class EvenniaCommandTest(BaseEvenniaTest, CommandTestMixin):
"""
Commands only using the default settings.
"""
class LocalEvenniaCommandTest(LocalEvenniaTest, CommandTestMixin):
class CommandTest(EvenniaTest, CommandTestMixin):
"""
Parent class to inherit from - makes tests use your own
classes and settings in mygame.
@ -1959,14 +1969,17 @@ class TestBuilding(EvenniaCommandTest):
import evennia.commands.default.comms as cmd_comms # noqa
from evennia.utils.create import create_channel # noqa
from evennia.comms.comms import DefaultChannel # noqa
@patch("evennia.commands.default.comms.CHANNEL_DEFAULT_TYPECLASS", DefaultChannel)
class TestCommsChannel(EvenniaCommandTest):
"""
Test the central `channel` command.
"""
def setUp(self):
super(EvenniaCommandTest, self).setUp()
super().setUp()
self.channel = create_channel(
key="testchannel",
desc="A test channel")
@ -2039,6 +2052,7 @@ class TestCommsChannel(EvenniaCommandTest):
def test_channel__alias__unalias(self):
"""Add and then remove a channel alias"""
# add alias
self.call(
self.cmdchannel(),

View file

@ -4,7 +4,7 @@ Unit testing for the Command system itself.
"""
from django.test import override_settings
from evennia.utils.test_resources import EvenniaTest, TestCase
from evennia.utils.test_resources import BaseEvenniaTest, TestCase
from evennia.commands.cmdset import CmdSet
from evennia.commands.command import Command
from evennia.commands import cmdparser
@ -989,7 +989,7 @@ def _mockdelay(time, func, *args, **kwargs):
return func(*args, **kwargs)
class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
class TestGetAndMergeCmdSets(TwistedTestCase, BaseEvenniaTest):
"Test the cmdhandler.get_and_merge_cmdsets function."
def setUp(self):
@ -1176,7 +1176,7 @@ class TestCmdParser(TestCase):
)
class TestCmdSetNesting(EvenniaTest):
class TestCmdSetNesting(BaseEvenniaTest):
"""
Test 'nesting' of cmdsets by adding
"""

View file

@ -1,9 +1,9 @@
from evennia import DefaultChannel
from evennia.utils.create import create_message
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
class ObjectCreationTest(EvenniaTest):
class ObjectCreationTest(BaseEvenniaTest):
def test_channel_create(self):
description = "A place to talk about coffee."
@ -18,7 +18,7 @@ class ObjectCreationTest(EvenniaTest):
self.assertEqual(str(msg), "peewee herman->: heh-heh!")
class ChannelWholistTests(EvenniaTest):
class ChannelWholistTests(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.default_channel, _ = DefaultChannel.create("coffeetalk", description="A place to talk about coffee.")

View file

@ -4,11 +4,11 @@ Test Color markup.
"""
import re
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import color_markups
class TestColorMarkup(EvenniaTest):
class TestColorMarkup(BaseEvenniaTest):
"""
Note: Normally this would be tested by importing the ansi parser and run
the mappings through it. This is not possible since the ansi module creates

View file

@ -5,7 +5,7 @@ Testing custom game time
# Testing custom_gametime
from mock import Mock, patch
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from .. import custom_gametime
@ -14,7 +14,7 @@ def _testcallback():
@patch("evennia.utils.gametime.gametime", new=Mock(return_value=2975000898.46))
class TestCustomGameTime(EvenniaTest):
class TestCustomGameTime(BaseEvenniaTest):
def tearDown(self):
if hasattr(self, "timescript"):
self.timescript.stop()

View file

@ -11,7 +11,7 @@ from evennia.commands.default.tests import EvenniaCommandTest
from evennia.objects.objects import ExitCommand
from evennia.utils import ansi, utils
from evennia.utils.create import create_object, create_script
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from .commands import CmdCallback
from .callbackhandler import CallbackHandler
@ -22,7 +22,7 @@ settings.EVENTS_CALENDAR = "standard"
OLD_EVENTS = {}
class TestEventHandler(EvenniaTest):
class TestEventHandler(BaseEvenniaTest):
"""
Test cases of the event handler to add, edit or delete events.

View file

@ -7,7 +7,7 @@ import pkgutil
from os import path
from evennia.commands.default.tests import EvenniaCommandTest
from evennia import InterruptCommand
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils import mod_import
from . import commands
from . import state as basestate
@ -191,7 +191,7 @@ class TestEvscaperoomCommands(EvenniaCommandTest):
self.call(commands.CmdFocusInteraction(), "", "Hm?")
class TestUtils(EvenniaTest):
class TestUtils(BaseEvenniaTest):
def test_overwrite(self):
room = utils.create_evscaperoom_object("evscaperoom.room.EvscapeRoom", key="Testroom")
obj1 = utils.create_evscaperoom_object(
@ -227,7 +227,7 @@ class TestUtils(EvenniaTest):
self.assertEqual(utils.parse_for_things(string, 2), "Looking at |y[book]|n and |y[key]|n.")
class TestEvScapeRoom(EvenniaTest):
class TestEvScapeRoom(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.room = utils.create_evscaperoom_object(
@ -256,7 +256,7 @@ class TestEvScapeRoom(EvenniaTest):
self.assertEqual(self.char1.tags.get(category=self.roomtag), None)
class TestStates(EvenniaTest):
class TestStates(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.room = utils.create_evscaperoom_object(

View file

@ -5,3 +5,4 @@ Clothing contrib - Tim Ashley Jenkins 2017
from .clothing import ClothedCharacter # noqa
from .clothing import ClothedCharacterCmdSet # noqa
from .clothing import ContribClothing # noqa

View file

@ -67,7 +67,7 @@ game's commands/default_cmdsets.py:
From here, you can use the default builder commands to create clothes
with which to test the system:
@create a pretty shirt : evennia.contrib.game_systems.clothing.Clothing
@create a pretty shirt : evennia.contrib.game_systems.clothing.ContribClothing
@set shirt/clothing_type = 'top'
wear shirt
@ -84,7 +84,7 @@ from evennia.utils import evtable
# Maximum character length of 'wear style' strings, or None for unlimited.
WEARSTYLE_MAXLENGTH = 50
# The rest of these options have to do with clothing types. Clothing types are optional,
# The rest of these options have to do with clothing types. ContribClothing types are optional,
# but can be used to give better control over how different items of clothing behave. You
# can freely add, remove, or change clothing types to suit the needs of your game and use
# the options below to affect their behavior.
@ -228,7 +228,7 @@ def single_type_count(clothes_list, type):
return type_count
class Clothing(DefaultObject):
class ContribClothing(DefaultObject):
def wear(self, wearer, wearstyle, quiet=False):
"""
Sets clothes to 'worn' and optionally echoes to the room.
@ -389,7 +389,7 @@ class CmdWear(MuxCommand):
if not clothing:
self.caller.msg("Thing to wear must be in your inventory.")
return
if not clothing.is_typeclass("evennia.contrib.game_systems.clothing.Clothing", exact=False):
if not clothing.is_typeclass(ContribClothing, exact=False):
self.caller.msg("That's not clothes!")
return
@ -492,10 +492,10 @@ class CmdCover(MuxCommand):
cover_with = self.caller.search(self.arglist[1], candidates=self.caller.contents)
if not to_cover or not cover_with:
return
if not to_cover.is_typeclass("evennia.contrib.game_systems.clothing.Clothing", exact=False):
if not to_cover.is_typeclass(ContribClothing, exact=False):
self.caller.msg("%s isn't clothes!" % to_cover.name)
return
if not cover_with.is_typeclass("evennia.contrib.game_systems.clothing.Clothing", exact=False):
if not cover_with.is_typeclass(ContribClothing, exact=False):
self.caller.msg("%s isn't clothes!" % cover_with.name)
return
if cover_with.db.clothing_type:

View file

@ -6,7 +6,7 @@ Testing clothing contrib
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.utils.create import create_object
from evennia.objects.objects import DefaultRoom
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import clothing
@ -18,11 +18,11 @@ class TestClothingCmd(EvenniaCommandTest):
wearer.location = room
friend.location = room
# Make a test hat
test_hat = create_object(clothing.Clothing, key="test hat")
test_hat = create_object(clothing.ContribClothing, key="test hat")
test_hat.db.clothing_type = "hat"
test_hat.location = wearer
# Make a test scarf
test_scarf = create_object(clothing.Clothing, key="test scarf")
test_scarf = create_object(clothing.ContribClothing, key="test scarf")
test_scarf.db.clothing_type = "accessory"
test_scarf.location = wearer
# Test wear command
@ -89,21 +89,21 @@ class TestClothingCmd(EvenniaCommandTest):
)
class TestClothingFunc(EvenniaTest):
class TestClothingFunc(BaseEvenniaTest):
def test_clothingfunctions(self):
wearer = create_object(clothing.ClothedCharacter, key="Wearer")
room = create_object(DefaultRoom, key="room")
wearer.location = room
# Make a test hat
test_hat = create_object(clothing.Clothing, key="test hat")
test_hat = create_object(clothing.ContribClothing, key="test hat")
test_hat.db.clothing_type = "hat"
test_hat.location = wearer
# Make a test shirt
test_shirt = create_object(clothing.Clothing, key="test shirt")
test_shirt = create_object(clothing.ContribClothing, key="test shirt")
test_shirt.db.clothing_type = "top"
test_shirt.location = wearer
# Make a test pants
test_pants = create_object(clothing.Clothing, key="test pants")
test_pants = create_object(clothing.ContribClothing, key="test pants")
test_pants.db.clothing_type = "bottom"
test_pants.location = wearer

View file

@ -4,12 +4,12 @@ Cooldowns tests.
"""
from mock import patch
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import cooldowns
@patch("evennia.contrib.game_systems.cooldowns.cooldowns.time.time", return_value=0.0)
class TestCooldowns(EvenniaTest):
class TestCooldowns(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.handler = cooldowns.CooldownHandler(self.char1)

View file

@ -7,12 +7,12 @@ 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.utils.test_resources import EvenniaTestCase
from evennia.utils.test_resources import BaseEvenniaTestCase
from evennia.utils.create import create_object
from . import crafting, example_recipes
class TestCraftUtils(EvenniaTestCase):
class TestCraftUtils(BaseEvenniaTestCase):
"""
Test helper utils for crafting.
@ -52,7 +52,7 @@ class _TestMaterial:
return self.name
class TestCraftingRecipeBase(EvenniaTestCase):
class TestCraftingRecipeBase(BaseEvenniaTestCase):
"""
Test the parent recipe class.
"""
@ -137,7 +137,7 @@ class _MockRecipe(crafting.CraftingRecipe):
@override_settings(CRAFT_RECIPE_MODULES=[])
class TestCraftingRecipe(EvenniaTestCase):
class TestCraftingRecipe(BaseEvenniaTestCase):
"""
Test the CraftingRecipe class with one recipe
"""
@ -474,7 +474,7 @@ class TestCraftingRecipe(EvenniaTestCase):
self.assertIsNotNone(self.tool2.pk)
class TestCraftSword(EvenniaTestCase):
class TestCraftSword(BaseEvenniaTestCase):
"""
Test the `craft` function by crafting the example sword.

View file

@ -6,7 +6,7 @@ Turnbattle tests.
from mock import patch, MagicMock
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.utils.create import create_object
from evennia.utils.test_resources import EvenniaTest
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
@ -93,7 +93,7 @@ class TestTurnBattleMagicCmd(EvenniaCommandTest):
self.call(tb_magic.CmdRest(), "", "Char rests to recover HP and MP.")
class TestTurnBattleBasicFunc(EvenniaTest):
class TestTurnBattleBasicFunc(BaseEvenniaTest):
def setUp(self):
super(TestTurnBattleBasicFunc, self).setUp()
self.testroom = create_object(DefaultRoom, key="Test Room")
@ -186,7 +186,7 @@ class TestTurnBattleBasicFunc(EvenniaTest):
self.assertTrue(self.turnhandler.db.fighters == [self.joiner, self.attacker, self.defender])
class TestTurnBattleEquipFunc(EvenniaTest):
class TestTurnBattleEquipFunc(BaseEvenniaTest):
def setUp(self):
super(TestTurnBattleEquipFunc, self).setUp()
self.testroom = create_object(DefaultRoom, key="Test Room")
@ -278,7 +278,7 @@ class TestTurnBattleEquipFunc(EvenniaTest):
self.assertTrue(self.turnhandler.db.fighters == [self.joiner, self.attacker, self.defender])
class TestTurnBattleRangeFunc(EvenniaTest):
class TestTurnBattleRangeFunc(BaseEvenniaTest):
def setUp(self):
super(TestTurnBattleRangeFunc, self).setUp()
self.testroom = create_object(DefaultRoom, key="Test Room")
@ -387,7 +387,7 @@ class TestTurnBattleRangeFunc(EvenniaTest):
self.assertTrue(tb_range.get_range(self.attacker, self.defender) == 1)
class TestTurnBattleItemsFunc(EvenniaTest):
class TestTurnBattleItemsFunc(BaseEvenniaTest):
@patch("evennia.contrib.game_systems.turnbattle.tb_items.tickerhandler", new=MagicMock())
def setUp(self):
super(TestTurnBattleItemsFunc, self).setUp()
@ -511,7 +511,7 @@ class TestTurnBattleItemsFunc(EvenniaTest):
self.assertTrue(self.user.db.conditions == {})
class TestTurnBattleMagicFunc(EvenniaTest):
class TestTurnBattleMagicFunc(BaseEvenniaTest):
def setUp(self):
super(TestTurnBattleMagicFunc, self).setUp()
self.testroom = create_object(DefaultRoom, key="Test Room")

View file

@ -3,13 +3,13 @@ Test wilderness
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia import DefaultCharacter
from evennia.utils.create import create_object
from . import wilderness
class TestWilderness(EvenniaTest):
class TestWilderness(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.char1 = create_object(DefaultCharacter, key="char1")

View file

@ -7,7 +7,7 @@ Tests for the XYZgrid system.
from random import randint
from parameterized import parameterized
from django.test import TestCase
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import xymap, xyzgrid, xymap_legend, xyzroom
@ -340,7 +340,7 @@ MAP12b = r"""
"""
class _MapTest(EvenniaTest):
class _MapTest(BaseEvenniaTest):
"""
Parent for map tests
@ -1147,7 +1147,7 @@ class TestMapStressTest(TestCase):
# f"slower than expected {max_time}s.")
class TestXYZGrid(EvenniaTest):
class TestXYZGrid(BaseEvenniaTest):
"""
Test base grid class with a single map, including spawning objects.
@ -1196,7 +1196,7 @@ class Map12bTransition(xymap_legend.TransitionMapNode):
target_map_xyz = (0, 1, "map12a")
class TestXYZGridTransition(EvenniaTest):
class TestXYZGridTransition(BaseEvenniaTest):
"""
Test the XYZGrid class and transitions between maps.
@ -1254,7 +1254,7 @@ class TestXYZGridTransition(EvenniaTest):
self.assertEqual(west_exit.db_destination, room1)
class TestBuildExampleGrid(EvenniaTest):
class TestBuildExampleGrid(BaseEvenniaTest):
"""
Test building the map-example (this takes about 30s)

View file

@ -3,11 +3,11 @@ Test health bar contrib
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import health_bar
class TestHealthBar(EvenniaTest):
class TestHealthBar(BaseEvenniaTest):
def test_healthbar(self):
expected_bar_str = "|[R|w|n|[B|w test0 / 200test |n"
self.assertEqual(

View file

@ -5,7 +5,7 @@ Tests for RP system
import time
from anything import Anything
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia import create_object
from . import rpsystem
@ -21,7 +21,7 @@ text = (
)
class TestLanguage(EvenniaTest):
class TestLanguage(BaseEvenniaTest):
def setUp(self):
super().setUp()
rplanguage.add_language(
@ -99,7 +99,7 @@ emote = 'With a flair, /me looks at /first and /colliding sdesc-guy. She says "T
case_emote = "/me looks at /first, then /FIRST, /First and /Colliding twice."
class TestRPSystem(EvenniaTest):
class TestRPSystem(BaseEvenniaTest):
maxDiff = None
def setUp(self):

View file

@ -9,7 +9,7 @@ Unit test module for Trait classes.
from copy import copy
from anything import Something
from mock import MagicMock, patch
from evennia.utils.test_resources import EvenniaTestCase
from evennia.utils.test_resources import BaseEvenniaTestCase
from . import traits
@ -39,7 +39,7 @@ _TEST_TRAIT_CLASS_PATHS = [
]
class _TraitHandlerBase(EvenniaTestCase):
class _TraitHandlerBase(BaseEvenniaTestCase):
"Base for trait tests"
@patch("evennia.contrib.rpg.traits.traits._TRAIT_CLASS_PATHS", new=_TEST_TRAIT_CLASS_PATHS)
@ -826,7 +826,7 @@ class TestTraitGaugeTimed(_TraitHandlerBase):
self.assertEqual(self._get_timer_data(), (70, 70, 1, None, 70))
class TestNumericTraitOperators(EvenniaTestCase):
class TestNumericTraitOperators(BaseEvenniaTestCase):
"""Test case for numeric magic method implementations."""
def setUp(self):
@ -909,7 +909,7 @@ class DummyCharacter(_MockObj):
health = traits.TraitProperty("Health value", trait_type="gauge", base=100)
class TestTraitFields(EvenniaTestCase):
class TestTraitFields(BaseEvenniaTestCase):
"""
Test the TraitField class.

View file

@ -3,12 +3,12 @@ Tests for the bodyfunctions.
"""
from mock import Mock, patch
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from .bodyfunctions import BodyFunctions
@patch("evennia.contrib.tutorials.bodyfunctions.bodyfunctions.random")
class TestBodyFunctions(EvenniaTest):
class TestBodyFunctions(BaseEvenniaTest):
script_typeclass = BodyFunctions
def setUp(self):

View file

@ -65,7 +65,8 @@ def info2(caller):
def info3(caller):
text = "'Well ... I'm sort of busy so, have to go. NPC business. Important stuff. You wouldn't understand.'"
text = ("'Well ... I'm sort of busy so, have to go. NPC business. "
"Important stuff. You wouldn't understand.'")
options = (
{"desc": "Oookay ... I won't keep you. Bye.", "goto": "END"},
@ -112,7 +113,8 @@ class CmdTalk(default_cmds.MuxCommand):
# Initiate the menu. Change this if you are putting this on
# some other custom NPC class.
EvMenu(self.caller, "evennia.contrib.tutorials.talking_npc", startnode="menu_start_node")
EvMenu(self.caller, "evennia.contrib.tutorials.talking_npc.talking_npc",
startnode="menu_start_node")
class TalkingCmdSet(CmdSet):

View file

@ -8,11 +8,11 @@ from twisted.trial.unittest import TestCase as TwistedTestCase
from twisted.internet.base import DelayedCall
from evennia.commands.default.tests import EvenniaCommandTest
from evennia.utils.create import create_object
from evennia.utils.test_resources import EvenniaTest, mockdelay, mockdeferLater
from evennia.utils.test_resources import BaseEvenniaTest, mockdelay, mockdeferLater
from . import mob, objects as tutobjects, rooms as tutrooms
class TestTutorialWorldMob(EvenniaTest):
class TestTutorialWorldMob(BaseEvenniaTest):
def test_mob(self):
mobobj = create_object(mob.Mob, key="mob")
self.assertEqual(mobobj.db.is_dead, True)

View file

@ -4,17 +4,36 @@ Module containing the test cases for the Audit system.
"""
from anything import Anything
from mock import patch
from django.test import override_settings
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
import re
from .server import AuditedServerSession
from evennia.server.sessionhandler import SESSIONS
@override_settings(
AUDIT_CALLBACK="evennia.contrib.utils.auditing.outputs.to_syslog",
AUDIT_IN=True,
AUDIT_OUT=True,
AUDIT_ALLOW_SPARSE=True)
class AuditingTest(EvenniaTest):
AUDIT_MASKS=[])
class AuditingTest(BaseEvenniaTest):
@patch("evennia.server.sessionhandler._ServerSession", AuditedServerSession)
def setup_session(self):
"""Overrides default one in EvenniaTest"""
dummysession = AuditedServerSession()
dummysession.init_session("telnet", ("localhost", "testmode"), SESSIONS)
dummysession.sessid = 1
SESSIONS.portal_connect(
dummysession.get_sync_data()
) # note that this creates a new Session!
session = SESSIONS.session_from_sessid(1) # the real session
SESSIONS.login(session, self.account, testmode=True)
self.session = session
print("session", type(self.session), self.session)
@patch("evennia.contrib.utils.auditing.server.AUDIT_CALLBACK",
"evennia.contrib.utils.auditing.outputs.to_syslog")
@patch("evennia.contrib.utils.auditing.server.AUDIT_IN", True)
@patch("evennia.contrib.utils.auditing.server.AUDIT_OUT", True)
def test_mask(self):
"""
Make sure the 'mask' function is properly masking potentially sensitive
@ -82,6 +101,10 @@ class AuditingTest(EvenniaTest):
for secret in secrets:
self.assertEqual(self.session.mask(secret), secret)
@patch("evennia.contrib.utils.auditing.server.AUDIT_CALLBACK",
"evennia.contrib.utils.auditing.outputs.to_syslog")
@patch("evennia.contrib.utils.auditing.server.AUDIT_IN", True)
@patch("evennia.contrib.utils.auditing.server.AUDIT_OUT", True)
def test_audit(self):
"""
Make sure the 'audit' function is returning a dictionary based on values

View file

@ -3,13 +3,13 @@ Random string tests.
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import random_string_generator
SIMPLE_GENERATOR = random_string_generator.RandomStringGenerator("simple", "[01]{2}")
class TestRandomStringGenerator(EvenniaTest):
class TestRandomStringGenerator(BaseEvenniaTest):
def test_generate(self):
"""Generate and fail when exhausted."""
generated = []

View file

@ -3,7 +3,7 @@ Test tree select
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from . import tree_select
from evennia.contrib.utils.fieldfill import fieldfill
@ -15,7 +15,7 @@ Bar
-Qux"""
class TestTreeSelectFunc(EvenniaTest):
class TestTreeSelectFunc(BaseEvenniaTest):
def test_tree_functions(self):
# Dash counter
self.assertTrue(tree_select.dashcount("--test") == 2)
@ -57,6 +57,6 @@ FIELD_TEST_TEMPLATE = [
FIELD_TEST_DATA = {"TextTest": None, "NumberTest": None, "DefaultText": "Test", "DefaultNum": 3}
class TestFieldFillFunc(EvenniaTest):
class TestFieldFillFunc(BaseEvenniaTest):
def test_field_functions(self):
self.assertTrue(fieldfill.form_template_to_dict(FIELD_TEST_TEMPLATE) == FIELD_TEST_DATA)

View file

@ -7,7 +7,7 @@ the stability and integrity of the codebase during updates.
This module tests the lock functionality of Evennia.
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
try:
# this is a special optimized Django version, only available in current Django devel
@ -24,7 +24,7 @@ from evennia.utils.create import create_object
# ------------------------------------------------------------
class TestLockCheck(EvenniaTest):
class TestLockCheck(BaseEvenniaTest):
def testrun(self):
dbref = self.obj2.dbref
self.obj1.locks.add(
@ -42,7 +42,7 @@ class TestLockCheck(EvenniaTest):
self.assertEqual(True, self.obj1.locks.check(self.obj2, "not_exist", default=True))
class TestLockfuncs(EvenniaTest):
class TestLockfuncs(BaseEvenniaTest):
def setUp(self):
super(TestLockfuncs, self).setUp()
self.account2.permissions.add("Admin")
@ -210,7 +210,7 @@ class TestLockfuncs(EvenniaTest):
self.assertEqual(False, lockfuncs.serversetting(None, None, "TESTVAL", "123"))
class TestPermissionCheck(EvenniaTest):
class TestPermissionCheck(BaseEvenniaTest):
"""
Test the PermissionHandler.check method

View file

@ -1,10 +1,10 @@
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia import DefaultObject, DefaultCharacter, DefaultRoom, DefaultExit
from evennia.objects.models import ObjectDB
from evennia.utils import create
class DefaultObjectTest(EvenniaTest):
class DefaultObjectTest(BaseEvenniaTest):
ip = "212.216.139.14"
@ -87,7 +87,7 @@ class DefaultObjectTest(EvenniaTest):
self.assertEqual(self.char1.search("co", stacked=2), None)
class TestObjectManager(EvenniaTest):
class TestObjectManager(BaseEvenniaTest):
"Test object manager methods"
def test_get_object_with_account(self):
@ -160,7 +160,7 @@ class TestObjectManager(EvenniaTest):
self.assertEqual(obj2.attributes.get(key="phrase", category="adventure"), "plugh")
class TestContentHandler(EvenniaTest):
class TestContentHandler(BaseEvenniaTest):
"Test the ContentHandler (obj.contents)"
def test_object_create_remove(self):

View file

@ -9,7 +9,7 @@ import uuid
from time import time
from anything import Something
from django.test.utils import override_settings
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils.tests.test_evmenu import TestEvMenu
from evennia.prototypes import spawner, prototypes as protlib
from evennia.prototypes import menus as olc_menus
@ -45,7 +45,7 @@ _PROTPARENTS = {
},
}
class TestSpawner(EvenniaTest):
class TestSpawner(BaseEvenniaTest):
def setUp(self):
super(TestSpawner, self).setUp()
self.prot1 = {
@ -86,7 +86,7 @@ class TestSpawner(EvenniaTest):
)
class TestUtils(EvenniaTest):
class TestUtils(BaseEvenniaTest):
def test_prototype_from_object(self):
self.maxDiff = None
self.obj1.attributes.add("test", "testval")
@ -307,7 +307,7 @@ class TestUtils(EvenniaTest):
)
class TestProtLib(EvenniaTest):
class TestProtLib(BaseEvenniaTest):
def setUp(self):
super(TestProtLib, self).setUp()
self.obj1.attributes.add("testattr", "testval")
@ -339,7 +339,7 @@ class TestProtLib(EvenniaTest):
self.assertEqual(match, [self.prot])
class TestProtFuncs(EvenniaTest):
class TestProtFuncs(BaseEvenniaTest):
@override_settings(PROT_FUNC_MODULES=["evennia.prototypes.protfuncs"])
def test_protkey_protfunc(self):
@ -355,7 +355,7 @@ class TestProtFuncs(EvenniaTest):
)
class TestPrototypeStorage(EvenniaTest):
class TestPrototypeStorage(BaseEvenniaTest):
def setUp(self):
super(TestPrototypeStorage, self).setUp()
self.maxDiff = None
@ -437,7 +437,7 @@ class _MockMenu(object):
pass
class TestMenuModule(EvenniaTest):
class TestMenuModule(BaseEvenniaTest):
maxDiff = None
@ -874,7 +874,7 @@ class TestOLCMenu(TestEvMenu):
]
class PrototypeCrashTest(EvenniaTest):
class PrototypeCrashTest(BaseEvenniaTest):
# increase this to 1000 for optimization testing
num_prototypes = 10
@ -901,7 +901,7 @@ class PrototypeCrashTest(EvenniaTest):
# print(f"Prototypes listed in {time()-start_time} seconds.")
class Test2474(EvenniaTest):
class Test2474(BaseEvenniaTest):
"""
Test bug #2474 (https://github.com/evennia/evennia/issues/2474),
where the prototype's attribute fails to take precedence over

View file

@ -4,11 +4,11 @@ from parameterized import parameterized
from evennia import DefaultScript
from evennia.scripts.models import ScriptDB, ObjectDoesNotExist
from evennia.utils.create import create_script
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.scripts.scripts import DoNothing, ExtendedLoopingCall
class TestScript(EvenniaTest):
class TestScript(BaseEvenniaTest):
def test_create(self):
"Check the script can be created via the convenience method."
obj, errors = DefaultScript.create("useless-machine")

View file

@ -16,7 +16,7 @@ import json
from mock import Mock, MagicMock
from evennia.server.portal import irc
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from twisted.conch.telnet import IAC, WILL, DONT, SB, SE, NAWS, DO
from twisted.test import proto_helpers
@ -281,7 +281,7 @@ class TestTelnet(TwistedTestCase):
return d
class TestWebSocket(EvenniaTest):
class TestWebSocket(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.proto = WebSocketClient()

View file

@ -8,7 +8,7 @@ import unittest
from django.test import TestCase
from evennia.server.validators import EvenniaPasswordValidator
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from django.test.runner import DiscoverRunner
@ -70,7 +70,7 @@ class TestDeprecations(TestCase):
)
class ValidatorTest(EvenniaTest):
class ValidatorTest(BaseEvenniaTest):
def test_validator(self):
# Validator returns None on success and ValidationError on failure.
validator = EvenniaPasswordValidator()
@ -84,7 +84,7 @@ class ValidatorTest(EvenniaTest):
self.assertRaises(ValidationError, validator.validate, "(#)[#]<>", user=self.account)
class ThrottleTest(EvenniaTest):
class ThrottleTest(BaseEvenniaTest):
"""
Class for testing the connection/IP throttle.
"""

View file

@ -3,7 +3,7 @@ Unit tests for typeclass base system
"""
from django.test import override_settings
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.typeclasses import attributes
from mock import patch
from parameterized import parameterized
@ -13,7 +13,7 @@ from parameterized import parameterized
# ------------------------------------------------------------
class TestAttributes(EvenniaTest):
class TestAttributes(BaseEvenniaTest):
def test_attrhandler(self):
key = "testattr"
value = "test attr value "
@ -58,7 +58,7 @@ class TestAttributes(EvenniaTest):
self.assertEqual(attrobj.locks.all(), ["attrread:id(1)"])
class TestTypedObjectManager(EvenniaTest):
class TestTypedObjectManager(BaseEvenniaTest):
def _manager(self, methodname, *args, **kwargs):
return list(getattr(self.obj1.__class__.objects, methodname)(*args, **kwargs))
@ -149,7 +149,7 @@ class TestTypedObjectManager(EvenniaTest):
self.assertEqual(tagobj.db_data, "data4")
class TestTags(EvenniaTest):
class TestTags(BaseEvenniaTest):
def test_has_tag_key_only(self):
self.obj1.tags.add("tagC")
self.assertTrue(self.obj1.tags.has("tagC"))
@ -175,7 +175,7 @@ class TestTags(EvenniaTest):
self.assertFalse(self.obj1.tags.has(category="categoryD"))
class TestNickHandler(EvenniaTest):
class TestNickHandler(BaseEvenniaTest):
"""
Test the nick handler replacement.

View file

@ -124,7 +124,6 @@ class EvenniaTestMixin:
"""
Evennia test environment mixin
"""
account_typeclass = DefaultAccount
object_typeclass = DefaultObject
character_typeclass = DefaultCharacter
@ -132,20 +131,27 @@ class EvenniaTestMixin:
room_typeclass = DefaultRoom
script_typeclass = DefaultScript
@patch("evennia.scripts.taskhandler.deferLater", _mock_deferlater)
def setUp(self):
"""
Sets up testing environment
"""
def save_backups(self):
self.backups = (
SESSIONS.data_out,
SESSIONS.disconnect,
settings.DEFAULT_HOME,
settings.PROTOTYPE_MODULES,
)
def restore_backups(self):
flush_cache()
SESSIONS.data_out = self.backups[0]
SESSIONS.disconnect = self.backups[1]
settings.DEFAULT_HOME = self.backups[2]
settings.PROTOTYPE_MODULES = self.backups[3]
def mock_sessions(self):
SESSIONS.data_out = Mock()
SESSIONS.disconnect = Mock()
self.mocked_SESSIONS = SESSIONS
def create_accounts(self):
self.account = create.create_account(
"TestAccount",
email="test@test.com",
@ -158,21 +164,33 @@ class EvenniaTestMixin:
password="testpassword",
typeclass=self.account_typeclass,
)
self.account.permissions.add("Developer")
def teardown_accounts(self):
self.account.delete()
self.account2.delete()
def create_rooms(self):
self.room1 = create.create_object(self.room_typeclass, key="Room", nohome=True)
self.room1.db.desc = "room_desc"
settings.DEFAULT_HOME = "#%i" % self.room1.id # we must have a default home
# Set up fake prototype module for allowing tests to use named prototypes.
settings.PROTOTYPE_MODULES = "evennia.utils.tests.data.prototypes_example"
self.room2 = create.create_object(self.room_typeclass, key="Room2")
self.exit = create.create_object(
self.exit_typeclass, key="out", location=self.room1, destination=self.room2
)
def create_objs(self):
self.obj1 = create.create_object(
self.object_typeclass, key="Obj", location=self.room1, home=self.room1
)
self.obj2 = create.create_object(
self.object_typeclass, key="Obj2", location=self.room1, home=self.room1
)
def create_chars(self):
self.char1 = create.create_object(
self.character_typeclass, key="Char", location=self.room1, home=self.room1
)
@ -184,11 +202,11 @@ class EvenniaTestMixin:
self.account.db._last_puppet = self.char1
self.char2.account = self.account2
self.account2.db._last_puppet = self.char2
def create_script(self):
self.script = create.create_script(self.script_typeclass, key="Script")
self.account.permissions.add("Developer")
# set up a fake session
def setup_session(self):
dummysession = ServerSession()
dummysession.init_session("telnet", ("localhost", "testmode"), SESSIONS)
dummysession.sessid = 1
@ -199,21 +217,32 @@ class EvenniaTestMixin:
SESSIONS.login(session, self.account, testmode=True)
self.session = session
def tearDown(self):
flush_cache()
SESSIONS.data_out = self.backups[0]
SESSIONS.disconnect = self.backups[1]
settings.DEFAULT_HOME = self.backups[2]
settings.PROTOTYPE_MODULES = self.backups[3]
def teardown_session(self):
del SESSIONS[self.session.sessid]
self.account.delete()
self.account2.delete()
@patch("evennia.scripts.taskhandler.deferLater", _mock_deferlater)
def setUp(self):
"""
Sets up testing environment
"""
self.save_backups()
self.mock_sessions()
self.create_accounts()
self.create_rooms()
self.create_objs()
self.create_chars()
self.create_script()
self.setup_session()
def tearDown(self):
self.restore_backups()
self.teardown_session()
self.teardown_accounts()
super().tearDown()
@override_settings(**DEFAULT_SETTINGS)
class EvenniaTestCase(TestCase):
class BaseEvenniaTestCase(TestCase):
"""
Base test (with no default objects) but with
enforced default settings.
@ -222,14 +251,14 @@ class EvenniaTestCase(TestCase):
@override_settings(**DEFAULT_SETTINGS)
class BaseEvenniaTest(EvenniaTestMixin, TestCase):
"""
This class parent has all default objects and uses only default settings.
"""
class EvenniaTest(EvenniaTestMixin, TestCase):
"""
This class parent uses only default settings.
"""
class LocalEvenniaTest(EvenniaTestMixin, TestCase):
"""
This test class is intended for inheriting in mygame tests.
It helps ensure your tests are run with your own objects

View file

@ -4,12 +4,12 @@ Tests of create functions
"""
from django.test import TestCase
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.scripts.scripts import DefaultScript
from evennia.utils import create
class TestCreateScript(EvenniaTest):
class TestCreateScript(BaseEvenniaTest):
def test_create_script(self):
class TestScriptA(DefaultScript):
def at_script_creation(self):
@ -129,7 +129,7 @@ class TestCreateHelpEntry(TestCase):
self.assertEqual(entry.tags.all(return_key_and_category=True), tags)
class TestCreateMessage(EvenniaTest):
class TestCreateMessage(BaseEvenniaTest):
msgtext = """
Qui laborum voluptas quis commodi ipsum quo temporibus eum. Facilis

View file

@ -3,13 +3,11 @@ Test eveditor
"""
from mock import MagicMock
from django.test import TestCase
from evennia.utils import eveditor
from evennia.commands.default.tests import CommandTest
from evennia.commands.default.tests import EvenniaCommandTest
class TestEvEditor(CommandTest):
class TestEvEditor(EvenniaCommandTest):
def test_eveditor_view_cmd(self):
eveditor.EvEditor(self.char1)
self.call(

View file

@ -20,7 +20,7 @@ To help debug the menu, turn on `debug_output`, which will print the traversal p
import copy
from anything import Anything
from django.test import TestCase
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils import evmenu
from evennia.utils import ansi
from mock import MagicMock
@ -274,7 +274,7 @@ def _callnode2(caller, raw_string, **kwargs):
return "node2"
class TestMenuTemplateParse(EvenniaTest):
class TestMenuTemplateParse(BaseEvenniaTest):
"""Test menu templating helpers"""
def setUp(self):

View file

@ -417,7 +417,7 @@ class TestDefaultCallables(TestCase):
)
class TestCallableSearch(test_resources.EvenniaTest):
class TestCallableSearch(test_resources.BaseEvenniaTest):
"""
Test the $search(query) callable

View file

@ -16,7 +16,7 @@ from twisted.internet import task
from evennia.utils.ansi import ANSIString
from evennia.utils import utils
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
class TestIsIter(TestCase):
@ -259,7 +259,7 @@ class TestDateTimeFormat(TestCase):
class TestImportFunctions(TestCase):
def _t_dir_file(self, filename):
def _path_to_file(self, filename):
testdir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(testdir, filename)
@ -272,12 +272,12 @@ class TestImportFunctions(TestCase):
self.assertIsNone(loaded_mod)
def test_mod_import_from_path(self):
test_path = self._t_dir_file("test_eveditor.py")
test_path = self._path_to_file("test_eveditor.py")
loaded_mod = utils.mod_import_from_path(test_path)
self.assertIsNotNone(loaded_mod)
def test_mod_import_from_path_invalid(self):
test_path = self._t_dir_file("invalid_filename.py")
test_path = self._path_to_file("invalid_filename.py")
loaded_mod = utils.mod_import_from_path(test_path)
self.assertIsNone(loaded_mod)
@ -452,7 +452,7 @@ def dummy_func(obj):
return True
class TestDelay(EvenniaTest):
class TestDelay(BaseEvenniaTest):
"""
Test utils.delay.
"""

View file

@ -2,7 +2,7 @@
Tests for the REST API.
"""
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.web.api import serializers
from rest_framework.test import APIClient
from django.urls import reverse
@ -18,7 +18,7 @@ urlpatterns = [
@override_settings(REST_API_ENABLED=True, ROOT_URLCONF=__name__, AUTH_USERNAME_VALIDATORS=[])
class TestEvenniaRESTApi(EvenniaTest):
class TestEvenniaRESTApi(BaseEvenniaTest):
client_class = APIClient
maxDiff = None

View file

@ -4,13 +4,13 @@ from django.test import Client, override_settings
from django.urls import reverse
from evennia.utils import class_from_module
from evennia.utils.create import create_help_entry
from evennia.utils.test_resources import EvenniaTest
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.help import filehelp
_FILE_HELP_ENTRIES = None
class EvenniaWebTest(EvenniaTest):
class EvenniaWebTest(BaseEvenniaTest):
# Use the same classes the views are expecting
account_typeclass = settings.BASE_ACCOUNT_TYPECLASS