Exemple #1
0
def test_para_salvar_arquivos_em_folders_inexistentes():

    errors = []

    folder_auxiliar = 'mocks2'
    file_name = 'arquivo_teste.txt'
    path_folder_salvar = InOut().ajuste_path('\\'.join(
        [paths_files.path_mocks(), folder_auxiliar]))
    path_arquivo_salvar = InOut().ajuste_path('\\'.join(
        [paths_files.path_mocks(), folder_auxiliar, file_name]))
    conteudo = 'teste_conteudo_linha_1\nteste_conteudo_linha_2'
    if not txt.salvar(path_arquivo_salvar, conteudo):
        errors.append('erro ao salvar em caminho de pasta inexistente')
    if not txt.ler(path_arquivo_salvar) == [
            'teste_conteudo_linha_1\n', 'teste_conteudo_linha_2'
    ]:
        errors.append(
            'erro ao comparar conteudo salvo com o lido no arquivo salvo')

    try:
        shutil.rmtree(path_folder_salvar)
    except Exception as ex:
        errors.append(f'erro ao remover arquivo gerado [{ex}]')

    assert not errors, 'ocorrencia de erros:\n{}'.format('\n'.join(errors))
Exemple #2
0
def test_de_nao_existencia_de_arquivo():

    path_mocks = paths_files.path_mocks()
    path_arquivo_inexistente = inout.ajuste_path('\\'.join(
        [path_mocks, 'arquivo_inexistente.txt']))

    assert inout.arquivo_existe(path_arquivo_inexistente) is False
Exemple #3
0
def test_de_copia_de_arquivo_quando_folder_destino_eh_existente():
    path_arquivo_para_copia = paths_files.path_arquivo_exemplo()
    path_arquivo_copiado = '\\'.join([paths_files.path_mocks(), 'arquivo_copiado.txt'])

    path_arquivo_copiado = InOut().ajuste_path(path_arquivo_copiado)

    if not copy.copy_file(path_arquivo_para_copia, path_arquivo_copiado):
        pytest.fail('erro ao copiar arquivo')
    if not InOut().arquivo_existe(path_arquivo_copiado):
        pytest.fail('arquivo copiado nao foi gerado')
    if not TXT().ler(path_arquivo_copiado) == TXT().ler(path_arquivo_para_copia):
        pytest.fail('conteudo arquivo copiado nao eh igual ao original')

    try:
        os.remove(path_arquivo_copiado)
    except Exception as ex:
        pytest.fail(f'Nao foi possivel remover arquivo gerado. Erro :[{ex}]')
Exemple #4
0
def test_de_criação_de_folder():
    nome_diretorio_auxiliar1 = 'mocks2'
    nome_diretorio_auxiliar2 = 'mocks3\\'

    path_criacao_folder = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1, nome_diretorio_auxiliar2])
    path_remocao_folder = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1])

    path_criacao_folder = InOut().ajuste_path(path_criacao_folder)
    path_remocao_folder = InOut().ajuste_path(path_remocao_folder)

    if not copy.criar_arquivos(path_criacao_folder):
        pytest.fail('Criacao de folder falhou')
    if not os.path.isdir(path_criacao_folder):
        pytest.fail('Folder nao foi criado')

    try:
        shutil.rmtree(path_remocao_folder)
    except Exception as ex:
        pytest.fail(f'Nao foi possivel remover folder criado. Erro :[{ex}]')
Exemple #5
0
def test_de_copia_de_arquivo_quando_folder_destino_nao_eh_existente():
    nome_diretorio_auxiliar1 = 'mocks2'
    nome_diretorio_auxiliar2 = 'mocks3\\'

    path_arquivo_para_copia = paths_files.path_arquivo_exemplo()

    path_arquivo_copiado = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1,
                                      nome_diretorio_auxiliar2, 'arquivo_copiado.txt'])
    path_arquivo_copiado = InOut().ajuste_path(path_arquivo_copiado)

    path_remocao_folder = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1])
    path_remocao_folder = InOut().ajuste_path(path_remocao_folder)

    if not copy.copy_file(path_arquivo_para_copia, path_arquivo_copiado):
        pytest.fail('Criacao de arquivo copiado falhou')
    if not os.path.isfile(path_arquivo_copiado):
        pytest.fail('Arquivo nao foi copiado')
    if not TXT().ler(path_arquivo_copiado) == TXT().ler(path_arquivo_para_copia):
        pytest.fail('conteudo arquivo copiado nao eh igual ao original')

    try:
        shutil.rmtree(path_remocao_folder)
    except Exception as ex:
        pytest.fail(f'Nao foi possivel remover folder criado. Erro :[{ex}]')
