def from_dict(cls, dic): # convert to Speaker and Message object from dictionary if dic.get("speaker"): speaker = Speaker.from_dict(dic["speaker"]) else: speaker = None if dic.get("message"): message = Speaker.from_dict(dic["message"]) else: message = None return cls(text=dic["text"], score=dic["score"], id_=dic.get("id_"), speaker=speaker, message=message, source=dic.get("source"))
def from_dict(cls, dic): speaker = dic.get("speaker") if speaker: speaker = Speaker.from_dict(speaker) m = Message(text=dic["text"], id_=dic.get("id_"), speaker=speaker) return m
def test_from_dict(self): dic = {"name": "太郎"} self.assertEqual(Speaker.from_dict(dic), Speaker(name="太郎"))