def remove(instance: Queue): if len(instance._data) == 0: return print("Não há elementos") path_file = instance._data[0]["nome_do_arquivo"] instance.dequeue() return print(f"Arquivo {path_file} removido com sucesso")
def test_search_com_indice_invalido(): queue = Queue() with pytest.raises(IndexError): queue.search(0) queue.enqueue(42) with pytest.raises(IndexError): queue.search(-1) with pytest.raises(IndexError): queue.search(2)
def test_search_deve_buscar_um_valor_a_partir_de_um_indice(): queue = Queue() queue.enqueue(42) queue.enqueue(43) queue.enqueue(44) assert queue.search(0) == 42 assert queue.search(1) == 43 assert queue.search(2) == 44
def test_validar_funcao_process_com_sucesso(capsys): project = Queue() process("statics/arquivo_teste.txt", project) out, err = capsys.readouterr() assert "'nome_do_arquivo': 'statics/arquivo_teste.txt'" in out assert "'qtd_linhas': 3" in out assert "'linhas_do_arquivo': ['Acima de tudo,'" in out
def test_dequeue_deve_remover_um_valor_a_fila(): queue = Queue() queue.enqueue(42) queue.enqueue(43) queue.enqueue(44) given = queue.dequeue() assert len(queue) == 2 assert given == 42
def test_validar_funcao_file_metadata_com_sucesso(capsys): project = Queue() process("statics/novo_paradigma_globalizado-min.txt", project) file_metadata(project, 0) out, err = capsys.readouterr() assert ("'nome_do_arquivo': 'statics/novo_paradigma_globalizado-min.txt'" in out) assert "'qtd_linhas': 19" in out assert ( "'linhas_do_arquivo': ['Estratégias em um Novo Paradigma Globalizado'" in out)
def test_validar_search_by_word_com_palavra_inexistente(capsys): project = Queue() process("statics/nome_pedro.txt", project) word = search_by_word("Ratinho", project) out, err = capsys.readouterr() assert word == []
def test_validar_search_by_word_com_sucesso(capsys): project = Queue() process("statics/nome_pedro.txt", project) word = search_by_word("pedro", project) out, err = capsys.readouterr() assert word == text_search_by_word
def test_validar_funcao_exists_word_sem_palavra_existente(capsys): project = Queue() process("statics/nome_pedro.txt", project) word = exists_word("Ratinho", project) out, err = capsys.readouterr() assert word == []
def test_validar_funcao_exists_word_com_sucesso(capsys): project = Queue() process("statics/nome_pedro.txt", project) word = exists_word("Pedro", project) out, err = capsys.readouterr() assert word == text_exists_word
def test_validar_funcao_file_metadata_com_posicao_invalida(capsys): project = Queue() process("statics/novo_paradigma_globalizado-min.txt", project) file_metadata(project, 200) out, err = capsys.readouterr() assert "Posição inválida" in err
def test_remover_arquivo_inexistente(capsys): project = Queue() remove(project) out, err = capsys.readouterr() assert out == "Não há elementos\n"
def test_remover_arquivo_com_sucesso(capsys): project2 = Queue() process("statics/arquivo_teste.txt", project2) remove(project2) out, err = capsys.readouterr() assert "Arquivo statics/arquivo_teste.txt removido com sucesso\n" in out
def test_validar_funcao_process_ignorando_mesmo_nome(capsys): project = Queue() process("statics/arquivo_teste.txt", project) process("statics/arquivo_teste.txt", project) assert len(project) == 1
def search_by_word(word, instance): news = [] for i_news in range(len(instance)): current = instance.dequeue() matched_lines = search_word_sentence( word, current["linhas_do_arquivo"] ) if matched_lines: news.append( { "palavra": word, "arquivo": current["nome_do_arquivo"], "ocorrencias": matched_lines, } ) instance.enqueue(current) return news if __name__ == "__main__": from ting_file_management.queue import Queue from ting_file_management.file_process import process project = Queue() process("statics/nome_pedro.txt", project) word = search_by_word("pedro", project) print(word)
def test_enqueue_deve_adicionar_um_valor_a_fila(): queue = Queue() queue.enqueue(42) assert len(queue) == 1