Beispiel #1
0
def test_insert_twice_fails():
    branch = Branch()
    insert_op1 = FileOpInsert("filename", "DATA")
    insert_op2 = FileOpInsert("filename", "DATA1")
    patch = Patch([insert_op1, insert_op2])
    with pytest.raises(Exception):
        branch.insert_patch(patch)
Beispiel #2
0
def test_insert():
    branch = Branch()
    insert_op = FileOpInsert("filename", "DATA")
    patch = Patch(set([insert_op]))
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert branch.states[-1].files["filename"] == "DATA"
Beispiel #3
0
def test_create():
    branch = Branch()
    json_file = JSONFile("filename", dict())
    insert_op = FileOpInsert("filename", json_file)
    patch = Patch([insert_op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert branch.states[-1].files["filename"] == json_file
def test_insert():
    branch = Branch()
    binary_file = BinaryFile("filename", "")
    insertOp = FileOpInsert("filename", binary_file)
    patch = Patch([insertOp])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert branch.states[-1].files["filename"] == binary_file
Beispiel #5
0
def test_insert():
    branch = Branch()
    text_file = TextFile("filename", [""])
    insertOp = FileOpInsert("filename", text_file)
    patch = Patch([insertOp])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert branch.states[-1].files["filename"] == text_file
Beispiel #6
0
def test_list_remove():
    branch = Branch()
    json_file = JSONFile("filename", [1])
    insert_op = FileOpInsert("filename", json_file)
    op = JSONOpListRemove("filename", ["0"])
    patch = Patch([insert_op, op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 0
Beispiel #7
0
def test_remove_dict():
    branch = Branch()
    json_file = JSONFile("filename", {'key': 123})
    insert_op = FileOpInsert("filename", json_file)
    del_dict_op = JSONOpDictRemove("filename", ["key"])
    patch = Patch([insert_op, del_dict_op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 0
Beispiel #8
0
def test_primitive_change():
    branch = Branch()
    json_file = JSONFile("filename", {'key': 123})
    insert_op = FileOpInsert("filename", json_file)
    op = JSONOpPrimitiveChange("filename", ["key"], 124)
    patch = Patch([insert_op, op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 1
    assert branch.states[-1].files["filename"].file_contents['key'] == 124
Beispiel #9
0
def test_insert_dict():
    branch = Branch()
    json_file = JSONFile("filename", {})
    insert_op = FileOpInsert("filename", json_file)
    insert_dict_op = JSONOpDictInsert("filename", ["key"], 123)
    patch = Patch([insert_op, insert_dict_op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 1
    assert branch.states[-1].files["filename"].file_contents['key'] == 123
Beispiel #10
0
def test_list_insert():
    branch = Branch()
    json_file = JSONFile("filename", [1])
    insert_op = FileOpInsert("filename", json_file)
    op = JSONOpListInsert("filename", ["1"], 2)
    patch = Patch([insert_op, op])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 2
    assert branch.states[-1].files["filename"].file_contents[0] == 1
    assert branch.states[-1].files["filename"].file_contents[1] == 2
Beispiel #11
0
def test_remove():
    branch = Branch()
    insert_op = FileOpInsert("filename", "DATA")
    patch = Patch([insert_op])
    branch.insert_patch(patch)

    remove_op = FileOpRemove("filename")
    patch = Patch([remove_op])
    branch.insert_patch(patch)
Beispiel #12
0
def get_curr_state(vcs_path, include_working_commit=True):
    branch = Branch()

    for patch_file_name in os.listdir(vcs_path + "/branch"):
        f = open(vcs_path + "/branch/" + patch_file_name, "r")
        patch_file_text = f.read().strip()
        f.close()
        patch = Patch.from_string(patch_file_text)
        branch.add_patch(patch)
        
    if include_working_commit:
        f = open(vcs_path + "/curr_commit", "r")
        patch_file_text = f.read().strip()
        f.close()
        if patch_file_text == "":
            return branch.curr_state()
        patch = Patch.from_string(patch_file_text)
        branch.add_patch(patch)

    return branch.curr_state()
def test_change_contents():
    branch = Branch()
    binary_file = BinaryFile("filename", "")
    insertOp = FileOpInsert("filename", binary_file)
    patch = Patch([insertOp])
    branch.insert_patch(patch)

    changeOp = BinaryOpChangeContents("filename", "new_data")
    patch = Patch([changeOp])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert branch.states[-1].files["filename"].file_contents == "new_data"
Beispiel #14
0
def test_remove_line():
    branch = Branch()
    text_file = TextFile("filename", ["new_line"])
    insertOp = FileOpInsert("filename", text_file)
    patch = Patch([insertOp])
    branch.insert_patch(patch)

    appendOp = TextOpRemoveLine("filename", 0)
    patch = Patch([appendOp])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files) == 1
    assert len(branch.states[-1].files["filename"].file_contents) == 0
Beispiel #15
0
def test_insert_line():
    branch = Branch()
    text_file = TextFile("filename", ["", ""])
    insertOp = FileOpInsert("filename", text_file)
    patch = Patch([insertOp])
    branch.insert_patch(patch)

    appendOp = TextOpInsertLine("filename", 1, "new_line")
    patch = Patch([appendOp])
    branch.insert_patch(patch)

    assert len(branch.states[-1].files["filename"].file_contents) == 3
    assert branch.states[-1].files["filename"].file_contents[1] == "new_line"
Beispiel #16
0
def test_remove_not_exist_fails():
    branch = Branch()
    remove_op = FileOpRemove("filename")
    patch = Patch([remove_op])
    with pytest.raises(Exception):
        branch.insert_patch(patch)