def test_dict(self): message = Message(text="テスト", id_=0) self.assertEqual(message.dict(), { "text": "テスト", "id_": 0, "speaker": None })
def test_manager(self): mod1 = ModDouble("mod1") mod2 = ModDouble("mod2") bot = KovotDouble() manager = ModManager(mods=[mod1, mod2]) message = Message(text="テストメッセージ") res = manager.generate_responses(bot, message) ans = [ gen_res(0.1, "mod1"), gen_res(0.2, "mod1"), gen_res(0.1, "mod2"), gen_res(0.2, "mod2") ] self.assertEqual(res, ans)
def __next__(self): while True: try: reses = self.sc.rtm_read() except: traceback.print_exc() self.sc.rtm_connect() if reses: for item in reses: name = self.id2name.get(item.get("user", None), None) if (item["type"] == "message" and name != self.name): self.messages.append(item) if self.messages: break time.sleep(1) mess = self.messages.popleft() return Message(text=self._get_text(mess), speaker=Speaker(name=""))
def test_transformer(self): text = "京都にいます" message = Message(text=text) transformer = MessageTransformer() self.assertEqual(transformer.transform(message), message)
def test_from_dict_arg_speaker(self): d = {"text": "テスト", "speaker": {"name": "bot"}} self.assertEqual(Message.from_dict(d), Message(text="テスト", speaker=Speaker(name="bot")))
def test_from_dict(self): d = {"text": "テスト"} self.assertEqual(Message.from_dict(d), Message(text="テスト"))
def test_message_with_id(self): text = "京都にいます" id_ = 100 message_with_id = Message(text=text, id_=id_) self.assertEqual(message_with_id.text, text) self.assertEqual(message_with_id.id_, id_)
def test_message(self): text = "京都にいます" message = Message(text=text) self.assertEqual(message.text, text)
def __next__(self): ipt = sys.stdin.readline().strip("\n") return Message(text=ipt, speaker=Speaker(name="You"))