def test_hash_sum_good(capfd): hash_value = 'fefb677369d7894997575b0e448c40e3' file = 'files/file_03.txt' hash_actual = hashlib.new("md5", file.encode()).hexdigest() CheckHash('data.txt', '').check_hash(hash_value, hash_actual, file) captured, err = capfd.readouterr() assert captured == f'{file} OK\n'
def test_path_bad(capfd): path = 'file_03.txt' f = CheckHash('data.txt', '').check_path_file(path) captured, err = capfd.readouterr() assert f == False assert captured == f'{path} NOT FOUND\n'
def test_hash_type_not_support(capfd, line): num_line = 10 type = line.split(' ')[1].lower() f = CheckHash('data.txt', '').check_hash_type(line, num_line, type) captured, err = capfd.readouterr() assert f == False assert captured == 'This type "test" is not supported\n'
def test_name_file_bad(capfd, line): num_line = 10 name = line.split(' ')[0] f = CheckHash('data.txt', '').check_name_file(line, num_line, name) captured, err = capfd.readouterr() assert f == False assert captured == f"File name error \n--- {line} ---\n in line {num_line}. Check the filename: {name}\n"
def test_hash_type_bad(capfd, line): num_line = 10 hash_type = ['md5', 'sha1', 'sha256', 'test'] type = line.split(' ')[1].lower() f = CheckHash('data.txt', '').check_hash_type(line, num_line, type) captured, err = capfd.readouterr() assert f == False assert captured == f"\nInvalid encoding method: {type}\n--- {line} ---\nin line {num_line}. Available encoding: {hash_type}\n"
def test_columns_bad(capfd, line): columns_in_row = 3 id_line = 10 separate_line = line.split(' ') f = CheckHash('data.txt', '').validation_line_in_file(line, id_line, separate_line) captured, err = capfd.readouterr() assert f == False assert captured == f"Invalid string \n--- {line} ---\nin line {id_line}. Count columns must be: {columns_in_row}\n"
def test_path_input_name_file(): path = 'no.txt' assert CheckHash(path, '').create_path(path) == 'no.txt'
def test_path_input_folder(): path = 'folder' assert CheckHash(path, '').create_path(path) == 'folder/'
def test_path_input_empty(): path = '/' assert CheckHash(path, '').create_path(path) == '/'
def test_path_input_file_slash(): path = 'folder/no.txt' assert CheckHash(path, '').create_path(path) == 'folder/no.txt'
def test_path_main_file_open(): path = 'files/data.txt' CheckHash(path, '').read_file()
def test_path_main_file_empty(capfd): path = 'files/empty.txt' with pytest.raises(SystemExit): CheckHash(path, '').read_file() captured, err = capfd.readouterr() assert captured == f"File {path} empty\n"
def test_path_main_file_raises_not_found(capfd, path): with pytest.raises(FileNotFoundError): CheckHash(path, '').read_file() captured, err = capfd.readouterr() assert captured == f"File {path} not found\n"
def test_hash_type_good(capfd, line): num_line = 10 type = line.split(' ')[1].lower() f = CheckHash('data.txt', '').check_hash_type(line, num_line, type) assert f == True
def test_name_file_good(line): num_line = 10 name = line.split(' ')[0] f = CheckHash('data.txt', '').check_name_file(line, num_line, name) assert f == True
def test_good(): path = 'files/file_03.txt' assert CheckHash('files/data.txt', '').check_path_file(path) == True
def test_empty_line(): path = 'files/data.txt' assert CheckHash(path, '').read_file() == None
def test_good(line): id_line = 5 separate_line = line.split(' ') assert CheckHash('data.txt', '').validation_line_in_file(line, id_line, separate_line) == True