Add extra unit test to test #3271
This commit is contained in:
parent
0f9d2beb09
commit
1add10bcb0
1 changed files with 57 additions and 39 deletions
|
|
@ -3,21 +3,20 @@ Unit tests for the scripts package
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from unittest import TestCase, mock
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from unittest import TestCase, mock
|
||||||
from parameterized import parameterized
|
|
||||||
|
|
||||||
from evennia import DefaultScript
|
from evennia import DefaultScript
|
||||||
from evennia.objects.objects import DefaultObject
|
from evennia.objects.objects import DefaultObject
|
||||||
from evennia.scripts.models import ObjectDoesNotExist, ScriptDB
|
|
||||||
from evennia.scripts.scripts import DoNothing, ExtendedLoopingCall
|
|
||||||
from evennia.utils.create import create_script
|
|
||||||
from evennia.utils.test_resources import BaseEvenniaTest
|
|
||||||
from evennia.scripts.tickerhandler import TickerHandler
|
|
||||||
from evennia.scripts.monitorhandler import MonitorHandler
|
|
||||||
from evennia.scripts.manager import ScriptDBManager
|
from evennia.scripts.manager import ScriptDBManager
|
||||||
|
from evennia.scripts.models import ObjectDoesNotExist, ScriptDB
|
||||||
|
from evennia.scripts.monitorhandler import MonitorHandler
|
||||||
|
from evennia.scripts.scripts import DoNothing, ExtendedLoopingCall
|
||||||
|
from evennia.scripts.tickerhandler import TickerHandler
|
||||||
|
from evennia.utils.create import create_script
|
||||||
from evennia.utils.dbserialize import dbserialize
|
from evennia.utils.dbserialize import dbserialize
|
||||||
|
from evennia.utils.test_resources import BaseEvenniaTest
|
||||||
|
from parameterized import parameterized
|
||||||
|
|
||||||
|
|
||||||
class TestScript(BaseEvenniaTest):
|
class TestScript(BaseEvenniaTest):
|
||||||
|
|
@ -29,6 +28,7 @@ class TestScript(BaseEvenniaTest):
|
||||||
self.assertFalse(errors, errors)
|
self.assertFalse(errors, errors)
|
||||||
mockinit.assert_called()
|
mockinit.assert_called()
|
||||||
|
|
||||||
|
|
||||||
class TestTickerHandler(TestCase):
|
class TestTickerHandler(TestCase):
|
||||||
"""Test the TickerHandler class"""
|
"""Test the TickerHandler class"""
|
||||||
|
|
||||||
|
|
@ -44,6 +44,7 @@ class TestTickerHandler(TestCase):
|
||||||
th = TickerHandler()
|
th = TickerHandler()
|
||||||
th.remove(callback=1)
|
th.remove(callback=1)
|
||||||
|
|
||||||
|
|
||||||
class TestScriptDBManager(TestCase):
|
class TestScriptDBManager(TestCase):
|
||||||
"""Test the ScriptDBManger class"""
|
"""Test the ScriptDBManger class"""
|
||||||
|
|
||||||
|
|
@ -53,10 +54,12 @@ class TestScriptDBManager(TestCase):
|
||||||
returned_list = manager_obj.get_all_scripts_on_obj(False)
|
returned_list = manager_obj.get_all_scripts_on_obj(False)
|
||||||
self.assertEqual(returned_list, [])
|
self.assertEqual(returned_list, [])
|
||||||
|
|
||||||
|
|
||||||
class TestingListIntervalScript(DefaultScript):
|
class TestingListIntervalScript(DefaultScript):
|
||||||
"""
|
"""
|
||||||
A script that does nothing. Used to test listing of script with nonzero intervals.
|
A script that does nothing. Used to test listing of script with nonzero intervals.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_script_creation(self):
|
def at_script_creation(self):
|
||||||
"""
|
"""
|
||||||
Setup the script
|
Setup the script
|
||||||
|
|
@ -66,11 +69,13 @@ class TestingListIntervalScript(DefaultScript):
|
||||||
self.interval = 1
|
self.interval = 1
|
||||||
self.repeats = 1
|
self.repeats = 1
|
||||||
|
|
||||||
|
|
||||||
class TestScriptHandler(BaseEvenniaTest):
|
class TestScriptHandler(BaseEvenniaTest):
|
||||||
"""
|
"""
|
||||||
Test the ScriptHandler class.
|
Test the ScriptHandler class.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.obj, self.errors = DefaultObject.create("test_object")
|
self.obj, self.errors = DefaultObject.create("test_object")
|
||||||
|
|
||||||
|
|
@ -90,6 +95,13 @@ class TestScriptHandler(BaseEvenniaTest):
|
||||||
self.assertTrue("None/1" in self.str)
|
self.assertTrue("None/1" in self.str)
|
||||||
self.assertTrue("1 repeats" in self.str)
|
self.assertTrue("1 repeats" in self.str)
|
||||||
|
|
||||||
|
def test_get_script(self):
|
||||||
|
"Checks that Scripthandler get function returns correct script"
|
||||||
|
self.obj.scripts.add(TestingListIntervalScript)
|
||||||
|
script = self.obj.scripts.get("interval_test")
|
||||||
|
self.assertTrue(bool(script))
|
||||||
|
|
||||||
|
|
||||||
class TestScriptDB(TestCase):
|
class TestScriptDB(TestCase):
|
||||||
"Check the singleton/static ScriptDB object works correctly"
|
"Check the singleton/static ScriptDB object works correctly"
|
||||||
|
|
||||||
|
|
@ -192,10 +204,12 @@ class TestExtendedLoopingCall(TestCase):
|
||||||
|
|
||||||
callback.assert_called_once()
|
callback.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def dummy_func():
|
def dummy_func():
|
||||||
"""Dummy function used as callback parameter"""
|
"""Dummy function used as callback parameter"""
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class TestMonitorHandler(TestCase):
|
class TestMonitorHandler(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the MonitorHandler class.
|
Test the MonitorHandler class.
|
||||||
|
|
@ -220,9 +234,9 @@ class TestMonitorHandler(TestCase):
|
||||||
def test_remove(self):
|
def test_remove(self):
|
||||||
"""Tests that removing an object from the monitor handler works correctly"""
|
"""Tests that removing an object from the monitor handler works correctly"""
|
||||||
obj = mock.Mock()
|
obj = mock.Mock()
|
||||||
fieldname = 'db_remove'
|
fieldname = "db_remove"
|
||||||
callback = dummy_func
|
callback = dummy_func
|
||||||
idstring = 'test_remove'
|
idstring = "test_remove"
|
||||||
|
|
||||||
"""Add an object to the monitor handler and then remove it"""
|
"""Add an object to the monitor handler and then remove it"""
|
||||||
self.handler.add(obj, fieldname, callback, idstring=idstring)
|
self.handler.add(obj, fieldname, callback, idstring=idstring)
|
||||||
|
|
@ -249,9 +263,13 @@ class TestMonitorHandler(TestCase):
|
||||||
self.handler.add(obj[1], fieldname[1], callback, idstring=idstring[1], persistent=True)
|
self.handler.add(obj[1], fieldname[1], callback, idstring=idstring[1], persistent=True)
|
||||||
|
|
||||||
output = self.handler.all()
|
output = self.handler.all()
|
||||||
self.assertEquals(output,
|
self.assertEquals(
|
||||||
[(obj[0], fieldname[0], idstring[0], False, {}),
|
output,
|
||||||
(obj[1], fieldname[1], idstring[1], True, {})])
|
[
|
||||||
|
(obj[0], fieldname[0], idstring[0], False, {}),
|
||||||
|
(obj[1], fieldname[1], idstring[1], True, {}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def test_clear(self):
|
def test_clear(self):
|
||||||
"""Tests that the clear function correctly clears the monitor handler"""
|
"""Tests that the clear function correctly clears the monitor handler"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue