Пример #1
0
def test_check_file_hash():
    test_file = create_test_file()
    result = check_file_hash(
        test_file,
        "4c77f1bd193cac476cea5af2225e8c0177d5a009390aa6e119c211a00cf325c9")
    assert result is True, "Bogus file hash check"
    remove_file(test_file)
Пример #2
0
def test_sha256sum():
    test_file = create_test_file()
    sum = sha256sum(test_file)
    assert (sum ==
            "4c77f1bd193cac476cea5af2225e8c0177d5a009390aa6e119c211a00cf325c9"
            ), "Bogus checksum"
    remove_file(test_file)
Пример #3
0
def test_csv_dict_reader():
    file = get_writable_random_file("csv_dict_reader")
    # Prepare a basic CSV file

    with open(file, "wt", encoding="utf-8") as fp:
        # python 2.7 compat fixes
        if sys.version_info[0] < 3:
            csv_content = u"SOME;CSV HEADER;WITH COLUMNS\n1;2;3\n#commented;out;line\nA;B;C\n4;5;6"
        else:
            csv_content = (
                "SOME;CSV HEADER;WITH COLUMNS\n1;2;3\n#commented;out;line\nA;B;C\n4;5;6"
            )
        fp.write(csv_content)
        fp.flush()

    data = csv_dict_reader(file,
                           skip_comment_char="#",
                           delimiter=";",
                           fieldnames=None)
    for index, line in enumerate(data):
        print(index, line)
        if index == 0:
            assert line["SOME"] == "1"
            assert line["CSV HEADER"] == "2"
            assert line["WITH COLUMNS"] == "3"
        if index == 1:
            assert line["SOME"] == "A"
            assert line["CSV HEADER"] == "B"
            assert line["WITH COLUMNS"] == "C"
        if index == 2:
            assert line["SOME"] == "4"
            assert line["CSV HEADER"] == "5"
            assert line["WITH COLUMNS"] == "6"
    remove_file(file)
Пример #4
0
def test_create_sha256sum_file():
    test_file = create_test_file()
    filename = os.path.basename(test_file)
    test_directory = os.path.abspath(os.path.dirname(test_file))
    create_sha256sum_file(test_directory)
    sum_file = os.path.join(test_directory, "SHA256SUMS.TXT")
    with open(sum_file, "r") as fp:
        data = fp.read()
        assert ("{}  {}".format(
            "4c77f1bd193cac476cea5af2225e8c0177d5a009390aa6e119c211a00cf325c9",
            filename,
        ) in data), "sha256file does not contain my favorite file"
    remove_file(sum_file)
    remove_file(test_file)
Пример #5
0
def test_create_manifest_from_dir():
    """
    Does not test prefixes
    """
    manifest_file = prepare_temp_file()
    test_file = create_test_file()
    create_manifest_from_dir(manifest_file, os.path.dirname(manifest_file))
    with open(manifest_file, "r") as fp:
        data = fp.read()
        print("{}  {}".format(
            "4c77f1bd193cac476cea5af2225e8c0177d5a009390aa6e119c211a00cf325c9",
            test_file,
        ))
        print(data)
        assert ("{}  {}".format(
            "4c77f1bd193cac476cea5af2225e8c0177d5a009390aa6e119c211a00cf325c9",
            test_file,
        ) in data), "sha256file does not contain my favorite file"
    remove_file(manifest_file)
    remove_file(test_file)
Пример #6
0
def prepare_temp_file():
    filename = "ofunctions.checksum_file." + random_string(16) + ".file"
    test_directory = os.path.abspath(os.path.dirname(__file__))
    path = os.path.join(test_directory, filename)
    remove_file(path)
    return path