changed module location, mocked out delay calls
This commit is contained in:
parent
a30e152405
commit
7dfbc12d7b
5 changed files with 35 additions and 6 deletions
|
|
@ -294,7 +294,7 @@ class Mod:
|
||||||
self.perstack = perstack
|
self.perstack = perstack
|
||||||
|
|
||||||
|
|
||||||
class BuffHandler(object):
|
class BuffHandler:
|
||||||
|
|
||||||
ownerref = None
|
ownerref = None
|
||||||
dbkey = "buffs"
|
dbkey = "buffs"
|
||||||
|
|
@ -734,6 +734,8 @@ class BuffHandler(object):
|
||||||
buff: The buff to search for. This can be a string (the key) or a class reference (the buff type)
|
buff: The buff to search for. This can be a string (the key) or a class reference (the buff type)
|
||||||
|
|
||||||
Returns a bool. If no buff and no key is specified, returns False."""
|
Returns a bool. If no buff and no key is specified, returns False."""
|
||||||
|
if not buff:
|
||||||
|
return False
|
||||||
if not (isinstance(buff, type) or isinstance(buff, str)):
|
if not (isinstance(buff, type) or isinstance(buff, str)):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
# in a module tests.py somewhere i your game dir
|
"""
|
||||||
from unittest.mock import Mock, patch
|
Tests for the buff system contrib
|
||||||
|
"""
|
||||||
|
from unittest.mock import Mock, call, patch
|
||||||
from evennia import DefaultObject, create_object
|
from evennia import DefaultObject, create_object
|
||||||
from evennia.utils import create
|
from evennia.utils import create
|
||||||
from evennia.utils.utils import lazy_property
|
from evennia.utils.utils import lazy_property
|
||||||
from .samplebuffs import StatBuff
|
from .samplebuffs import StatBuff
|
||||||
|
|
||||||
# the function we want to test
|
|
||||||
from .buff import BaseBuff, Mod, BuffHandler, BuffableProperty
|
from .buff import BaseBuff, Mod, BuffHandler, BuffableProperty
|
||||||
from evennia.utils.test_resources import EvenniaTest
|
from evennia.utils.test_resources import EvenniaTest
|
||||||
|
|
||||||
|
from evennia.contrib.rpg.buffs import buff
|
||||||
|
|
||||||
|
|
||||||
class _EmptyBuff(BaseBuff):
|
class _EmptyBuff(BaseBuff):
|
||||||
pass
|
pass
|
||||||
|
|
@ -117,6 +119,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
del self.testobj
|
del self.testobj
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_addremove(self):
|
def test_addremove(self):
|
||||||
"""tests adding and removing buffs"""
|
"""tests adding and removing buffs"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -159,6 +162,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
handler.clear()
|
handler.clear()
|
||||||
self.assertFalse(self.testobj.buffs.all)
|
self.assertFalse(self.testobj.buffs.all)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_getters(self):
|
def test_getters(self):
|
||||||
"""tests all built-in getters"""
|
"""tests all built-in getters"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -184,6 +188,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.assertTrue("ttb" in handler.get_by_cachevalue("ttbcache"))
|
self.assertTrue("ttb" in handler.get_by_cachevalue("ttbcache"))
|
||||||
self.assertTrue("ttb" in handler.get_by_cachevalue("ttbcache", True))
|
self.assertTrue("ttb" in handler.get_by_cachevalue("ttbcache", True))
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_details(self):
|
def test_details(self):
|
||||||
"""tests that buff details like name and flavor are correct"""
|
"""tests that buff details like name and flavor are correct"""
|
||||||
handler: BuffHandler = self.testobj.buffs
|
handler: BuffHandler = self.testobj.buffs
|
||||||
|
|
@ -192,6 +197,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.assertEqual(handler.get("tmb").flavor, "modderbuff")
|
self.assertEqual(handler.get("tmb").flavor, "modderbuff")
|
||||||
self.assertEqual(handler.get("ttb").name, "ttb")
|
self.assertEqual(handler.get("ttb").name, "ttb")
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_modify(self):
|
def test_modify(self):
|
||||||
"""tests to ensure that values are modified correctly, and stack across mods"""
|
"""tests to ensure that values are modified correctly, and stack across mods"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -226,6 +232,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.assertEqual(handler.check(_stat1, "stat1"), 30)
|
self.assertEqual(handler.check(_stat1, "stat1"), 30)
|
||||||
self.assertEqual(handler.check(_stat2, "stat2"), 20)
|
self.assertEqual(handler.check(_stat2, "stat2"), 20)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_trigger(self):
|
def test_trigger(self):
|
||||||
"""tests to ensure triggers correctly fire"""
|
"""tests to ensure triggers correctly fire"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -242,6 +249,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.assertTrue(self.testobj.db.triggertest1)
|
self.assertTrue(self.testobj.db.triggertest1)
|
||||||
self.assertTrue(self.testobj.db.triggertest2)
|
self.assertTrue(self.testobj.db.triggertest2)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_context_conditional(self):
|
def test_context_conditional(self):
|
||||||
"""tests to ensure context is passed to buffs, and also tests conditionals"""
|
"""tests to ensure context is passed to buffs, and also tests conditionals"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -269,6 +277,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.assertEqual(self.testobj.db.att, self.obj2)
|
self.assertEqual(self.testobj.db.att, self.obj2)
|
||||||
self.assertEqual(self.testobj.db.dmg, 5)
|
self.assertEqual(self.testobj.db.dmg, 5)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_complex(self):
|
def test_complex(self):
|
||||||
"""tests a complex mod (conditionals, multiple triggers/mods)"""
|
"""tests a complex mod (conditionals, multiple triggers/mods)"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -310,11 +319,26 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
handler.check(self.testobj.db.comtwo, "com2", context=self.testobj.db.comtext), 100
|
handler.check(self.testobj.db.comtwo, "com2", context=self.testobj.db.comtext), 100
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_timing(self):
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay")
|
||||||
|
def test_timing(self, mock_delay: Mock):
|
||||||
"""tests timing-related features, such as ticking and duration"""
|
"""tests timing-related features, such as ticking and duration"""
|
||||||
# setup
|
# setup
|
||||||
handler: BuffHandler = self.testobj.buffs
|
handler: BuffHandler = self.testobj.buffs
|
||||||
|
mock_delay.side_effect = [None, handler.cleanup]
|
||||||
handler.add(_TestTimeBuff)
|
handler.add(_TestTimeBuff)
|
||||||
|
calls = [
|
||||||
|
call(
|
||||||
|
1,
|
||||||
|
buff.tick_buff,
|
||||||
|
handler=handler,
|
||||||
|
buffkey="ttib",
|
||||||
|
context={},
|
||||||
|
initial=False,
|
||||||
|
persistent=True,
|
||||||
|
),
|
||||||
|
call(5, handler.cleanup, persistent=True),
|
||||||
|
]
|
||||||
|
mock_delay.assert_has_calls(calls)
|
||||||
self.testobj.db.timetest, self.testobj.db.ticktest = 1, False
|
self.testobj.db.timetest, self.testobj.db.ticktest = 1, False
|
||||||
# test duration and ticking
|
# test duration and ticking
|
||||||
_instance = handler.get("ttib")
|
_instance = handler.get("ttib")
|
||||||
|
|
@ -328,6 +352,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
handler.cleanup()
|
handler.cleanup()
|
||||||
self.assertFalse(handler.get("ttib"), None)
|
self.assertFalse(handler.get("ttib"), None)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_buffableproperty(self):
|
def test_buffableproperty(self):
|
||||||
"""tests buffable properties"""
|
"""tests buffable properties"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -336,6 +361,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.testobj.buffs.remove("tmb")
|
self.testobj.buffs.remove("tmb")
|
||||||
self.assertEqual(self.testobj.stat1, 10)
|
self.assertEqual(self.testobj.stat1, 10)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_stresstest(self):
|
def test_stresstest(self):
|
||||||
"""tests large amounts of buffs, and related removal methods"""
|
"""tests large amounts of buffs, and related removal methods"""
|
||||||
# setup
|
# setup
|
||||||
|
|
@ -349,6 +375,7 @@ class TestBuffsAndHandler(EvenniaTest):
|
||||||
self.testobj.buffs.clear()
|
self.testobj.buffs.clear()
|
||||||
self.assertFalse(self.testobj.buffs.all)
|
self.assertFalse(self.testobj.buffs.all)
|
||||||
|
|
||||||
|
@patch("evennia.contrib.rpg.buffs.buff.utils.delay", new=Mock())
|
||||||
def test_modgen(self):
|
def test_modgen(self):
|
||||||
"""test generating mods on the fly"""
|
"""test generating mods on the fly"""
|
||||||
# setup
|
# setup
|
||||||
Loading…
Add table
Add a link
Reference in a new issue