def test_new_chatter(): ps = Playerset() us = IrcUserset(ps) p = Player(**{"id_": 1, "login": "******"}) ps[p.id] = p u = IrcUser("Guy", "") us[u.name] = u assert u.player is p
def __init__(self, client, playerset, me, *args, **kwargs): if not self.use_chat: logger.info("Disabling chat") return logger.debug("Lobby instantiating.") BaseClass.__init__(self, *args, **kwargs) SimpleIRCClient.__init__(self) self.setupUi(self) self.client = client self._me = me self._chatters = IrcUserset(playerset) self.channels = {} # avatar downloader self.nam = QNetworkAccessManager() self.nam.finished.connect(self.finish_download_avatar) # nickserv stuff self.identified = False # IRC parameters self.crucialChannels = ["#aeolus"] self.optionalChannels = [] # We can't send command until the welcome message is received self.welcomed = False # Load colors and styles from theme self.a_style = util.THEME.readfile("chat/formatters/a_style.qss") # load UI perform some tweaks self.tabBar().setTabButton(0, 1, None) self.tabCloseRequested.connect(self.close_channel) # Hook with client's connection and autojoin mechanisms self.client.authorized.connect(self.connect) self.client.autoJoin.connect(self.auto_join) self.channelsAvailable = [] self._notifier = None self._timer = QTimer() self._timer.timeout.connect(self.once) # disconnection checks self.canDisconnect = False
def test_chatter_rename_no_player(mocker): ps = Playerset() us = IrcUserset(ps) p = Player(**{"id_": 1, "login": "******"}) ps[p.id] = p u = IrcUser("Guy", "") us[u.name] = u pUpd = mocker.Mock() u.newPlayer.connect(pUpd) u.update(name="Other") pUpd.assert_called_with(u, None, p) with pytest.raises(KeyError): us["Guy"] assert us["Other"] is u assert u.player is None
def test_player_change(mocker): ps = Playerset() us = IrcUserset(ps) u = IrcUser("Guy", "") us[u.name] = u assert u.player is None pUpd = mocker.Mock() u.newPlayer.connect(pUpd) p = Player(**{"id_": 1, "login": "******"}) ps[p.id] = p pUpd.assert_called_with(u, p, None) assert u.player is p pUpd.reset_mock() del ps[p.id] pUpd.assert_called_with(u, None, p) assert u.player is None
def test_add_remove(playerset, mocker): ps = IrcUserset(playerset) p = IrcUser("Name", "Hostname") def test_user_signal(sp): assert sp is p newuser = mocker.Mock() goneuser = mocker.Mock() ps.userAdded.connect(newuser) ps.userAdded.connect(test_user_signal) ps.userRemoved.connect(goneuser) ps.userRemoved.connect(test_user_signal) ps[p.name] = p assert newuser.called assert ps[p.name] is p del ps[p.name] assert goneuser.called assert p.name not in ps with pytest.raises(KeyError): ps[p.name]
def test_cant_add_mismatched_name(playerset): ps = IrcUserset(playerset) p = IrcUser("Name", "Hostname") ps[p.name] = p with pytest.raises(ValueError): ps[p.name + "Other"] = p
def test_cant_add_twice(playerset): ps = IrcUserset(playerset) p = IrcUser("Name", "Hostname") ps[p.name] = p with pytest.raises(ValueError): ps[p.name] = p