Exemple #6
0
def test_para_salvar_arquivos():

    errors = []

    file_name = 'arquivo_teste.txt'
    path_arquivo_salvar = InOut().ajuste_path('\\'.join(
        [paths_files.path_mocks(), file_name]))
    conteudo = 'teste_conteudo_linha_1\nteste_conteudo_linha_2'

    if not txt.salvar(path_arquivo_salvar, conteudo) == True:
        errors.append('erro ao salvar em caminho de pasta existente')
    if not txt.ler(path_arquivo_salvar) == [
            'teste_conteudo_linha_1\n', 'teste_conteudo_linha_2'
    ]:
        errors.append(
            'erro ao comparar conteudo salvo com o lido no arquivo salvo')

    try:
        os.remove(path_arquivo_salvar)
    except Exception as ex:
        errors.append(f'erro ao apagar arquivo gerado [{ex}]')

    assert not errors, 'ocorrencia de erros:\n{}'.format('\n'.join(errors))
Exemple #7
0
import os
import pytest
import shutil

from src.inout.InOut import InOut
from src.inout.TXT import TXT
from src.inout.Copy import Copy
import tests.utilitarios.PathsFiles as paths_files

copy = Copy()
copy.set_arquivo_log(paths_files.path_arquivo_log())


def test_de_criação_de_folder():
    nome_diretorio_auxiliar1 = 'mocks2'
    nome_diretorio_auxiliar2 = 'mocks3\\'

    path_criacao_folder = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1, nome_diretorio_auxiliar2])
    path_remocao_folder = '\\'.join([paths_files.path_mocks(), nome_diretorio_auxiliar1])

    path_criacao_folder = InOut().ajuste_path(path_criacao_folder)
    path_remocao_folder = InOut().ajuste_path(path_remocao_folder)

    if not copy.criar_arquivos(path_criacao_folder):
        pytest.fail('Criacao de folder falhou')
    if not os.path.isdir(path_criacao_folder):
        pytest.fail('Folder nao foi criado')

    try:
        shutil.rmtree(path_remocao_folder)
    except Exception as ex:
import pytest
from src.inout.Terminal import Terminal
import tests.utilitarios.PathsFiles as paths_files

terminal = Terminal()
terminal.set_arquivo_log(paths_files.path_arquivo_log())


def test_de_execucao_terminal_com_valor_valido():
    assert terminal.run('dir') is True


def test_de_execucao_terminal_com_valor_nao_valido():
    assert terminal.run('comando nao inexiste') is False
Exemple #9
0
def test_de_retorno_vazio_na_leitura_de_arquivo_inexistente():

    path_arquivo_inexistente = InOut().ajuste_path('\\'.join(
        [paths_files.path_mocks(), 'arquivo_inexistente.txt']))
    assert txt.ler(path_arquivo_inexistente) == [None]
Exemple #10
0
def test_de_verificacao_de_leitura_de_arquivo():
    assert txt.ler(paths_files.path_arquivo_exemplo()) == [
        'id;cab1;cab2\n', '1;val11;val12\n', '2;val21;val22'
    ]
Exemple #11
0
def test_de_existencia_de_arquivo():

    assert inout.arquivo_existe(paths_files.path_arquivo_exemplo()) == True
Exemple #12
0
import tests.utilitarios.PathsFiles as paths_files
from src.loggin.Loggin import Loggin
from src.inout.InOut import InOut
import platform

inout = InOut()
Loggin().set_arquivo_log(paths_files.path_arquivo_log())


def test_ajuste_barras():
    path_desajustado = '..\\\\mocks/exemplo.txt'
    path_win = '..\\mocks\\exemplo.txt'
    path_lin = '../mocks/exemplo.txt'

    if platform.system().upper() == "WINDOWS":
        assert inout.ajuste_path(path_desajustado) == path_win
    else:
        assert inout.ajuste_path(path_desajustado) == path_lin


def test_de_existencia_de_arquivo():

    assert inout.arquivo_existe(paths_files.path_arquivo_exemplo()) == True


def test_de_nao_existencia_de_arquivo():

    path_mocks = paths_files.path_mocks()
    path_arquivo_inexistente = inout.ajuste_path('\\'.join(
        [path_mocks, 'arquivo_inexistente.txt']))