בדיקות לפרוייקט wit

הכנתי לעצמי בדיקות אז אני משתף. רשמתי בהערות איפה אתם צריכים להשלים את החיבור לקוד שלכם.
לדוגמא:

    head_id = ""  # Get head ID from references file

פה תצטרכו לגשת לקובץ ה references שלכם ולהביא את הID של ה HEAD. מכיוון שכל אחד כתב כנראה את הקוד אחרת, תצטרכו למלא את החלקים האלה.

בתחילת הקובץ יש פונקציה ריקה.

def main(args):
    # Pass this to your functions.
    # Data is passed like it would be passed via cmd.
    pass

הפונקציה main מדמה הכנסת נתונים כמו דרך cmd אז פשוט תחברו את זה לקוד שלכם שמקבל את הקלט.

דבר אחרון, הפונקציה reset_tests נועדה לאפס את התקייה. תצטרכו להוסיף בשורה הראשונה קוד שמוחק את התקייה של .wit

אם ראיתם שגיאה בבדיקות אשמח לדעת. כמו כן, זה מן הסתם לא בודק את כל התוכנה אז אם יש לכם בדיקות נוספות תרגישו חופשי לשתף.

קוד
import pathlib


def reset_tests():
    # Important! Delete the wit directory
    with open("references file", "w") as text_file:
        text_file.write("")

    with open("activated branch file", "w") as text_file:
        text_file.write("")



def main(args):
    # Pass this to your functions.
    # Data is passed like it would be passed via cmd.
    pass


def test_init():
    reset_tests()
    main(["", "init"])
    activated_branch = ""  # Get the activated branch name from file
    print("master" == activated_branch)


def test_add_file():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    files = ""  # Get the files from your staging area dir
    print(len(files) == 1)


def test_add_two_files():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file2])
    files = ""  # Get the files from your staging area dir
    print(len(files) == 2)


def test_add_file_in_dir():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("test").joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    files = ""  # Get the files from your staging area dir
    print(len(files) == 1)


def test_commit_head_and_master():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    head = ""  # Get head ID from references file
    master = ""  # Get master ID from references file
    print(head and head == master)


def test_commit_branch_checkout_head_master_and_branch_same():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    main(["", "branch", "branch1"])
    main(["", "checkout", "branch1"])
    head_id = ""  # Get head ID from references file
    master_id = ""  # Get master ID from references file
    branch_id = ""  # Get branch1 ID from references file
    print(head_id and head_id == master_id and head_id == branch_id)


def test_commit_branch_checkout_head_master_and_branch_not_same():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    main(["", "branch", "branch1"])
    main(["", "checkout", "branch1"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "second"])
    head_id = ""  # Get head ID from references file
    master_id = ""  # Get master ID from references file
    branch_id = ""  # Get branch1 ID from references file
    print(head_id and head_id != master_id and head_id == branch_id)


def test_get_changes_to_be_committed_same_file():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    result = ""  # Get changes to be committed
    print(len(result) == 1)


def test_get_changes_to_be_committed_different_file():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file2])
    result = ""  # Get changes to be committed
    print(len(result) == 1)


def test_get_changes_to_be_committed_two_files():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "add", text_file2])
    result = ""  # Get changes to be committed
    print(len(result) == 2)


def test_get_changes_not_staged_for_commit_same_file():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    result = ""  # Get changes not staged for commit
    print(len(result) == 1)


def test_get_changes_not_staged_for_commit_different_file():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    result = ""  # Get changes not staged for commit
    print(len(result) == 0)


def test_get_changes_not_staged_for_commit_two_files():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    result = ""  # Get changes not staged for commit
    print(len(result) == 1)


def test_file_in_both_changes_to_be_committed_and_changes_not_staged_for_commit():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "add", text_file2])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    result1 = ""  # Get changes to be committed
    result2 = ""  # Get changes not staged for commit
    print(len(result1) == 2 and len(result2) == 1)


def test_branch_checkout():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    main(["", "branch", "branch1"])
    main(["", "checkout", "branch1"])
    main(["", "commit", "second"])
    main(["", "branch", "branch2"])
    main(["", "checkout", "branch2"])
    main(["", "commit", "third"])
    main(["", "checkout", "master"])

    head_id = ""  # Get head ID from references file
    master_id = ""  # Get master ID from references file
    activated_branch = ""  # Get the activated branch name from file
    check1 = "master" == activated_branch
    check2 = head_id == master_id
    files = ""  # Get the files from your staging area dir
    check3 = len(files) == 1
    print(check1 and check2 and check3)


def test_merge():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])  # 0000
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "second"])  # 1111
    head_before_branch = ""  # Get head ID from references file
    main(["", "branch", "meow"])
    main(["", "checkout", "meow"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "third"])  # 2222
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file2])
    main(["", "commit", "fourth"])  # 3333
    main(["", "checkout", "master"])
    main(["", "merge", "meow"])  # 4444 - parents of this commit are 1111 and 3333
    main(["", "graph"])

    head_id = ""  # Get head ID from references file
    master_id = ""  # Get master ID from references file
    meow_id = ""  # Get meow ID from references file
    merge_parents = ""  # Get head ID parents from head commit file
    print(merge_parents == f"{head_before_branch},{meow_id}" and head_id == master_id and head_id != meow_id)


def test_merge_fail():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    text_file2 = pathlib.Path.cwd().joinpath("text_file2.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "second"])
    main(["", "branch", "meow"])
    main(["", "checkout", "meow"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "third"])
    with open(text_file2, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file2])
    main(["", "commit", "fourth"])
    main(["", "checkout", "master"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "merge", "meow"])


def test_linear_graph():
    reset_tests()
    main(["", "init"])
    text_file1 = pathlib.Path.cwd().joinpath("text_file1.txt")
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "first"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "second"])
    with open(text_file1, "a") as text_file:
        text_file.write("test ")
    main(["", "add", text_file1])
    main(["", "commit", "third"])
    main(["", "graph"])

# test_init()
# test_add_file()
# test_add_two_files()
# test_add_file_in_dir()
# test_commit_head_and_master()
# test_commit_branch_checkout_head_master_and_branch_same()
# test_commit_branch_checkout_head_master_and_branch_not_same()
# test_get_changes_to_be_committed_same_file()
# test_get_changes_to_be_committed_different_file()
# test_get_changes_to_be_committed_two_files()
# test_get_changes_not_staged_for_commit_same_file()
# test_get_changes_not_staged_for_commit_different_file()
# test_get_changes_not_staged_for_commit_two_files()
# test_get_changes_not_staged_for_commit()
# test_file_in_both_changes_to_be_committed_and_changes_not_staged_for_commit()
# test_branch_checkout()
# test_merge()
# test_merge_fail()
# test_linear_graph()
10 לייקים