kopia lustrzana https://github.com/biobootloader/wolverine
Added tests for apply changes method
rodzic
c50b51e949
commit
4c8e7f7964
|
@ -0,0 +1,54 @@
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import tempfile
|
||||||
|
from wolverine import apply_changes
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def temp_file():
|
||||||
|
# Create a temporary file
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
|
||||||
|
f.write("first line\nsecond line\nthird line")
|
||||||
|
file_path = f.name
|
||||||
|
yield file_path
|
||||||
|
# Clean up the temporary file
|
||||||
|
os.remove(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_changes_replace(temp_file):
|
||||||
|
# Make a "replace" change to the second line
|
||||||
|
changes = [
|
||||||
|
{"operation": "Replace", "line": 2, "content": "new second line"}
|
||||||
|
]
|
||||||
|
apply_changes(temp_file, changes)
|
||||||
|
|
||||||
|
# Check that the file was updated correctly
|
||||||
|
with open(temp_file) as f:
|
||||||
|
content = f.read()
|
||||||
|
assert content == "first line\nnew second line\nthird line"
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_changes_delete(temp_file):
|
||||||
|
# Make a "delete" change to the third line
|
||||||
|
changes = [
|
||||||
|
{"operation": "Delete", "line": 3},
|
||||||
|
]
|
||||||
|
apply_changes(temp_file, changes)
|
||||||
|
|
||||||
|
# Check that the file was updated correctly
|
||||||
|
with open(temp_file) as f:
|
||||||
|
content = f.read()
|
||||||
|
assert content == "first line\nsecond line"
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_changes_insert(temp_file):
|
||||||
|
# Make an "insert" change after the second line
|
||||||
|
changes = [
|
||||||
|
{"operation": "InsertAfter", "line": 2, "content": "inserted line"},
|
||||||
|
]
|
||||||
|
apply_changes(temp_file, changes)
|
||||||
|
|
||||||
|
# Check that the file was updated correctly
|
||||||
|
with open(temp_file) as f:
|
||||||
|
content = f.read()
|
||||||
|
assert content == "first line\nsecond line\ninserted line"
|
Ładowanie…
Reference in New Issue