def chat_file(self, value): """ The function will make sure the chat file has the right extenstion :param value: the chat file (FileStorage) :return: The chat as dataframe (Pandas Dataframe) """ if not Validators.check_ext(value.filename, self._supported_chat_file_ext): raise ValueError(RestErrors.INVALID_CHAT_FILE) chat_file = value.stream.read().decode("utf-8").split( "\n") #TODO: check this in test chat_df = create_chat_df(chat_file) if chat_df.empty: raise ValueError(RestErrors.INVALID_CHAT_FILE) return chat_df
def test_create_chat_df_validation_regular(self, folders, file_name, expected_output): with open(os.path.join(folders["chat_folder"], file_name), "r", encoding="utf-8") as f: chat_df = create_chat_df(f.readlines()) assert chat_df.empty == expected_output
def test_create_chat_df_validation_empty(self, folders, file_name, expected_output): with open(os.path.join(folders["chat_folder"], file_name), "r", encoding="utf-8") as f: with pytest.raises(ValueError): assert create_chat_df(f.readlines())
def arrange_chat_df(chat_path): with open(chat_path, "r", encoding="utf-8") as f: chat_df = create_chat_df(f.readlines()) return chat_df