Example #1
0
def test_get_operations_same():
    text_file1 = TextFile("filename", [""])
    text_file2 = TextFile("filename", [""])
    operations = text_file1.get_operations(text_file2)
    assert len(operations) == 0

    text_file1 = TextFile("filename", ["hi", "i", "am", "nate"])
    text_file2 = TextFile("filename", ["hi", "i", "am", "nate"])
    operations = text_file1.get_operations(text_file2)
    assert len(operations) == 0
Example #2
0
def test_get_operations_remove_insert_line():
    text_file1 = TextFile("filename", [""])
    text_file2 = TextFile("filename", ["123"])
    operations = text_file1.get_operations(text_file2)
    assert len(operations) == 2
    assert isinstance(operations[0], TextOpRemoveLine)
    assert operations[0].file_name == "filename"
    assert operations[0].line_number == 0
    assert isinstance(operations[1], TextOpInsertLine)
    assert operations[1].file_name == "filename"
    assert operations[1].line_number == 0
    assert operations[1].line_contents == "123"
Example #3
0
def test_get_operations_complex_changes():
    text_file1 = TextFile("filename", ["a", "b", "c", "d", "e"])
    text_file2 = TextFile("filename", ["a", "k", "b", "e"])
    operations = text_file1.get_operations(text_file2)
    assert len(operations) == 3
    assert isinstance(operations[0], TextOpRemoveLine)
    assert operations[0].file_name == "filename"
    assert operations[0].line_number == 2
    assert isinstance(operations[1], TextOpRemoveLine)
    assert operations[1].file_name == "filename"
    assert operations[1].line_number == 2
    assert isinstance(operations[2], TextOpInsertLine)
    assert operations[2].file_name == "filename"
    assert operations[2].line_number == 1
    assert operations[2].line_contents == "k"
Example #4
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
Example #5
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
Example #6
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"
Example #7
0
def test_patch_to_from_string():
    text_file = TextFile("filename", [""])
    insertOp = FileOpInsert("filename", text_file)
    remove_op = FileOpRemove("filename")
    patch = Patch([insertOp, remove_op])

    patch_string = patch.to_string()
    patch1 = Patch.from_string(patch_string)

    assert len(patch.operations) == len(patch1.operations)
    assert patch.operations[0].file_name == patch1.operations[0].file_name
    assert patch.operations[0].file.file_contents == patch1.operations[
        0].file.file_contents
    assert patch.operations[1].file_name == patch1.operations[0].file_name
    assert isinstance(patch1.operations[0], FileOpInsert)
    assert isinstance(patch1.operations[1], FileOpRemove)
Example #8
0
def test_to_from_file():
    text_file = TextFile(os.getcwd() + "/temp/text", ["hi", "yo"])
    text_file.to_file(os.getcwd() + "/temp/text")
    text_file1 = TextFile.from_file(os.getcwd() + "/temp/text")
    assert text_file1.file_name == os.getcwd() + "/temp/text"
    assert text_file1.file_contents == ["hi", "yo"]
Example #9
0
def test_to_from_string():
    text_file = TextFile("text", ["this", "is", "a", "file"])
    text_file_string = text_file.to_string()
    text_file1 = TextFile.from_string(text_file_string)
    assert text_file.file_name == text_file1.file_name
    assert text_file.file_contents == text_file1.file_contents