mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-03-03 21:10:40 +01:00
Fixed bug in IrcState.copy -- it wasn't doing deep copies.
This commit is contained in:
parent
ee24accaf7
commit
683ba63949
@ -207,7 +207,7 @@ class ChannelState(object):
|
|||||||
# without changing any of his categories.
|
# without changing any of his categories.
|
||||||
for s in (self.users, self.ops, self.halfops, self.voices):
|
for s in (self.users, self.ops, self.halfops, self.voices):
|
||||||
if oldNick in s:
|
if oldNick in s:
|
||||||
s.discard(oldNick)
|
s.remove(oldNick)
|
||||||
s.add(newNick)
|
s.add(newNick)
|
||||||
|
|
||||||
def removeUser(self, user):
|
def removeUser(self, user):
|
||||||
@ -266,9 +266,9 @@ class IrcState(IrcCommandDispatcher):
|
|||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
ret = self.__class__()
|
ret = self.__class__()
|
||||||
ret.history = copy.copy(self.history)
|
ret.history = copy.deepcopy(self.history)
|
||||||
ret.nicksToHostmasks = copy.copy(self.nicksToHostmasks)
|
ret.nicksToHostmasks = copy.deepcopy(self.nicksToHostmasks)
|
||||||
ret.channels = copy.copy(self.channels)
|
ret.channels = copy.deepcopy(self.channels)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def addMsg(self, irc, msg):
|
def addMsg(self, irc, msg):
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
from test import *
|
from test import *
|
||||||
|
|
||||||
|
import copy
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
@ -130,8 +131,21 @@ class IrcMsgQueueTestCase(unittest.TestCase):
|
|||||||
class ChannelStateTestCase(unittest.TestCase):
|
class ChannelStateTestCase(unittest.TestCase):
|
||||||
def testPickleCopy(self):
|
def testPickleCopy(self):
|
||||||
c = irclib.ChannelState()
|
c = irclib.ChannelState()
|
||||||
c1 = pickle.loads(pickle.dumps(c))
|
|
||||||
self.assertEqual(pickle.loads(pickle.dumps(c)), c)
|
self.assertEqual(pickle.loads(pickle.dumps(c)), c)
|
||||||
|
c.addUser('jemfinch')
|
||||||
|
c1 = pickle.loads(pickle.dumps(c))
|
||||||
|
self.assertEqual(c, c1)
|
||||||
|
c.removeUser('jemfinch')
|
||||||
|
self.failIf('jemfinch' in c.users)
|
||||||
|
self.failUnless('jemfinch' in c1.users)
|
||||||
|
|
||||||
|
def testCopy(self):
|
||||||
|
c = irclib.ChannelState()
|
||||||
|
c.addUser('jemfinch')
|
||||||
|
c1 = copy.deepcopy(c)
|
||||||
|
c.removeUser('jemfinch')
|
||||||
|
self.failIf('jemfinch' in c.users)
|
||||||
|
self.failUnless('jemfinch' in c1.users)
|
||||||
|
|
||||||
def testAddUser(self):
|
def testAddUser(self):
|
||||||
c = irclib.ChannelState()
|
c = irclib.ChannelState()
|
||||||
@ -190,6 +204,31 @@ class IrcStateTestCase(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
self.assertEqual(state, pickle.loads(pickle.dumps(state)))
|
self.assertEqual(state, pickle.loads(pickle.dumps(state)))
|
||||||
|
|
||||||
|
def testCopy(self):
|
||||||
|
state = irclib.IrcState()
|
||||||
|
self.assertEqual(state, state.copy())
|
||||||
|
for msg in msgs:
|
||||||
|
try:
|
||||||
|
state.addMsg(self.irc, msg)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.assertEqual(state, state.copy())
|
||||||
|
|
||||||
|
state = irclib.IrcState()
|
||||||
|
|
||||||
|
def testJoin(self):
|
||||||
|
st = irclib.IrcState()
|
||||||
|
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
|
||||||
|
self.failUnless('#foo' in st.channels)
|
||||||
|
self.failUnless(self.irc.nick in st.channels['#foo'].users)
|
||||||
|
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz'))
|
||||||
|
self.failUnless('foo' in st.channels['#foo'].users)
|
||||||
|
st2 = st.copy()
|
||||||
|
st.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz'))
|
||||||
|
self.failIf('foo' in st.channels['#foo'].users)
|
||||||
|
self.failUnless('foo' in st2.channels['#foo'].users)
|
||||||
|
|
||||||
|
|
||||||
def testEq(self):
|
def testEq(self):
|
||||||
state1 = irclib.IrcState()
|
state1 = irclib.IrcState()
|
||||||
state2 = irclib.IrcState()
|
state2 = irclib.IrcState()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user