Fix edge cases in channelhandler and make unittests work.

This commit is contained in:
Griatch 2016-10-16 19:04:05 +02:00
parent e39e1bdd45
commit cd9c11f6a8
3 changed files with 13 additions and 10 deletions

View file

@ -309,5 +309,5 @@ class TestBatchProcess(CommandTest):
def test_batch_commands(self):
# cannot test batchcode here, it must run inside the server process
self.call(batchprocess.CmdBatchCommands(), "example_batch_cmds", "Running Batchcommand processor Automatic mode for example_batch_cmds")
#self.call(batchprocess.CmdBatchCode(), "examples.batch_code", "")
# we make sure to delete the button again here to stop the running reactor
self.call(building.CmdDestroy(), "button", "button was destroyed.")

View file

@ -3,7 +3,7 @@ Unit testing for the Command system itself.
"""
from evennia.utils.test_resources import EvenniaTest, SESSIONS, TestCase
from evennia.utils.test_resources import EvenniaTest, TestCase
from evennia.commands.cmdset import CmdSet
from evennia.commands.command import Command
@ -307,9 +307,11 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
import evennia
from evennia.commands.default.cmdset_player import PlayerCmdSet
from evennia.comms.channelhandler import CHANNEL_HANDLER
testchannel = evennia.create_channel("testchannel", locks="listen:all();send:all()")
testchannel = evennia.create_channel("channeltest", locks="listen:all();send:all()")
CHANNEL_HANDLER.add(testchannel)
CHANNEL_HANDLER.update()
self.assertTrue(testchannel.connect(self.player))
self.assertTrue(testchannel.has_connection(self.player))
a, b, c, d = self.cmdset_a, self.cmdset_b, self.cmdset_c, self.cmdset_d
self.set_cmdsets(self.player, a, b, c, d)
deferred = cmdhandler.get_and_merge_cmdsets(self.session, self.session, self.player, self.char1, "session")
@ -334,9 +336,3 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
self.assertEqual(len(cmdset.commands), 9)
deferred.addCallback(_callback)
return deferred

View file

@ -36,6 +36,8 @@ _GA = object.__getattribute__
_SA = object.__setattr__
_DA = object.__delattr__
_CHANNELHANDLER = None
#------------------------------------------------------------
#
@ -486,6 +488,9 @@ class SubscriptionHandler(object):
no hooks will be called.
"""
global _CHANNELHANDLER
if not _CHANNELHANDLER:
from evennia.comms.channelhandler import CHANNEL_HANDLER as _CHANNELHANDLER
for subscriber in make_iter(entity):
if subscriber:
clsname = subscriber.__dbclass__.__name__
@ -494,6 +499,7 @@ class SubscriptionHandler(object):
self.obj.db_object_subscriptions.add(subscriber)
elif clsname == "PlayerDB":
self.obj.db_subscriptions.add(subscriber)
_CHANNELHANDLER.cached_cmdsets.pop(subscriber, None)
self._recache()
def remove(self, entity):
@ -513,6 +519,7 @@ class SubscriptionHandler(object):
self.obj.db_subscriptions.remove(entity)
elif clsname == "ObjectDB":
self.obj.db_object_subscriptions.remove(entity)
_CHANNELHANDLER.cached_cmdsets.pop(subscriber, None)
self._recache()
def all(self):