Esempio n. 1
0
def check_same_files(file1, file2):
    content1 = common.get_file_content(file1)
    content2 = common.get_file_content(file2)

    content1 = content1.replace('\r', '')
    content2 = content2.replace('\r', '')

    return (len(content1) == len(content2)) and (content1 == content2)
Esempio n. 2
0
def check_trans_text_function_one(filename, filename_result,
                                  transform_function):
    input_filename = common.check_is_file_and_correct_path(filename)
    result_filename = common.check_is_file_and_correct_path(filename_result)

    input1 = common.get_file_content(input_filename)
    result = common.get_file_content(result_filename)

    trans1 = transform_function(input1)

    trans1 = trans1.replace('\r', '')
    result = result.replace('\r', '')

    assert trans1 == result
Esempio n. 3
0
def test_get_file_content():

    random_name = '.{}'.format(hash(os.times()))
    test_filename_1 = "./" + random_name + "1.txt"
    test_filename_2 = "./" + random_name + "2.txt"

    with pytest.raises(Exception):
        common.check_is_file_and_correct_path(test_filename_1)
    with pytest.raises(Exception):
        common.check_is_file_and_correct_path(test_filename_2)

    file_content = "Test"

    # create the file
    output_file = codecs.open(test_filename_1, "w", encoding="utf-8")
    output_file.write(file_content)
    output_file.close()
    # create the file
    output_file = codecs.open(test_filename_2, "w", encoding="utf-8")
    output_file.write(u'\ufeff' + file_content)
    output_file.close()

    assert common.check_is_file_and_correct_path(
        test_filename_1) == os.path.abspath(test_filename_1)
    assert common.check_is_file_and_correct_path(
        test_filename_2) == os.path.abspath(test_filename_2)

    assert common.get_file_content(test_filename_1) == file_content
    assert common.get_file_content(test_filename_2) == file_content

    if os.path.isfile(test_filename_1):
        os.remove(test_filename_1)
    if os.path.isfile(test_filename_2):
        os.remove(test_filename_2)

    with pytest.raises(Exception):
        common.check_is_file_and_correct_path(test_filename_2)
    with pytest.raises(Exception):
        common.check_is_file_and_correct_path(test_filename_2)
Esempio n. 4
0
    def __create_result__(filename):
        filename = common.check_is_file_and_correct_path(filename)
        result_filename = common.set_correct_path(os.path.splitext(filename)[
            0] + new_extension_for_result)

        if (len(filename) > len_end_of_filename) and \
                (filename[-len_end_of_filename:] ==
                 new_extension_for_result):
            return
        if (os.path.isfile(result_filename)) and (not force_creation):
            return

        logging.info('Create result for the file %s', filename)
        common.set_file_content(result_filename, function_test(
            common.get_file_content(filename)))